summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/php/controls/UrlBasedCalendarControl.php33
-rw-r--r--app/php/facades/CalendarFacade.php11
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;
+ }
+
}
?>