diff options
author | emkael <emkael@tlen.pl> | 2016-05-04 15:43:10 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-05-04 15:48:28 +0200 |
commit | bdd798916cef168d3ce57e1039bf22cd617beff6 (patch) | |
tree | 4f20162f6fedda6f89cf90d02e101db38ea9d9aa /app | |
parent | 46afd2ec473ec4adc7e1de2a0d59872ba84288b1 (diff) |
* controls capable of resolving calendar URLs
Diffstat (limited to 'app')
-rw-r--r-- | app/php/controls/UrlBasedCalendarControl.php | 33 | ||||
-rw-r--r-- | app/php/facades/CalendarFacade.php | 11 |
2 files changed, 44 insertions, 0 deletions
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 @@ +<?php + +Prado::using('Application.web.TemplateControl'); +Prado::using('Application.facades.CalendarFacade'); + +class UrlBasedCalendarControl extends TemplateControl { + + public function setFacade(Facade $facade) { + $this->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 @@ <?php Prado::using('Application.facades.Facade'); +Prado::using('Application.dto.CalendarDTO'); Prado::using('Application.dto.CalendarGroupDTO'); Prado::using('Application.model.Calendar'); Prado::using('Application.model.Category'); @@ -62,6 +63,16 @@ class CalendarFacade extends Facade { return Calendar::finder()->withCategory()->findAllByPks($uid); } + public function resolveUrl($url) { + $dto = new CalendarDTO(); + $record = Calendar::finder()->findByCustomUrl($url); + if ($record) { + $dto->loadRecord($record); + return $dto; + } + return NULL; + } + } ?> |