summaryrefslogtreecommitdiff
path: root/backend/php/src/objects/class.pog_base.php
Unidiff
Diffstat (limited to 'backend/php/src/objects/class.pog_base.php') (more/less context) (ignore whitespace changes)
-rw-r--r--backend/php/src/objects/class.pog_base.php143
1 files changed, 143 insertions, 0 deletions
diff --git a/backend/php/src/objects/class.pog_base.php b/backend/php/src/objects/class.pog_base.php
new file mode 100644
index 0000000..6a8f570
--- a/dev/null
+++ b/backend/php/src/objects/class.pog_base.php
@@ -0,0 +1,143 @@
1<?php
2class POG_Base
3{
4 /**
5 * Overloading
6 */
7 function __call($method, $argv)
8 {
9 include_once($GLOBALS['configuration']['plugins_path']."/IPlugin.php");
10 include_once($GLOBALS['configuration']['plugins_path']."/plugin.".strtolower($method).".php");
11 eval('$plugin = new $method($this,$argv);');
12 return $plugin->Execute();
13 }
14
15 /**
16 * constructor
17 *
18 * @return POG_Base
19 */
20 private function POG_Base()
21 {
22 }
23
24
25 function SetFieldAttribute($fieldName, $attributeName, $attributeValue)
26 {
27 if (isset($this->pog_attribute_type[$fieldName]) && isset($this->pog_attribute_type[$fieldName][$attributeName]))
28 {
29 $this->pog_attribute_type[$fieldName][$attributeName] = $attributeValue;
30 }
31 }
32
33 function GetFieldAttribute($fieldName, $attributeName)
34 {
35 if (isset($this->pog_attribute_type[$fieldName]) && isset($this->pog_attribute_type[$fieldName][$attributeName]))
36 {
37 return $this->pog_attribute_type[$fieldName][$attributeName];
38 }
39 return null;
40 }
41
42 ///////////////////////////
43 // Data manipulation
44 ///////////////////////////
45
46 /**
47 * This function will try to encode $text to base64, except when $text is a number. This allows us to Escape all data before they're inserted in the database, regardless of attribute type.
48 * @param string $text
49 * @return string encoded to base64
50 */
51 public function Escape($text)
52 {
53 if ($GLOBALS['configuration']['db_encoding'] && !is_numeric($text))
54 {
55 return base64_encode($text);
56 }
57 return addslashes($text);
58 }
59
60 /**
61 * Enter description here...
62 *
63 * @param unknown_type $text
64 * @return unknown
65 */
66 public function Unescape($text)
67 {
68 if ($GLOBALS['configuration']['db_encoding'] && !is_numeric($text))
69 {
70 return base64_decode($text);
71 }
72 return stripcslashes($text);
73 }
74
75
76 ////////////////////////////////
77 // Table -> Object Mapping
78 ////////////////////////////////
79
80 /**
81 * Executes $query against database and returns the result set as an array of POG objects
82 *
83 * @param string $query. SQL query to execute against database
84 * @param string $objectClass. POG Object type to return
85 * @param bool $lazy. If true, will also load all children/sibling
86 */
87 public function FetchObjects($query, $objectClass, $lazy = true)
88 {
89 $databaseConnection = Database::Connect();
90 $result = Database::Query($query, $databaseConnection);
91 $objectList = $this->CreateObjects($result, $objectClass, $lazy);
92 return $objectList;
93 }
94
95 private function CreateObjects($mysql_result, $objectClass, $lazyLoad = true)
96 {
97 $objectList = array();
98 while ($row = mysql_fetch_assoc($mysql_result))
99 {
100 $pog_object = new $objectClass();
101 $this->PopulateObjectAttributes($row, $pog_object);
102 $objectList[] = $pog_object;
103 }
104 return $objectList;
105 }
106
107 private function PopulateObjectAttributes($fetched_row, $pog_object)
108 {
109 foreach ($this->GetAttributes($pog_object) as $column)
110 {
111 $pog_object->{$column} = $this->Unescape($fetched_row[strtolower($column)]);
112 }
113 return $pog_object;
114 }
115
116 private function GetAttributes($object)
117 {
118 $columns = array();
119 foreach ($object->pog_attribute_type as $att => $properties)
120 {
121 if ($properties['db_attributes'][0] != 'OBJECT')
122 {
123 $columns[] = $att;
124 }
125 }
126 return $columns;
127 }
128
129 //misc
130 public static function IsColumn($value)
131 {
132 if (strlen($value) > 2)
133 {
134 if (substr($value, 0, 1) == '`' && substr($value, strlen($value) - 1, 1) == '`')
135 {
136 return true;
137 }
138 return false;
139 }
140 return false;
141 }
142}
143?> \ No newline at end of file