-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* export harmonogramu do ical * coding standard
- Loading branch information
1 parent
484ce8d
commit 171d40e
Showing
8 changed files
with
178 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\ExportModule\Presenters; | ||
|
||
use App\Model\User\UserRepository; | ||
use App\Services\IcalResponse; | ||
use Eluceo\iCal\Component\Calendar; | ||
use Eluceo\iCal\Component\Event; | ||
use Eluceo\iCal\Property\Event\Organizer; | ||
use Nette\Application\AbortException; | ||
|
||
/** | ||
* Presenter pro generování kalendáře ve formátu ICS. | ||
* | ||
* @author Jan Staněk <jan.stanek@skaut.cz> | ||
*/ | ||
class SchedulePresenter extends ExportBasePresenter | ||
{ | ||
/** @inject */ | ||
public UserRepository $userRepository; | ||
|
||
/** | ||
* @throws AbortException | ||
*/ | ||
public function actionIcal(int $id) : void | ||
{ | ||
$calendar = new Calendar('-//Junák - český skaut//SRS//CS'); | ||
|
||
$user = $this->userRepository->findById($id); | ||
$programs = $user->getPrograms(); | ||
|
||
foreach ($programs as $program) { | ||
$event = new Event(); | ||
$event->setDtStart($program->getStart()) | ||
->setDtEnd($program->getEnd()) | ||
->setSummary($program->getBlock()->getName()) | ||
->setDescription($program->getBlock()->getDescription()); | ||
|
||
if (! $program->getBlock()->getLectors()->isEmpty()) { | ||
$event->setOrganizer(new Organizer($program->getBlock()->getLectorsText())); | ||
} | ||
|
||
if ($program->getRoom() !== null) { | ||
$event->setLocation($program->getRoom()->getName()); | ||
} | ||
|
||
$calendar->addComponent($event); | ||
} | ||
|
||
$icalResponse = new IcalResponse($calendar, 'harmonogram.ics'); | ||
$this->sendResponse($icalResponse); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Services; | ||
|
||
use Eluceo\iCal\Component\Calendar; | ||
use Nette; | ||
use Nette\Application\IResponse; | ||
|
||
/** | ||
* IcalResponse. | ||
* | ||
* @author Jan Staněk <jan.stanek@skaut.cz> | ||
*/ | ||
class IcalResponse implements IResponse | ||
{ | ||
use Nette\SmartObject; | ||
|
||
private Calendar $calendar; | ||
|
||
private string $filename; | ||
|
||
public function __construct(Calendar $calendar, string $filename) | ||
{ | ||
$this->calendar = $calendar; | ||
$this->filename = $filename; | ||
} | ||
|
||
public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse) : void | ||
{ | ||
$httpResponse->setContentType('text/calendar', 'utf-8'); | ||
$httpResponse->setHeader('Content-Disposition', 'attachment;filename=' . $this->filename); | ||
|
||
echo $this->calendar->render(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.