Skip to content

Commit 171d40e

Browse files
authored
export harmonogramu do ical (#741)
* export harmonogramu do ical * coding standard
1 parent 484ce8d commit 171d40e

File tree

8 files changed

+178
-10
lines changed

8 files changed

+178
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
}

app/Services/IcalResponse.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Services;
6+
7+
use Eluceo\iCal\Component\Calendar;
8+
use Nette;
9+
use Nette\Application\IResponse;
10+
11+
/**
12+
* IcalResponse.
13+
*
14+
* @author Jan Staněk <[email protected]>
15+
*/
16+
class IcalResponse implements IResponse
17+
{
18+
use Nette\SmartObject;
19+
20+
private Calendar $calendar;
21+
22+
private string $filename;
23+
24+
public function __construct(Calendar $calendar, string $filename)
25+
{
26+
$this->calendar = $calendar;
27+
$this->filename = $filename;
28+
}
29+
30+
public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse) : void
31+
{
32+
$httpResponse->setContentType('text/calendar', 'utf-8');
33+
$httpResponse->setHeader('Content-Disposition', 'attachment;filename=' . $this->filename);
34+
35+
echo $this->calendar->render();
36+
}
37+
}

app/WebModule/Forms/RolesFormFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function create(int $id) : Form
151151
$ticketDownloadFrom = $this->settingsService->getDateTimeValue(Settings::TICKETS_FROM);
152152
if ($ticketDownloadFrom !== null) {
153153
$downloadTicketButton = $form->addSubmit('downloadTicket', 'web.profile.download_ticket')
154-
->setHtmlAttribute('class', 'btn-success');
154+
->setHtmlAttribute('class', 'btn-secondary');
155155

156156
if ($this->user->isInRole($this->roleRepository->findBySystemName(Role::NONREGISTERED))
157157
|| ! $this->user->hasPaidEveryApplication()

app/WebModule/Presenters/ProfilePresenter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function renderDefault() : void
9292
public function actionExportSchedule() : void
9393
{
9494
$user = $this->userRepository->findById($this->user->id);
95-
$response = $this->excelExportService->exportUserSchedule($user, 'harmonogram-seminare.xlsx');
95+
$response = $this->excelExportService->exportUserSchedule($user, 'harmonogram.xlsx');
9696
$this->sendResponse($response);
9797
}
9898

app/WebModule/Presenters/templates/Profile/default.latte

+23-1
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,31 @@
159159
</div>
160160
<div class="row mb-3">
161161
<div class="col">
162-
<a n:href="exportschedule" class="btn btn-primary">{_web.profile.download_schedule}</a>
162+
<div class="btn-toolbar">
163+
<a n:href="exportschedule" class="btn btn-secondary mr-2">{_web.profile.download_schedule_excel}</a>
164+
165+
<div class="input-group">
166+
<div class="input-group-prepend">
167+
<a n:href=":Export:Schedule:ical $user->id" class="btn btn-secondary">
168+
{_web.profile.download_schedule_ical}
169+
</a>
170+
</div>
171+
<input type="text" class="form-control" id="schedule-url" value="{plink //:Export:Schedule:ical $user->id}">
172+
<div class="input-group-append">
173+
<button class="btn btn-outline-secondary" onclick="clipboard()" title="{_web.profile.download_schedule_ical_copy}">
174+
<span class="fa fa-clipboard">
175+
</button>
176+
</div>
177+
</div>
178+
</div>
163179
</div>
164180
</div>
181+
<script>
182+
function clipboard() {
183+
document.getElementById('schedule-url').select();
184+
document.execCommand('copy');
185+
}
186+
</script>
165187
{/if}
166188
</div>
167189
</div>

app/lang/web.cs_CZ.neon

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ profile:
110110
room: "Místnost"
111111
lectors: "Lektoři"
112112
no_programs: "Nemáte zvolené žádné programy."
113-
download_schedule: "Stáhnout harmonogram"
113+
download_schedule_excel: "Stáhnout harmonogram (XLSX)"
114+
download_schedule_ical: "Stáhnout harmonogram (ICS)"
115+
download_schedule_ical_copy: "Kopírovat URL kalendáře"
114116

115117
member:
116118
name: "Nepropojený účet člena"

composer.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,24 @@
4343
"nextras/forms-rendering": "^1.0",
4444
"vojtys/nette-forms-gpspicker": "dev-master",
4545

46+
"bicisteadm/webloader-reload": "^3.0",
47+
4648
"twbs/bootstrap": "^4.5",
4749
"snapappointments/bootstrap-select": "^1.13",
4850
"kartik-v/bootstrap-fileinput": "^5.0",
4951

5052
"ublaboo/datagrid": "^6.2",
5153
"ublaboo/mailing": "^1.2",
5254

53-
"bicisteadm/webloader-reload": "^3.0",
5455
"jms/serializer": "^3.6",
55-
56-
"skautis/skautis": "^2.1",
57-
"skautis/nette": "^2.2",
58-
5956
"phpoffice/phpspreadsheet": "^1.12",
6057
"joseki/pdf-response": "^5.1",
6158
"mpdf/qrcode": "^1.0",
6259
"dfridrich/qr-platba": "^1.0",
60+
"eluceo/ical": "^0.16",
61+
62+
"skautis/skautis": "^2.1",
63+
"skautis/nette": "^2.2",
6364

6465
"pear/numbers_words": "^0.18",
6566
"azuyalabs/yasumi": "^1.8",

composer.lock

+52-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)