From 171d40eb4b00bc5fbcee477ce94ceadfc47a7d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= Date: Mon, 1 Jun 2020 22:39:26 +0200 Subject: [PATCH] export harmonogramu do ical (#741) * export harmonogramu do ical * coding standard --- .../Presenters/SchedulePresenter.php | 55 +++++++++++++++++++ app/Services/IcalResponse.php | 37 +++++++++++++ app/WebModule/Forms/RolesFormFactory.php | 2 +- app/WebModule/Presenters/ProfilePresenter.php | 2 +- .../templates/Profile/default.latte | 24 +++++++- app/lang/web.cs_CZ.neon | 4 +- composer.json | 11 ++-- composer.lock | 53 +++++++++++++++++- 8 files changed, 178 insertions(+), 10 deletions(-) create mode 100644 app/ExportModule/Presenters/SchedulePresenter.php create mode 100644 app/Services/IcalResponse.php diff --git a/app/ExportModule/Presenters/SchedulePresenter.php b/app/ExportModule/Presenters/SchedulePresenter.php new file mode 100644 index 000000000..34a3b7d82 --- /dev/null +++ b/app/ExportModule/Presenters/SchedulePresenter.php @@ -0,0 +1,55 @@ + + */ +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); + } +} diff --git a/app/Services/IcalResponse.php b/app/Services/IcalResponse.php new file mode 100644 index 000000000..7980641fa --- /dev/null +++ b/app/Services/IcalResponse.php @@ -0,0 +1,37 @@ + + */ +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(); + } +} diff --git a/app/WebModule/Forms/RolesFormFactory.php b/app/WebModule/Forms/RolesFormFactory.php index f3bf54156..aa07d5a61 100644 --- a/app/WebModule/Forms/RolesFormFactory.php +++ b/app/WebModule/Forms/RolesFormFactory.php @@ -151,7 +151,7 @@ public function create(int $id) : Form $ticketDownloadFrom = $this->settingsService->getDateTimeValue(Settings::TICKETS_FROM); if ($ticketDownloadFrom !== null) { $downloadTicketButton = $form->addSubmit('downloadTicket', 'web.profile.download_ticket') - ->setHtmlAttribute('class', 'btn-success'); + ->setHtmlAttribute('class', 'btn-secondary'); if ($this->user->isInRole($this->roleRepository->findBySystemName(Role::NONREGISTERED)) || ! $this->user->hasPaidEveryApplication() diff --git a/app/WebModule/Presenters/ProfilePresenter.php b/app/WebModule/Presenters/ProfilePresenter.php index 65920a65c..d24b561e3 100644 --- a/app/WebModule/Presenters/ProfilePresenter.php +++ b/app/WebModule/Presenters/ProfilePresenter.php @@ -92,7 +92,7 @@ public function renderDefault() : void public function actionExportSchedule() : void { $user = $this->userRepository->findById($this->user->id); - $response = $this->excelExportService->exportUserSchedule($user, 'harmonogram-seminare.xlsx'); + $response = $this->excelExportService->exportUserSchedule($user, 'harmonogram.xlsx'); $this->sendResponse($response); } diff --git a/app/WebModule/Presenters/templates/Profile/default.latte b/app/WebModule/Presenters/templates/Profile/default.latte index 8e5c20a2f..8b103b35d 100644 --- a/app/WebModule/Presenters/templates/Profile/default.latte +++ b/app/WebModule/Presenters/templates/Profile/default.latte @@ -159,9 +159,31 @@
+ {/if} diff --git a/app/lang/web.cs_CZ.neon b/app/lang/web.cs_CZ.neon index f6b936ea3..72bae2bdd 100644 --- a/app/lang/web.cs_CZ.neon +++ b/app/lang/web.cs_CZ.neon @@ -110,7 +110,9 @@ profile: room: "Místnost" lectors: "Lektoři" no_programs: "Nemáte zvolené žádné programy." - download_schedule: "Stáhnout harmonogram" + download_schedule_excel: "Stáhnout harmonogram (XLSX)" + download_schedule_ical: "Stáhnout harmonogram (ICS)" + download_schedule_ical_copy: "Kopírovat URL kalendáře" member: name: "Nepropojený účet člena" diff --git a/composer.json b/composer.json index 97227b025..b96912d9f 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,8 @@ "nextras/forms-rendering": "^1.0", "vojtys/nette-forms-gpspicker": "dev-master", + "bicisteadm/webloader-reload": "^3.0", + "twbs/bootstrap": "^4.5", "snapappointments/bootstrap-select": "^1.13", "kartik-v/bootstrap-fileinput": "^5.0", @@ -50,16 +52,15 @@ "ublaboo/datagrid": "^6.2", "ublaboo/mailing": "^1.2", - "bicisteadm/webloader-reload": "^3.0", "jms/serializer": "^3.6", - - "skautis/skautis": "^2.1", - "skautis/nette": "^2.2", - "phpoffice/phpspreadsheet": "^1.12", "joseki/pdf-response": "^5.1", "mpdf/qrcode": "^1.0", "dfridrich/qr-platba": "^1.0", + "eluceo/ical": "^0.16", + + "skautis/skautis": "^2.1", + "skautis/nette": "^2.2", "pear/numbers_words": "^0.18", "azuyalabs/yasumi": "^1.8", diff --git a/composer.lock b/composer.lock index f87932130..4df99848f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "741937d9bf97cd0f833df3ebf1e38c78", + "content-hash": "0bc2766d5b941d31ecc4a48cd638f9b3", "packages": [ { "name": "azuyalabs/yasumi", @@ -1606,6 +1606,57 @@ ], "time": "2020-03-27T11:06:43+00:00" }, + { + "name": "eluceo/ical", + "version": "0.16.0", + "source": { + "type": "git", + "url": "https://github.com/markuspoerschke/iCal.git", + "reference": "97da0d94c9716e65c141066a2d96aa098379721b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/markuspoerschke/iCal/zipball/97da0d94c9716e65c141066a2d96aa098379721b", + "reference": "97da0d94c9716e65c141066a2d96aa098379721b", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "suggest": { + "ext-mbstring": "Massive performance enhancement of line folding" + }, + "type": "library", + "autoload": { + "psr-4": { + "Eluceo\\iCal\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Markus Poerschke", + "email": "markus@eluceo.de", + "role": "Developer" + } + ], + "description": "The eluceo/iCal package offers a abstraction layer for creating iCalendars. You can easily create iCal files by using PHP object instead of typing your *.ics file by hand. The output will follow RFC 5545 as best as possible.", + "homepage": "https://github.com/markuspoerschke/iCal", + "keywords": [ + "calendar", + "iCalendar", + "ical", + "ics", + "php calendar" + ], + "time": "2019-12-29T22:08:56+00:00" + }, { "name": "endroid/qr-code", "version": "2.5.0",