summaryrefslogtreecommitdiff
path: root/app/php/facades/CalendarFacade.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/php/facades/CalendarFacade.php')
-rw-r--r--app/php/facades/CalendarFacade.php39
1 files changed, 32 insertions, 7 deletions
diff --git a/app/php/facades/CalendarFacade.php b/app/php/facades/CalendarFacade.php
index 232acf3..b15eac3 100644
--- a/app/php/facades/CalendarFacade.php
+++ b/app/php/facades/CalendarFacade.php
@@ -135,7 +135,11 @@ class CalendarFacade extends Facade {
}
public function getAll() {
- return Calendar::finder()->withCategory()->findAll('ORDER BY name ASC');
+ $records = Calendar::finder()->withCategory()->findAll('ORDER BY name ASC');
+ foreach ($records as $record) {
+ $this->_fillUrlCache($record);
+ }
+ return $records;
}
public function getCategories() {
@@ -143,15 +147,36 @@ class CalendarFacade extends Facade {
}
public function get($uid) {
- return Calendar::finder()->withCategory()->findAllByPks($uid);
+ $records = Calendar::finder()->withCategory()->findAllByPks($uid);
+ foreach ($records as $record) {
+ $this->_fillUrlCache($record);
+ }
+ return $records;
+ }
+
+ private $_urlCache = [];
+ private function _fillUrlCache($record) {
+ if ($record && $record->CustomUrl
+ && !isset($this->_urlCache[$record->CustomUrl])) {
+ $dto = new CalendarDTO();
+ if ($record) {
+ $dto->loadRecord($record);
+ } else {
+ $dto = NULL;
+ }
+ return $this->_urlCache[$record->CustomUrl] = $dto;
+ }
}
public function resolveUrl($url) {
- $dto = new CalendarDTO();
- $record = Calendar::finder()->findByCustomUrl($url);
- if ($record) {
- $dto->loadRecord($record);
- return $dto;
+ if ($url) {
+ if (isset($this->_urlCache[$url])) {
+ return $this->_urlCache[$url];
+ }
+ $record = Calendar::finder()->findByCustomUrl($url);
+ if ($record) {
+ return $this->_fillUrlCache($record);
+ }
}
return NULL;
}