summaryrefslogtreecommitdiff
path: root/app/frontend/model
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-06-07 15:17:49 +0200
committeremkael <emkael@tlen.pl>2016-06-10 11:46:41 +0200
commit823d71ced9b4947b1a5a5ade7245d521ed490061 (patch)
treea9a6c7cb0de74ff705e8320c284de423a698f5b5 /app/frontend/model
parentdf401552aac363655ab8f056a6c910a7611954d6 (diff)
* renaming php directory
Diffstat (limited to 'app/frontend/model')
-rw-r--r--app/frontend/model/Calendar.php92
-rw-r--r--app/frontend/model/Category.php30
-rw-r--r--app/frontend/model/Entry.php43
-rw-r--r--app/frontend/model/User.php36
-rw-r--r--app/frontend/model/UserPreference.php23
-rw-r--r--app/frontend/model/config.xml9
6 files changed, 233 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();
+ }
+
+}
+
+?>
diff --git a/app/frontend/model/Category.php b/app/frontend/model/Category.php
new file mode 100644
index 0000000..87b97b6
--- /dev/null
+++ b/app/frontend/model/Category.php
@@ -0,0 +1,30 @@
+<?php
+
+Prado::using('Application.db.ActiveRecord');
+Prado::using('Application.model.Calendar');
+
+class Category extends ActiveRecord {
+
+ const TABLE = 'categories';
+
+ public $ID;
+ public $Name;
+ public $Priority;
+
+ public static $COLUMN_MAPPING = [
+ 'id' => 'ID',
+ 'name' => 'Name',
+ 'priority' => 'Priority'
+ ];
+
+ public static $RELATIONS = [
+ 'Calendars' => [self::HAS_MANY, 'Calendar', '_category']
+ ];
+
+ public static function finder($className=__CLASS__) {
+ return parent::finder($className);
+ }
+
+}
+
+?>
diff --git a/app/frontend/model/Entry.php b/app/frontend/model/Entry.php
new file mode 100644
index 0000000..4b93f04
--- /dev/null
+++ b/app/frontend/model/Entry.php
@@ -0,0 +1,43 @@
+<?php
+
+Prado::using('Application.db.ActiveRecord');
+Prado::using('Application.model.Calendar');
+
+class Entry extends ActiveRecord {
+
+ const TABLE = 'entries';
+
+ public $ID;
+ public $UID;
+ public $BeginDate;
+ public $EndDate;
+ public $AllDay;
+ public $Name;
+ public $Location;
+ public $LastModified;
+
+ public $CalendarID;
+
+ public static $COLUMN_MAPPING = [
+ 'id' => 'ID',
+ 'uid' => 'UID',
+ 'begin_date' => 'BeginDate',
+ 'end_date' => 'EndDate',
+ 'all_day' => 'AllDay',
+ 'name' => 'Name',
+ 'location' => 'Location',
+ 'last_modified' => 'LastModified',
+ '_calendar' => 'CalendarID'
+ ];
+
+ public static $RELATIONS = [
+ 'Calendar' => [self::BELONGS_TO, 'Calendar', '_calendar']
+ ];
+
+ public static function finder($className=__CLASS__) {
+ return parent::finder($className);
+ }
+
+}
+
+?>
diff --git a/app/frontend/model/User.php b/app/frontend/model/User.php
new file mode 100644
index 0000000..d431183
--- /dev/null
+++ b/app/frontend/model/User.php
@@ -0,0 +1,36 @@
+<?php
+
+Prado::using('Application.db.ActiveRecord');
+Prado::using('Application.model.Calendar');
+
+class User extends ActiveRecord {
+
+ const TABLE = 'users';
+
+ public $ID;
+ public $Login;
+ public $Password;
+ public $IsAdmin;
+ public $Timezone;
+ public $LastLogin;
+
+ public static $COLUMN_MAPPING = [
+ 'id' => 'ID',
+ 'login' => 'Login',
+ 'password' => 'Password',
+ 'is_admin' => 'IsAdmin',
+ 'timezone' => 'Timezone',
+ 'last_login' => 'LastLogin'
+ ];
+
+ public static $RELATIONS = [
+ 'Calendars' => [self::MANY_TO_MANY, 'Calendar', 'user_selections']
+ ];
+
+ public static function finder($className=__CLASS__) {
+ return parent::finder($className);
+ }
+
+}
+
+?>
diff --git a/app/frontend/model/UserPreference.php b/app/frontend/model/UserPreference.php
new file mode 100644
index 0000000..90fa221
--- /dev/null
+++ b/app/frontend/model/UserPreference.php
@@ -0,0 +1,23 @@
+<?php
+
+Prado::using('Application.db.ActiveRecord');
+
+class UserPreference extends ActiveRecord {
+
+ const TABLE = 'user_selections';
+
+ public $UserID;
+ public $CalendarID;
+
+ public static $COLUMN_MAPPING = [
+ '_user' => 'UserID',
+ '_calendar' => 'CalendarID'
+ ];
+
+ public static function finder($className=__CLASS__) {
+ return parent::finder($className);
+ }
+
+}
+
+?>
diff --git a/app/frontend/model/config.xml b/app/frontend/model/config.xml
new file mode 100644
index 0000000..a729150
--- /dev/null
+++ b/app/frontend/model/config.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <modules>
+ <module id="active-record"
+ class="System.Data.ActiveRecord.TActiveRecordConfig"
+ ConnectionID="db"
+ EnableCache="true" />
+ </modules>
+</configuration>