author | Josh <jokajak@gmail.com> | 2011-10-05 20:40:29 (UTC) |
---|---|---|
committer | Josh <jokajak@gmail.com> | 2011-10-06 01:58:00 (UTC) |
commit | a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa (patch) (unidiff) | |
tree | 3ca0b96e843f5820f0bee7dede1847b014bba1e6 /backend/php/src/objects/class.record.php | |
parent | 6ba274c79e60e417132b260bd0117c5a68121387 (diff) | |
download | clipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.zip clipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.tar.gz clipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.tar.bz2 |
Fix timestamps on records
- update the access and update date when a record is saved
- set the creation date when a record is created
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.php | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/backend/php/src/objects/class.record.php b/backend/php/src/objects/class.record.php index a269e75..37a9702 100644 --- a/backend/php/src/objects/class.record.php +++ b/backend/php/src/objects/class.record.php | |||
@@ -1,36 +1,36 @@ | |||
1 | <?php | 1 | <?php |
2 | /* | 2 | /* |
3 | This SQL query will create the table to store your object. | 3 | This SQL query will create the table to store your object. |
4 | 4 | ||
5 | CREATE TABLE `record` ( | 5 | CREATE TABLE `record` ( |
6 | `recordid` int(11) NOT NULL auto_increment, | 6 | `recordid` int(11) NOT NULL auto_increment, |
7 | `userid` int(11) NOT NULL, | 7 | `userid` int(11) NOT NULL, |
8 | `reference` VARCHAR(255) NOT NULL, | 8 | `reference` VARCHAR(255) NOT NULL, |
9 | `data` LONGTEXT NOT NULL, | 9 | `data` LONGTEXT NOT NULL, |
10 | `version` VARCHAR(255) NOT NULL, | 10 | `version` VARCHAR(255) NOT NULL, |
11 | `creation_date` TIMESTAMP NOT NULL, | 11 | `creation_date` TIMESTAMP NOT NULL, |
12 | `update_date` TIMESTAMP NOT NULL, | 12 | `update_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
13 | `access_date` TIMESTAMP NOT NULL, INDEX(`userid`), PRIMARY KEY (`recordid`)) ENGINE=MyISAM; | 13 | `access_date` TIMESTAMP NOT NULL, INDEX(`userid`), PRIMARY KEY (`recordid`)) ENGINE=MyISAM; |
14 | */ | 14 | */ |
15 | 15 | ||
16 | /** | 16 | /** |
17 | * <b>record</b> class with integrated CRUD methods. | 17 | * <b>record</b> class with integrated CRUD methods. |
18 | * @author Php Object Generator | 18 | * @author Php Object Generator |
19 | * @version POG 3.0e / PHP5.1 MYSQL | 19 | * @version POG 3.0e / PHP5.1 MYSQL |
20 | * @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql | 20 | * @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql |
21 | * @copyright Free for personal & commercial use. (Offered under the BSD license) | 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 | 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 | */ | 23 | */ |
24 | include_once('class.pog_base.php'); | 24 | include_once('class.pog_base.php'); |
25 | class record extends POG_Base | 25 | class record extends POG_Base |
26 | { | 26 | { |
27 | public $recordId = ''; | 27 | public $recordId = ''; |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * @var INT(11) | 30 | * @var INT(11) |
31 | */ | 31 | */ |
32 | public $userId; | 32 | public $userId; |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * @var private array of recordversion objects | 35 | * @var private array of recordversion objects |
36 | */ | 36 | */ |
@@ -105,49 +105,50 @@ class record extends POG_Base | |||
105 | $this->creation_date = $creation_date; | 105 | $this->creation_date = $creation_date; |
106 | $this->update_date = $update_date; | 106 | $this->update_date = $update_date; |
107 | $this->access_date = $access_date; | 107 | $this->access_date = $access_date; |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | /** | 111 | /** |
112 | * Gets object from database | 112 | * Gets object from database |
113 | * @param integer $recordId | 113 | * @param integer $recordId |
114 | * @return object $record | 114 | * @return object $record |
115 | */ | 115 | */ |
116 | function Get($recordId) | 116 | function Get($recordId) |
117 | { | 117 | { |
118 | $connection = Database::Connect(); | 118 | $connection = Database::Connect(); |
119 | $this->pog_query = "select * from `record` where `recordid`='".intval($recordId)."' LIMIT 1"; | 119 | $this->pog_query = "select * from `record` where `recordid`='".intval($recordId)."' LIMIT 1"; |
120 | $cursor = Database::Reader($this->pog_query, $connection); | 120 | $cursor = Database::Reader($this->pog_query, $connection); |
121 | while ($row = Database::Read($cursor)) | 121 | while ($row = Database::Read($cursor)) |
122 | { | 122 | { |
123 | $this->recordId = $row['recordid']; | 123 | $this->recordId = $row['recordid']; |
124 | $this->userId = $row['userid']; | 124 | $this->userId = $row['userid']; |
125 | $this->reference = $this->Unescape($row['reference']); | 125 | $this->reference = $this->Unescape($row['reference']); |
126 | $this->data = $this->Unescape($row['data']); | 126 | $this->data = $this->Unescape($row['data']); |
127 | $this->version = $this->Unescape($row['version']); | 127 | $this->version = $this->Unescape($row['version']); |
128 | $this->creation_date = $row['creation_date']; | 128 | $this->creation_date = $row['creation_date']; |
129 | $this->update_date = $row['update_date']; | 129 | $oDate = strtotime($row['update_date']); |
130 | $this->update_date = date('r', $oDate); | ||
130 | $this->access_date = $row['access_date']; | 131 | $this->access_date = $row['access_date']; |
131 | } | 132 | } |
132 | return $this; | 133 | return $this; |
133 | } | 134 | } |
134 | 135 | ||
135 | 136 | ||
136 | /** | 137 | /** |
137 | * Returns a sorted array of objects that match given conditions | 138 | * Returns a sorted array of objects that match given conditions |
138 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} | 139 | * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} |
139 | * @param string $sortBy | 140 | * @param string $sortBy |
140 | * @param boolean $ascending | 141 | * @param boolean $ascending |
141 | * @param int limit | 142 | * @param int limit |
142 | * @return array $recordList | 143 | * @return array $recordList |
143 | */ | 144 | */ |
144 | function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') | 145 | function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='') |
145 | { | 146 | { |
146 | $connection = Database::Connect(); | 147 | $connection = Database::Connect(); |
147 | $sqlLimit = ($limit != '' ? "LIMIT $limit" : ''); | 148 | $sqlLimit = ($limit != '' ? "LIMIT $limit" : ''); |
148 | $this->pog_query = "select * from `record` "; | 149 | $this->pog_query = "select * from `record` "; |
149 | $recordList = Array(); | 150 | $recordList = Array(); |
150 | if (sizeof($fcv_array) > 0) | 151 | if (sizeof($fcv_array) > 0) |
151 | { | 152 | { |
152 | $this->pog_query .= " where "; | 153 | $this->pog_query .= " where "; |
153 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) | 154 | for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++) |
@@ -197,111 +198,115 @@ class record extends POG_Base | |||
197 | $sortBy = "$sortBy "; | 198 | $sortBy = "$sortBy "; |
198 | } | 199 | } |
199 | } | 200 | } |
200 | else | 201 | else |
201 | { | 202 | { |
202 | $sortBy = "$sortBy "; | 203 | $sortBy = "$sortBy "; |
203 | } | 204 | } |
204 | } | 205 | } |
205 | else | 206 | else |
206 | { | 207 | { |
207 | $sortBy = "recordid"; | 208 | $sortBy = "recordid"; |
208 | } | 209 | } |
209 | $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit"; | 210 | $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit"; |
210 | $thisObjectName = get_class($this); | 211 | $thisObjectName = get_class($this); |
211 | $cursor = Database::Reader($this->pog_query, $connection); | 212 | $cursor = Database::Reader($this->pog_query, $connection); |
212 | while ($row = Database::Read($cursor)) | 213 | while ($row = Database::Read($cursor)) |
213 | { | 214 | { |
214 | $record = new $thisObjectName(); | 215 | $record = new $thisObjectName(); |
215 | $record->recordId = $row['recordid']; | 216 | $record->recordId = $row['recordid']; |
216 | $record->userId = $row['userid']; | 217 | $record->userId = $row['userid']; |
217 | $record->reference = $this->Unescape($row['reference']); | 218 | $record->reference = $this->Unescape($row['reference']); |
218 | $record->data = $this->Unescape($row['data']); | 219 | $record->data = $this->Unescape($row['data']); |
219 | $record->version = $this->Unescape($row['version']); | 220 | $record->version = $this->Unescape($row['version']); |
220 | $record->creation_date = $row['creation_date']; | 221 | $record->creation_date = $row['creation_date']; |
221 | $record->update_date = $row['update_date']; | 222 | $oDate = strtotime($row['update_date']); |
223 | $record->update_date = date('r', $oDate); | ||
222 | $record->access_date = $row['access_date']; | 224 | $record->access_date = $row['access_date']; |
223 | $recordList[] = $record; | 225 | $recordList[] = $record; |
224 | } | 226 | } |
225 | return $recordList; | 227 | return $recordList; |
226 | } | 228 | } |
227 | 229 | ||
228 | 230 | ||
229 | /** | 231 | /** |
230 | * Saves the object to the database | 232 | * Saves the object to the database |
231 | * @return integer $recordId | 233 | * @return integer $recordId |
232 | */ | 234 | */ |
233 | function Save($deep = true) | 235 | function Save($deep = true) |
234 | { | 236 | { |
235 | $connection = Database::Connect(); | 237 | $connection = Database::Connect(); |
238 | $this->update_date = date( 'r'); | ||
239 | $this->access_date = date( 'r'); | ||
236 | $this->pog_query = "select `recordid` from `record` where `recordid`='".$this->recordId."' LIMIT 1"; | 240 | $this->pog_query = "select `recordid` from `record` where `recordid`='".$this->recordId."' LIMIT 1"; |
237 | $rows = Database::Query($this->pog_query, $connection); | 241 | $rows = Database::Query($this->pog_query, $connection); |
238 | if ($rows > 0) | 242 | if ($rows > 0) |
239 | { | 243 | { |
240 | $this->pog_query = "update `record` set | 244 | $this->pog_query = "update `record` set |
241 | `userid`='".$this->userId."', | 245 | `userid`='".$this->userId."', |
242 | `reference`='".$this->Escape($this->reference)."', | 246 | `reference`='".$this->Escape($this->reference)."', |
243 | `data`='".$this->Escape($this->data)."', | 247 | `data`='".$this->Escape($this->data)."', |
244 | `version`='".$this->Escape($this->version)."', | 248 | `version`='".$this->Escape($this->version)."', |
245 | `creation_date`='".$this->creation_date."', | 249 | `creation_date`='".$this->creation_date."', |
246 | `update_date`='".$this->update_date."', | 250 | `update_date`='".$this->update_date."', |
247 | `access_date`='".$this->access_date."' where `recordid`='".$this->recordId."'"; | 251 | `access_date`='".$this->access_date."' where `recordid`='".$this->recordId."'"; |
248 | } | 252 | } |
249 | else | 253 | else |
250 | { | 254 | { |
251 | $this->pog_query = "insert into `record` (`userid`, `reference`, `data`, `version`, `creation_date`, `update_date`, `access_date` ) values ( | 255 | $this->pog_query = "insert into `record` (`userid`, `reference`, `data`, `version`, `creation_date`, `update_date`, `access_date` ) values ( |
252 | '".$this->userId."', | 256 | '".$this->userId."', |
253 | '".$this->Escape($this->reference)."', | 257 | '".$this->Escape($this->reference)."', |
254 | '".$this->Escape($this->data)."', | 258 | '".$this->Escape($this->data)."', |
255 | '".$this->Escape($this->version)."', | 259 | '".$this->Escape($this->version)."', |
256 | '".$this->creation_date."', | 260 | '".$this->creation_date."', |
257 | '".$this->update_date."', | 261 | '".$this->update_date."', |
258 | '".$this->access_date."' )"; | 262 | '".$this->access_date."' )"; |
259 | } | 263 | } |
260 | $insertId = Database::InsertOrUpdate($this->pog_query, $connection); | 264 | $insertId = Database::InsertOrUpdate($this->pog_query, $connection); |
261 | if ($this->recordId == "") | 265 | if ($this->recordId == "") |
262 | { | 266 | { |
263 | $this->recordId = $insertId; | 267 | $this->recordId = $insertId; |
264 | } | 268 | } |
265 | if ($deep) | 269 | if ($deep) |
266 | { | 270 | { |
267 | foreach ($this->_recordversionList as $recordversion) | 271 | foreach ($this->_recordversionList as $recordversion) |
268 | { | 272 | { |
269 | $recordversion->recordId = $this->recordId; | 273 | $recordversion->recordId = $this->recordId; |
270 | $recordversion->Save($deep); | 274 | $recordversion->Save($deep); |
271 | } | 275 | } |
272 | } | 276 | } |
273 | return $this->recordId; | 277 | return $this->recordId; |
274 | } | 278 | } |
275 | 279 | ||
276 | 280 | ||
277 | /** | 281 | /** |
278 | * Clones the object and saves it to the database | 282 | * Clones the object and saves it to the database |
279 | * @return integer $recordId | 283 | * @return integer $recordId |
280 | */ | 284 | */ |
281 | function SaveNew($deep = false) | 285 | function SaveNew($deep = false) |
282 | { | 286 | { |
283 | $this->recordId = ''; | 287 | $this->recordId = ''; |
288 | $this->creation_date = date( 'Y-m-d H:i:s'); | ||
284 | return $this->Save($deep); | 289 | return $this->Save($deep); |
285 | } | 290 | } |
286 | 291 | ||
287 | 292 | ||
288 | /** | 293 | /** |
289 | * Deletes the object from the database | 294 | * Deletes the object from the database |
290 | * @return boolean | 295 | * @return boolean |
291 | */ | 296 | */ |
292 | function Delete($deep = false, $across = false) | 297 | function Delete($deep = false, $across = false) |
293 | { | 298 | { |
294 | if ($deep) | 299 | if ($deep) |
295 | { | 300 | { |
296 | $recordversionList = $this->GetRecordversionList(); | 301 | $recordversionList = $this->GetRecordversionList(); |
297 | foreach ($recordversionList as $recordversion) | 302 | foreach ($recordversionList as $recordversion) |
298 | { | 303 | { |
299 | $recordversion->Delete($deep, $across); | 304 | $recordversion->Delete($deep, $across); |
300 | } | 305 | } |
301 | } | 306 | } |
302 | $connection = Database::Connect(); | 307 | $connection = Database::Connect(); |
303 | $this->pog_query = "delete from `record` where `recordid`='".$this->recordId."'"; | 308 | $this->pog_query = "delete from `record` where `recordid`='".$this->recordId."'"; |
304 | return Database::NonQuery($this->pog_query, $connection); | 309 | return Database::NonQuery($this->pog_query, $connection); |
305 | } | 310 | } |
306 | 311 | ||
307 | 312 | ||
@@ -412,25 +417,25 @@ class record extends POG_Base | |||
412 | 417 | ||
413 | 418 | ||
414 | /** | 419 | /** |
415 | * Associates the recordversion object to this one | 420 | * Associates the recordversion object to this one |
416 | * @return | 421 | * @return |
417 | */ | 422 | */ |
418 | function AddRecordversion(&$recordversion) | 423 | function AddRecordversion(&$recordversion) |
419 | { | 424 | { |
420 | $recordversion->recordId = $this->recordId; | 425 | $recordversion->recordId = $this->recordId; |
421 | $found = false; | 426 | $found = false; |
422 | foreach($this->_recordversionList as $recordversion2) | 427 | foreach($this->_recordversionList as $recordversion2) |
423 | { | 428 | { |
424 | if ($recordversion->recordversionId > 0 && $recordversion->recordversionId == $recordversion2->recordversionId) | 429 | if ($recordversion->recordversionId > 0 && $recordversion->recordversionId == $recordversion2->recordversionId) |
425 | { | 430 | { |
426 | $found = true; | 431 | $found = true; |
427 | break; | 432 | break; |
428 | } | 433 | } |
429 | } | 434 | } |
430 | if (!$found) | 435 | if (!$found) |
431 | { | 436 | { |
432 | $this->_recordversionList[] = $recordversion; | 437 | $this->_recordversionList[] = $recordversion; |
433 | } | 438 | } |
434 | } | 439 | } |
435 | } | 440 | } |
436 | ?> \ No newline at end of file | 441 | ?> |