gyro/core/lib/interfaces/idataobject.cls.php
Go to the documentation of this file.00001 <?php 00002 require_once dirname(__FILE__) . '/isearchadapter.cls.php'; 00003 require_once dirname(__FILE__) . '/idbtable.cls.php'; 00004 require_once dirname(__FILE__) . '/idbwhereholder.cls.php'; 00005 00006 /** 00007 * Base interface for data objects 00008 * 00009 * @author Gerd Riesselmann 00010 * @ingroup Interfaces 00011 */ 00012 interface IDataObject extends ISearchAdapter, IDBTable, IDBWhereHolder { 00013 const NORMAL = 0; 00014 const WHERE_ONLY = 1; 00015 const AUTOFETCH = 1; 00016 00017 /** 00018 * Sets all default values on instance. Previous values are overwritten! 00019 */ 00020 public function set_default_values(); 00021 00022 /** 00023 * Either update or insert object 00024 * 00025 * This function handles autoupdating IDs 00026 * 00027 * @return Status 00028 */ 00029 public function save(); 00030 00031 /** 00032 * Insert data. Autoincrement IDs will be automatically set. 00033 * 00034 * @return Status 00035 */ 00036 public function insert(); 00037 00038 /** 00039 * Inserts if data does not exist, updates else 00040 * 00041 * This function queries the database, that is it does not use MySQL "replace into" 00042 * It does not handle autoupdated ids. That is: It only works if all keys are set 00043 * 00044 * @return Status 00045 */ 00046 public function replace(); 00047 00048 /** 00049 * Update current item 00050 * 00051 * @param int $policy IDataObject::WHERE_ONLY is used, no conditions are build automatically 00052 * @return Status 00053 */ 00054 public function update($policy = self::NORMAL); 00055 00056 /** 00057 * Delete this object 00058 * 00059 * @param int $policy If IDataObject::WHERE_ONLY is used, no conditions are build automatically 00060 * @return Status 00061 * 00062 */ 00063 public function delete($policy = self::NORMAL); 00064 00065 /** 00066 * read properties of object form array 00067 * 00068 * @param array $values Associative array with property name as key and property value as value 00069 */ 00070 public function read_from_array($values); 00071 00072 /** 00073 * Validate this object 00074 * 00075 * @return Status Error 00076 */ 00077 public function validate(); 00078 00079 /** 00080 * Returns first result of a select for $value on $column_or_value. 00081 * 00082 * If $value is empty, this function assumes $column_or_value contains the value of first key column 00083 * 00084 * @param mixed $column_or_value 00085 * @param mixed $value 00086 */ 00087 public function get($column_or_value, $value = null); 00088 00089 /** 00090 * Find results, either normal or crosstable 00091 * 00092 * for example 00093 * 00094 * $object = new mytable(); 00095 * $object->ID = 1; 00096 * $object->find(); 00097 * 00098 * @param int $policy If set to IDataObject::AUTOFETCH, first record is fetched automatically 00099 * @return int Number of rows found 00100 */ 00101 public function find($policy = self::NORMAL); 00102 00103 /** 00104 * Return array of elements, based on current configuration 00105 * 00106 * @return array Array of IDataObject 00107 */ 00108 public function find_array(); 00109 00110 /** 00111 * fetches next row into this objects var's 00112 * 00113 * returns true on success false on failure 00114 * 00115 * Example 00116 * $object = new mytable(); 00117 * $object->name = "fred"; 00118 * $object->find(); 00119 * $store = array(); 00120 * while ($object->fetch()) { 00121 * echo $this->ID; 00122 * $store[] = $object; // builds an array of object lines. 00123 * } 00124 * 00125 * @return boolean True on success 00126 */ 00127 public function fetch(); 00128 00129 /** 00130 * Fetch and return an array 00131 * 00132 * @return array Array of IDataObject 00133 */ 00134 public function fetch_array(); 00135 00136 /** 00137 * Quote and escape a string 00138 * 00139 * @param string $val 00140 * @return string 00141 */ 00142 public function quote($val); 00143 00144 /** 00145 * Returns true if a both this and the given object refer to the same instance in the DB 00146 * 00147 * The codes tests if table and key fields are identical. Note that this function 00148 * returns true even if some properties are not identical. Use equals() to test this 00149 * 00150 * @param IDataObject $other 00151 * @return bool 00152 */ 00153 public function is_same_as($other); 00154 00155 /** 00156 * Returns true if a both this and the given object are identical 00157 * 00158 * The codes tests if table and all fields are identical. Note that this function 00159 * may return false in cases when is_same_as() returns true. 00160 * 00161 * @param IDataObject $other 00162 * @return bool 00163 */ 00164 public function equals($other); 00165 }