Skip to content

Commit

Permalink
export harmonogramu do ical (#741)
Browse files Browse the repository at this point in the history
* export harmonogramu do ical

* coding standard
  • Loading branch information
jan-stanek authored Jun 1, 2020
1 parent 484ce8d commit 171d40e
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 10 deletions.
55 changes: 55 additions & 0 deletions app/ExportModule/Presenters/SchedulePresenter.php
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);
}
}
37 changes: 37 additions & 0 deletions app/Services/IcalResponse.php
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();
}
}
2 changes: 1 addition & 1 deletion app/WebModule/Forms/RolesFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion app/WebModule/Presenters/ProfilePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
24 changes: 23 additions & 1 deletion app/WebModule/Presenters/templates/Profile/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,31 @@
</div>
<div class="row mb-3">
<div class="col">
<a n:href="exportschedule" class="btn btn-primary">{_web.profile.download_schedule}</a>
<div class="btn-toolbar">
<a n:href="exportschedule" class="btn btn-secondary mr-2">{_web.profile.download_schedule_excel}</a>

<div class="input-group">
<div class="input-group-prepend">
<a n:href=":Export:Schedule:ical $user->id" class="btn btn-secondary">
{_web.profile.download_schedule_ical}
</a>
</div>
<input type="text" class="form-control" id="schedule-url" value="{plink //:Export:Schedule:ical $user->id}">
<div class="input-group-append">
<button class="btn btn-outline-secondary" onclick="clipboard()" title="{_web.profile.download_schedule_ical_copy}">
<span class="fa fa-clipboard">
</button>
</div>
</div>
</div>
</div>
</div>
<script>
function clipboard() {
document.getElementById('schedule-url').select();
document.execCommand('copy');
}
</script>
{/if}
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion app/lang/web.cs_CZ.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,24 @@
"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",

"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",
Expand Down
53 changes: 52 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 171d40e

Please sign in to comment.