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