gyro/core/model/base/dataobjecttimestampedcached.cls.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * Base class for items where creation and modification date is of interest 00004 * 00005 * If used, just array_merge your table fields and $this->get_timestamp_field_declarations(): 00006 * 00007 * @code 00008 * ..., 00009 * array_merge(array( 00010 * new DBFieldInt('id', ...), 00011 * .. more of your fields ... 00012 * ), $this->get_timestamp_field_declarations() 00013 * ), 00014 * ... 00015 * @endcode 00016 * 00017 * @since 0.5.1 00018 * 00019 * @author Gerd Riesselmann 00020 * @ingroup model 00021 */ 00022 class DataObjectTimestampedCached extends DataObjectCached implements ITimeStamped { 00023 public $creationdate; 00024 public $modificationdate; 00025 00026 /** 00027 * Returns array of field instances for ceration- and modificationdate 00028 * 00029 * @return array 00030 */ 00031 protected function get_timestamp_field_declarations() { 00032 return array( 00033 new DBFieldDateTime('creationdate', DBFieldDateTime::NOW, DBFieldDateTime::NOT_NULL | DBField::INTERNAL), 00034 new DBFieldDateTime('modificationdate', DBFieldDateTime::NOW, DBFieldDateTime::TIMESTAMP | DBFieldDateTime::NOT_NULL | DBField::INTERNAL), 00035 ); 00036 } 00037 00038 /** 00039 * Insert data. Autoincrement IDs will be automatically set. 00040 * 00041 * @return Status 00042 */ 00043 public function insert() { 00044 $this->modificationdate = time(); 00045 $this->creationdate = time(); 00046 return parent::insert(); 00047 } 00048 00049 /** 00050 * Update current item 00051 * 00052 * @param int $policy If DBDataObject::WHERE_ONLY is used, no conditions are build automatically 00053 * @return Status 00054 */ 00055 public function update($policy = self::NORMAL) { 00056 $this->modificationdate = time(); 00057 return parent::update($policy); 00058 } 00059 00060 // --------------------------------- 00061 // ITimestamped 00062 // --------------------------------- 00063 00064 /** 00065 * Return creation date and time 00066 * 00067 * @return timestamp 00068 */ 00069 public function get_creation_date() { 00070 return $this->creationdate; 00071 } 00072 00073 /** 00074 * Return modification date and time 00075 * 00076 * @return timestamp 00077 */ 00078 public function get_modification_date() { 00079 return $this->modificationdate; 00080 } 00081 }