summaryrefslogtreecommitdiff
path: root/app/frontend/model/Calendar.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/frontend/model/Calendar.php')
-rw-r--r--app/frontend/model/Calendar.php92
1 files changed, 92 insertions, 0 deletions
diff --git a/app/frontend/model/Calendar.php b/app/frontend/model/Calendar.php
new file mode 100644
index 0000000..b49bf92
--- /dev/null
+++ b/app/frontend/model/Calendar.php
@@ -0,0 +1,92 @@
+<?php
+
+Prado::using('Application.db.ActiveRecord');
+Prado::using('Application.model.Entry');
+Prado::using('Application.model.Category');
+
+class Calendar extends ActiveRecord {
+
+ const TABLE = 'calendars';
+
+ public $UID;
+ public $Url;
+ public $Name;
+ public $Website;
+ public $Visible;
+ public $CustomName;
+ public $CustomImage;
+ public $CustomUrl;
+ public $LastUpdated;
+
+ public $CategoryID;
+
+ public static $COLUMN_MAPPING = [
+ 'uid' => 'UID',
+ 'url' => 'Url',
+ 'name' => 'Name',
+ 'website' => 'Website',
+ 'visible' => 'Visible',
+ 'last_updated' => 'LastUpdated',
+ 'custom_name' => 'CustomName',
+ 'custom_image' => 'CustomImage',
+ 'custom_url' => 'CustomUrl',
+ '_category' => 'CategoryID'
+ ];
+
+ public static $RELATIONS = [
+ 'Entries' => [self::HAS_MANY, 'Entry', '_calendar'],
+ 'Category' => [self::BELONGS_TO, 'Category', '_category']
+ ];
+
+ public static function finder($className=__CLASS__) {
+ return parent::finder($className);
+ }
+
+ const CUSTOM_IMAGE_PATH = 'resources/images/calendars';
+
+ public function getCustomImageUrl() {
+ if ($this->CustomImage) {
+ if (!preg_match('#^//#', $this->CustomImage)) {
+ return Prado::getApplication()->getAssetManager()->publishFilePath(
+ implode(
+ DIRECTORY_SEPARATOR,
+ [
+ Prado::getApplication()->getBasePath(),
+ self::CUSTOM_IMAGE_PATH,
+ $this->CustomImage
+ ]
+ ),
+ TRUE
+ );
+ }
+ return $this->CustomImage;
+ }
+ }
+
+ public function getCustomImagePath($forFile = NULL, $type = '') {
+ $pathParts = [
+ Prado::getApplication()->getBasePath(),
+ self::CUSTOM_IMAGE_PATH
+ ];
+ if ($forFile) {
+ $pathParts[] = $this->_getCustomImageHash($forFile, $type);
+ }
+ return implode(DIRECTORY_SEPARATOR, $pathParts);
+ }
+
+ private function _getCustomImageHash($file, $type) {
+ $hash = md5($file . md5_file($file) . filemtime($file));
+ if ($type) {
+ $hash .= '.' . preg_replace('#^image/#', '', $type);
+ }
+ return $hash;
+ }
+
+ public function saveData($data) {
+ $this->copyFrom($data);
+ return $this->save();
+ }
+
+}
+
+?>