|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\ExportModule\Presenters; |
| 6 | + |
| 7 | +use App\Model\User\UserRepository; |
| 8 | +use App\Services\IcalResponse; |
| 9 | +use Eluceo\iCal\Component\Calendar; |
| 10 | +use Eluceo\iCal\Component\Event; |
| 11 | +use Eluceo\iCal\Property\Event\Organizer; |
| 12 | +use Nette\Application\AbortException; |
| 13 | + |
| 14 | +/** |
| 15 | + * Presenter pro generování kalendáře ve formátu ICS. |
| 16 | + * |
| 17 | + * @author Jan Staněk <[email protected]> |
| 18 | + */ |
| 19 | +class SchedulePresenter extends ExportBasePresenter |
| 20 | +{ |
| 21 | + /** @inject */ |
| 22 | + public UserRepository $userRepository; |
| 23 | + |
| 24 | + /** |
| 25 | + * @throws AbortException |
| 26 | + */ |
| 27 | + public function actionIcal(int $id) : void |
| 28 | + { |
| 29 | + $calendar = new Calendar('-//Junák - český skaut//SRS//CS'); |
| 30 | + |
| 31 | + $user = $this->userRepository->findById($id); |
| 32 | + $programs = $user->getPrograms(); |
| 33 | + |
| 34 | + foreach ($programs as $program) { |
| 35 | + $event = new Event(); |
| 36 | + $event->setDtStart($program->getStart()) |
| 37 | + ->setDtEnd($program->getEnd()) |
| 38 | + ->setSummary($program->getBlock()->getName()) |
| 39 | + ->setDescription($program->getBlock()->getDescription()); |
| 40 | + |
| 41 | + if (! $program->getBlock()->getLectors()->isEmpty()) { |
| 42 | + $event->setOrganizer(new Organizer($program->getBlock()->getLectorsText())); |
| 43 | + } |
| 44 | + |
| 45 | + if ($program->getRoom() !== null) { |
| 46 | + $event->setLocation($program->getRoom()->getName()); |
| 47 | + } |
| 48 | + |
| 49 | + $calendar->addComponent($event); |
| 50 | + } |
| 51 | + |
| 52 | + $icalResponse = new IcalResponse($calendar, 'harmonogram.ics'); |
| 53 | + $this->sendResponse($icalResponse); |
| 54 | + } |
| 55 | +} |
0 commit comments