From 42721e95726559b4a601240bb5b0fe4e5d755b2a Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 27 Nov 2019 23:43:21 +0100 Subject: Added Schedule parsing and replaced old Fahrplan importer Resolves #553 (Change Frab Import from xCal to XML) Resolves #538 (Feature Request: Multi Frab Import) --- src/Helpers/Schedule/Event.php | 337 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100644 src/Helpers/Schedule/Event.php (limited to 'src/Helpers/Schedule/Event.php') diff --git a/src/Helpers/Schedule/Event.php b/src/Helpers/Schedule/Event.php new file mode 100644 index 00000000..46970e7b --- /dev/null +++ b/src/Helpers/Schedule/Event.php @@ -0,0 +1,337 @@ + name */ + protected $persons; + + /** @var string|null two letter code */ + protected $language; + + /** @var string|null */ + protected $description; + + /** @var string|null license (and opt out in XML, null if not recorded, empty if no license defined) */ + protected $recording; + + /** @var array href => title */ + protected $links; + + /** @var array href => name */ + protected $attachments; + + /** @var string|null */ + protected $url; + + /** @var string|null */ + protected $videoDownloadUrl; + + /** @var Carbon Calculated */ + protected $endDate; + + /** + * Event constructor. + * + * @param string $guid + * @param int $id + * @param Room $room + * @param string $title + * @param string $subtitle + * @param string $type + * @param Carbon $date + * @param string $start + * @param string $duration + * @param string $abstract + * @param string $slug + * @param string $track + * @param string|null $logo + * @param string[] $persons + * @param string|null $language + * @param string|null $description + * @param string|null $recording license + * @param array $links + * @param array $attachments + * @param string|null $url + * @param string|null $videoDownloadUrl + */ + public function __construct( + string $guid, + int $id, + Room $room, + string $title, + string $subtitle, + string $type, + Carbon $date, + string $start, + string $duration, + string $abstract, + string $slug, + string $track, + ?string $logo = null, + array $persons = [], + ?string $language = null, + ?string $description = null, + string $recording = '', + array $links = [], + array $attachments = [], + ?string $url = null, + ?string $videoDownloadUrl = null + ) { + $this->guid = $guid; + $this->id = $id; + $this->room = $room; + $this->title = $title; + $this->subtitle = $subtitle; + $this->type = $type; + $this->date = $date; + $this->start = $start; + $this->duration = $duration; + $this->abstract = $abstract; + $this->slug = $slug; + $this->track = $track; + $this->logo = $logo; + $this->persons = $persons; + $this->language = $language; + $this->description = $description; + $this->recording = $recording; + $this->links = $links; + $this->attachments = $attachments; + $this->url = $url; + $this->videoDownloadUrl = $videoDownloadUrl; + + $this->endDate = $this->date + ->copy() + ->addSeconds($this->getDurationSeconds()); + } + + /** + * @return string + */ + public function getGuid(): string + { + return $this->guid; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return Room + */ + public function getRoom(): Room + { + return $this->room; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @return string + */ + public function getSubtitle(): string + { + return $this->subtitle; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @return Carbon + */ + public function getDate(): Carbon + { + return $this->date; + } + + /** + * @return string + */ + public function getStart(): string + { + return $this->start; + } + + /** + * @return string + */ + public function getDuration(): string + { + return $this->duration; + } + + /** + * @return int + */ + public function getDurationSeconds(): int + { + return $this->secondsFromTime($this->duration); + } + + /** + * @return string + */ + public function getAbstract(): string + { + return $this->abstract; + } + + /** + * @return string + */ + public function getSlug(): string + { + return $this->slug; + } + + /** + * @return string + */ + public function getTrack(): string + { + return $this->track; + } + + /** + * @return string|null + */ + public function getLogo(): ?string + { + return $this->logo; + } + + /** + * @return string[] + */ + public function getPersons(): array + { + return $this->persons; + } + + /** + * @return string|null + */ + public function getLanguage(): ?string + { + return $this->language; + } + + /** + * @return string|null + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @return string|null + */ + public function getRecording(): ?string + { + return $this->recording; + } + + /** + * @return array + */ + public function getLinks(): array + { + return $this->links; + } + + /** + * @return array + */ + public function getAttachments(): array + { + return $this->attachments; + } + + /** + * @return string|null + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @return string|null + */ + public function getVideoDownloadUrl(): ?string + { + return $this->videoDownloadUrl; + } + + /** + * @return Carbon + */ + public function getEndDate(): Carbon + { + return $this->endDate; + } +} -- cgit v1.3.1 From 47e209e12594b935ba1670096ae4c55538ebde94 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 30 Nov 2019 01:15:39 +0100 Subject: ImportSchedule: Append talk language to shift title Resolves #587 (Include talk language into Frab-imported shift titles) --- includes/pages/schedule/ImportSchedule.php | 1 + src/Helpers/Schedule/Event.php | 8 ++++++++ tests/Unit/Helpers/Schedule/EventTest.php | 4 ++++ 3 files changed, 13 insertions(+) (limited to 'src/Helpers/Schedule/Event.php') diff --git a/includes/pages/schedule/ImportSchedule.php b/includes/pages/schedule/ImportSchedule.php index 1b03b57b..8bc769d4 100644 --- a/includes/pages/schedule/ImportSchedule.php +++ b/includes/pages/schedule/ImportSchedule.php @@ -440,6 +440,7 @@ class ImportSchedule extends BaseController $event->getDate()->subMinutes($minutesBefore); $event->getEndDate()->addMinutes($minutesAfter); + $event->setTitle(sprintf('%s [%s]', $event->getTitle(), $event->getLanguage())); } } } diff --git a/src/Helpers/Schedule/Event.php b/src/Helpers/Schedule/Event.php index 46970e7b..ab3b39a5 100644 --- a/src/Helpers/Schedule/Event.php +++ b/src/Helpers/Schedule/Event.php @@ -183,6 +183,14 @@ class Event return $this->title; } + /** + * @param string $title + */ + public function setTitle(string $title): void + { + $this->title = $title; + } + /** * @return string */ diff --git a/tests/Unit/Helpers/Schedule/EventTest.php b/tests/Unit/Helpers/Schedule/EventTest.php index 262aeea7..d9706b13 100644 --- a/tests/Unit/Helpers/Schedule/EventTest.php +++ b/tests/Unit/Helpers/Schedule/EventTest.php @@ -84,6 +84,7 @@ class EventTest extends TestCase * @covers \Engelsystem\Helpers\Schedule\Event::getId * @covers \Engelsystem\Helpers\Schedule\Event::getRoom * @covers \Engelsystem\Helpers\Schedule\Event::getTitle + * @covers \Engelsystem\Helpers\Schedule\Event::setTitle * @covers \Engelsystem\Helpers\Schedule\Event::getSubtitle * @covers \Engelsystem\Helpers\Schedule\Event::getType * @covers \Engelsystem\Helpers\Schedule\Event::getDate @@ -141,5 +142,8 @@ class EventTest extends TestCase $this->assertEquals($attachments, $event->getAttachments()); $this->assertEquals('https://foo.bar/2-lorem', $event->getUrl()); $this->assertEquals('https://videos.orem.ipsum/2-lorem.mp4', $event->getVideoDownloadUrl()); + + $event->setTitle('Event title'); + $this->assertEquals('Event title', $event->getTitle()); } } -- cgit v1.3.1