From bdd798916cef168d3ce57e1039bf22cd617beff6 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 4 May 2016 15:43:10 +0200 Subject: * controls capable of resolving calendar URLs --- app/php/controls/UrlBasedCalendarControl.php | 33 ++++++++++++++++++++++++++++ app/php/facades/CalendarFacade.php | 11 ++++++++++ 2 files changed, 44 insertions(+) create mode 100644 app/php/controls/UrlBasedCalendarControl.php (limited to 'app/php') diff --git a/app/php/controls/UrlBasedCalendarControl.php b/app/php/controls/UrlBasedCalendarControl.php new file mode 100644 index 0000000..89d05a1 --- /dev/null +++ b/app/php/controls/UrlBasedCalendarControl.php @@ -0,0 +1,33 @@ +setViewState('Facade', $facade); + } + + public function getFacade() { + return $this->getViewState('Facade'); + } + + public function setCalendarUrl($url) { + if ($url) { + $calendar = $this->getFacade()->resolveUrl($url); + if ($calendar) { + $this->setViewState('Calendar', $calendar); + return; + } + } + throw new THttpException(404, 'Page not found'); + } + + public function getCalendar() { + return $this->getViewState('Calendar'); + } + +} + +?> diff --git a/app/php/facades/CalendarFacade.php b/app/php/facades/CalendarFacade.php index 4b00a03..71ddcb4 100644 --- a/app/php/facades/CalendarFacade.php +++ b/app/php/facades/CalendarFacade.php @@ -1,6 +1,7 @@ withCategory()->findAllByPks($uid); } + public function resolveUrl($url) { + $dto = new CalendarDTO(); + $record = Calendar::finder()->findByCustomUrl($url); + if ($record) { + $dto->loadRecord($record); + return $dto; + } + return NULL; + } + } ?> -- cgit v1.2.3