summaryrefslogtreecommitdiff
path: root/backend/php/src/objects/class.record.php
Unidiff
Diffstat (limited to 'backend/php/src/objects/class.record.php') (more/less context) (ignore whitespace changes)
-rw-r--r--backend/php/src/objects/class.record.php436
1 files changed, 436 insertions, 0 deletions
diff --git a/backend/php/src/objects/class.record.php b/backend/php/src/objects/class.record.php
new file mode 100644
index 0000000..a269e75
--- a/dev/null
+++ b/backend/php/src/objects/class.record.php
@@ -0,0 +1,436 @@
1<?php
2/*
3 This SQL query will create the table to store your object.
4
5 CREATE TABLE `record` (
6 `recordid` int(11) NOT NULL auto_increment,
7 `userid` int(11) NOT NULL,
8 `reference` VARCHAR(255) NOT NULL,
9 `data` LONGTEXT NOT NULL,
10 `version` VARCHAR(255) NOT NULL,
11 `creation_date` TIMESTAMP NOT NULL,
12 `update_date` TIMESTAMP NOT NULL,
13 `access_date` TIMESTAMP NOT NULL, INDEX(`userid`), PRIMARY KEY (`recordid`)) ENGINE=MyISAM;
14*/
15
16/**
17* <b>record</b> class with integrated CRUD methods.
18* @author Php Object Generator
19* @version POG 3.0e / PHP5.1 MYSQL
20* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
21* @copyright Free for personal & commercial use. (Offered under the BSD license)
22* @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=record&attributeList=array+%28%0A++0+%3D%3E+%27user%27%2C%0A++1+%3D%3E+%27recordversion%27%2C%0A++2+%3D%3E+%27reference%27%2C%0A++3+%3D%3E+%27data%27%2C%0A++4+%3D%3E+%27version%27%2C%0A++5+%3D%3E+%27creation_date%27%2C%0A++6+%3D%3E+%27update_date%27%2C%0A++7+%3D%3E+%27access_date%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527BELONGSTO%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2529
23*/
24include_once('class.pog_base.php');
25class record extends POG_Base
26{
27 public $recordId = '';
28
29 /**
30 * @var INT(11)
31 */
32 public $userId;
33
34 /**
35 * @var private array of recordversion objects
36 */
37 private $_recordversionList = array();
38
39 /**
40 * @var VARCHAR(255)
41 */
42 public $reference;
43
44 /**
45 * @var LONGTEXT
46 */
47 public $data;
48
49 /**
50 * @var VARCHAR(255)
51 */
52 public $version;
53
54 /**
55 * @var TIMESTAMP
56 */
57 public $creation_date;
58
59 /**
60 * @var TIMESTAMP
61 */
62 public $update_date;
63
64 /**
65 * @var TIMESTAMP
66 */
67 public $access_date;
68
69 public $pog_attribute_type = array(
70 "recordId" => array('db_attributes' => array("NUMERIC", "INT")),
71 "user" => array('db_attributes' => array("OBJECT", "BELONGSTO")),
72 "recordversion" => array('db_attributes' => array("OBJECT", "HASMANY")),
73 "reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
74 "data" => array('db_attributes' => array("TEXT", "LONGTEXT")),
75 "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
76 "creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
77 "update_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
78 "access_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
79 );
80 public $pog_query;
81
82
83 /**
84 * Getter for some private attributes
85 * @return mixed $attribute
86 */
87 public function __get($attribute)
88 {
89 if (isset($this->{"_".$attribute}))
90 {
91 return $this->{"_".$attribute};
92 }
93 else
94 {
95 return false;
96 }
97 }
98
99 function record($reference='', $data='', $version='', $creation_date='', $update_date='', $access_date='')
100 {
101 $this->_recordversionList = array();
102 $this->reference = $reference;
103 $this->data = $data;
104 $this->version = $version;
105 $this->creation_date = $creation_date;
106 $this->update_date = $update_date;
107 $this->access_date = $access_date;
108 }
109
110
111 /**
112 * Gets object from database
113 * @param integer $recordId
114 * @return object $record
115 */
116 function Get($recordId)
117 {
118 $connection = Database::Connect();
119 $this->pog_query = "select * from `record` where `recordid`='".intval($recordId)."' LIMIT 1";
120 $cursor = Database::Reader($this->pog_query, $connection);
121 while ($row = Database::Read($cursor))
122 {
123 $this->recordId = $row['recordid'];
124 $this->userId = $row['userid'];
125 $this->reference = $this->Unescape($row['reference']);
126 $this->data = $this->Unescape($row['data']);
127 $this->version = $this->Unescape($row['version']);
128 $this->creation_date = $row['creation_date'];
129 $this->update_date = $row['update_date'];
130 $this->access_date = $row['access_date'];
131 }
132 return $this;
133 }
134
135
136 /**
137 * Returns a sorted array of objects that match given conditions
138 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
139 * @param string $sortBy
140 * @param boolean $ascending
141 * @param int limit
142 * @return array $recordList
143 */
144 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
145 {
146 $connection = Database::Connect();
147 $sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
148 $this->pog_query = "select * from `record` ";
149 $recordList = Array();
150 if (sizeof($fcv_array) > 0)
151 {
152 $this->pog_query .= " where ";
153 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
154 {
155 if (sizeof($fcv_array[$i]) == 1)
156 {
157 $this->pog_query .= " ".$fcv_array[$i][0]." ";
158 continue;
159 }
160 else
161 {
162 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
163 {
164 $this->pog_query .= " AND ";
165 }
166 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
167 {
168 if ($GLOBALS['configuration']['db_encoding'] == 1)
169 {
170 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
171 $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
172 }
173 else
174 {
175 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
176 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
177 }
178 }
179 else
180 {
181 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
182 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
183 }
184 }
185 }
186 }
187 if ($sortBy != '')
188 {
189 if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
190 {
191 if ($GLOBALS['configuration']['db_encoding'] == 1)
192 {
193 $sortBy = "BASE64_DECODE($sortBy) ";
194 }
195 else
196 {
197 $sortBy = "$sortBy ";
198 }
199 }
200 else
201 {
202 $sortBy = "$sortBy ";
203 }
204 }
205 else
206 {
207 $sortBy = "recordid";
208 }
209 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
210 $thisObjectName = get_class($this);
211 $cursor = Database::Reader($this->pog_query, $connection);
212 while ($row = Database::Read($cursor))
213 {
214 $record = new $thisObjectName();
215 $record->recordId = $row['recordid'];
216 $record->userId = $row['userid'];
217 $record->reference = $this->Unescape($row['reference']);
218 $record->data = $this->Unescape($row['data']);
219 $record->version = $this->Unescape($row['version']);
220 $record->creation_date = $row['creation_date'];
221 $record->update_date = $row['update_date'];
222 $record->access_date = $row['access_date'];
223 $recordList[] = $record;
224 }
225 return $recordList;
226 }
227
228
229 /**
230 * Saves the object to the database
231 * @return integer $recordId
232 */
233 function Save($deep = true)
234 {
235 $connection = Database::Connect();
236 $this->pog_query = "select `recordid` from `record` where `recordid`='".$this->recordId."' LIMIT 1";
237 $rows = Database::Query($this->pog_query, $connection);
238 if ($rows > 0)
239 {
240 $this->pog_query = "update `record` set
241 `userid`='".$this->userId."',
242 `reference`='".$this->Escape($this->reference)."',
243 `data`='".$this->Escape($this->data)."',
244 `version`='".$this->Escape($this->version)."',
245 `creation_date`='".$this->creation_date."',
246 `update_date`='".$this->update_date."',
247 `access_date`='".$this->access_date."' where `recordid`='".$this->recordId."'";
248 }
249 else
250 {
251 $this->pog_query = "insert into `record` (`userid`, `reference`, `data`, `version`, `creation_date`, `update_date`, `access_date` ) values (
252 '".$this->userId."',
253 '".$this->Escape($this->reference)."',
254 '".$this->Escape($this->data)."',
255 '".$this->Escape($this->version)."',
256 '".$this->creation_date."',
257 '".$this->update_date."',
258 '".$this->access_date."' )";
259 }
260 $insertId = Database::InsertOrUpdate($this->pog_query, $connection);
261 if ($this->recordId == "")
262 {
263 $this->recordId = $insertId;
264 }
265 if ($deep)
266 {
267 foreach ($this->_recordversionList as $recordversion)
268 {
269 $recordversion->recordId = $this->recordId;
270 $recordversion->Save($deep);
271 }
272 }
273 return $this->recordId;
274 }
275
276
277 /**
278 * Clones the object and saves it to the database
279 * @return integer $recordId
280 */
281 function SaveNew($deep = false)
282 {
283 $this->recordId = '';
284 return $this->Save($deep);
285 }
286
287
288 /**
289 * Deletes the object from the database
290 * @return boolean
291 */
292 function Delete($deep = false, $across = false)
293 {
294 if ($deep)
295 {
296 $recordversionList = $this->GetRecordversionList();
297 foreach ($recordversionList as $recordversion)
298 {
299 $recordversion->Delete($deep, $across);
300 }
301 }
302 $connection = Database::Connect();
303 $this->pog_query = "delete from `record` where `recordid`='".$this->recordId."'";
304 return Database::NonQuery($this->pog_query, $connection);
305 }
306
307
308 /**
309 * Deletes a list of objects that match given conditions
310 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
311 * @param bool $deep
312 * @return
313 */
314 function DeleteList($fcv_array, $deep = false, $across = false)
315 {
316 if (sizeof($fcv_array) > 0)
317 {
318 if ($deep || $across)
319 {
320 $objectList = $this->GetList($fcv_array);
321 foreach ($objectList as $object)
322 {
323 $object->Delete($deep, $across);
324 }
325 }
326 else
327 {
328 $connection = Database::Connect();
329 $pog_query = "delete from `record` where ";
330 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
331 {
332 if (sizeof($fcv_array[$i]) == 1)
333 {
334 $pog_query .= " ".$fcv_array[$i][0]." ";
335 continue;
336 }
337 else
338 {
339 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
340 {
341 $pog_query .= " AND ";
342 }
343 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
344 {
345 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
346 }
347 else
348 {
349 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
350 }
351 }
352 }
353 return Database::NonQuery($pog_query, $connection);
354 }
355 }
356 }
357
358
359 /**
360 * Associates the user object to this one
361 * @return boolean
362 */
363 function GetUser()
364 {
365 $user = new user();
366 return $user->Get($this->userId);
367 }
368
369
370 /**
371 * Associates the user object to this one
372 * @return
373 */
374 function SetUser(&$user)
375 {
376 $this->userId = $user->userId;
377 }
378
379
380 /**
381 * Gets a list of recordversion objects associated to this one
382 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
383 * @param string $sortBy
384 * @param boolean $ascending
385 * @param int limit
386 * @return array of recordversion objects
387 */
388 function GetRecordversionList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
389 {
390 $recordversion = new recordversion();
391 $fcv_array[] = array("recordId", "=", $this->recordId);
392 $dbObjects = $recordversion->GetList($fcv_array, $sortBy, $ascending, $limit);
393 return $dbObjects;
394 }
395
396
397 /**
398 * Makes this the parent of all recordversion objects in the recordversion List array. Any existing recordversion will become orphan(s)
399 * @return null
400 */
401 function SetRecordversionList(&$list)
402 {
403 $this->_recordversionList = array();
404 $existingRecordversionList = $this->GetRecordversionList();
405 foreach ($existingRecordversionList as $recordversion)
406 {
407 $recordversion->recordId = '';
408 $recordversion->Save(false);
409 }
410 $this->_recordversionList = $list;
411 }
412
413
414 /**
415 * Associates the recordversion object to this one
416 * @return
417 */
418 function AddRecordversion(&$recordversion)
419 {
420 $recordversion->recordId = $this->recordId;
421 $found = false;
422 foreach($this->_recordversionList as $recordversion2)
423 {
424 if ($recordversion->recordversionId > 0 && $recordversion->recordversionId == $recordversion2->recordversionId)
425 {
426 $found = true;
427 break;
428 }
429 }
430 if (!$found)
431 {
432 $this->_recordversionList[] = $recordversion;
433 }
434 }
435}
436?> \ No newline at end of file