summaryrefslogtreecommitdiff
path: root/app/php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-03-15 22:06:47 +0100
committeremkael <emkael@tlen.pl>2016-03-15 22:06:47 +0100
commitcc09e963e8ef7ea093c7b13096856e5c732cd776 (patch)
tree9da36344800f23ed05b00df914e2b9c71e86ccee /app/php
parent6dcabb240f0ff0ee1654ac66f806bedb22495d23 (diff)
* extending TActiveRecord so it's capable of fetching mapped column fields from sql maps
Diffstat (limited to 'app/php')
-rw-r--r--app/php/db/ActiveRecord.php30
-rw-r--r--app/php/model/Calendar.php11
-rw-r--r--app/php/model/Category.php7
-rw-r--r--app/php/model/Entry.php7
-rw-r--r--app/php/model/User.php3
-rw-r--r--app/php/model/UserPreference.php4
6 files changed, 49 insertions, 13 deletions
diff --git a/app/php/db/ActiveRecord.php b/app/php/db/ActiveRecord.php
new file mode 100644
index 0000000..f5d06a3
--- /dev/null
+++ b/app/php/db/ActiveRecord.php
@@ -0,0 +1,30 @@
+<?php
+
+class ActiveRecord extends TActiveRecord {
+
+ private function _getMappedPropertyName($name) {
+ if (isset(static::$COLUMN_MAPPING[$name])) {
+ return static::$COLUMN_MAPPING[$name];
+ }
+ return $name;
+ }
+
+ public function __get($name) {
+ $name = $this->_getMappedPropertyName($name);
+ if (property_exists($this, $name)) {
+ return $this->$name;
+ }
+ return parent::__get($name);
+ }
+
+ public function __set($name, $value) {
+ $name = $this->_getMappedPropertyName($name);
+ if (property_exists($this, $name)) {
+ return $this->$name = $value;
+ }
+ return parent::__set($this->_getMappedPropertyName($name), $value);
+ }
+
+}
+
+?>
diff --git a/app/php/model/Calendar.php b/app/php/model/Calendar.php
index 4438572..9e1afce 100644
--- a/app/php/model/Calendar.php
+++ b/app/php/model/Calendar.php
@@ -1,12 +1,13 @@
<?php
+Prado::using('Application.db.ActiveRecord');
Prado::using('Application.model.Entry');
Prado::using('Application.model.Category');
-class Calendar extends TActiveRecord {
+class Calendar extends ActiveRecord {
const TABLE = 'calendars';
-
+
public $UID;
public $Url;
public $Name;
@@ -23,18 +24,18 @@ class Calendar extends TActiveRecord {
'website' => 'Website',
'visible' => 'Visible',
'last_updated' => 'LastUpdated',
- '_category' => 'CategoryID'
+ '_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);
}
-
+
}
?>
diff --git a/app/php/model/Category.php b/app/php/model/Category.php
index 03a368a..5e71e53 100644
--- a/app/php/model/Category.php
+++ b/app/php/model/Category.php
@@ -1,8 +1,9 @@
<?php
+Prado::using('Application.db.ActiveRecord');
Prado::using('Application.model.Calendar');
-class Category extends TActiveRecord {
+class Category extends ActiveRecord {
const TABLE = 'categories';
@@ -17,11 +18,11 @@ class Category extends TActiveRecord {
public static $RELATIONS = [
'Calendars' => [self::HAS_MANY, 'Calendar', '_category']
];
-
+
public static function finder($className=__CLASS__) {
return parent::finder($className);
}
-
+
}
?>
diff --git a/app/php/model/Entry.php b/app/php/model/Entry.php
index 85d522f..3106e8e 100644
--- a/app/php/model/Entry.php
+++ b/app/php/model/Entry.php
@@ -1,8 +1,9 @@
<?php
+Prado::using('Application.db.ActiveRecord');
Prado::using('Application.model.Calendar');
-class Entry extends TActiveRecord {
+class Entry extends ActiveRecord {
const TABLE = 'entries';
@@ -30,11 +31,11 @@ class Entry extends TActiveRecord {
public static $RELATIONS = [
'Calendar' => [self::BELONGS_TO, 'Calendar', '_calendar']
];
-
+
public static function finder($className=__CLASS__) {
return parent::finder($className);
}
-
+
}
?>
diff --git a/app/php/model/User.php b/app/php/model/User.php
index b31b926..baa9912 100644
--- a/app/php/model/User.php
+++ b/app/php/model/User.php
@@ -1,8 +1,9 @@
<?php
+Prado::using('Application.db.ActiveRecord');
Prado::using('Application.model.Calendar');
-class User extends TActiveRecord {
+class User extends ActiveRecord {
const TABLE = 'users';
diff --git a/app/php/model/UserPreference.php b/app/php/model/UserPreference.php
index ff32529..90fa221 100644
--- a/app/php/model/UserPreference.php
+++ b/app/php/model/UserPreference.php
@@ -1,6 +1,8 @@
<?php
-class UserPreference extends TActiveRecord {
+Prado::using('Application.db.ActiveRecord');
+
+class UserPreference extends ActiveRecord {
const TABLE = 'user_selections';