• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List

E:/E/GEAMP/www/openbiz/openbiz/bin/data/DataRecord.php

00001 <?php
00026 class DataRecord implements Iterator, ArrayAccess
00027 {
00033     protected $m_var = array();
00034 
00040     protected $m_var_old = array();
00041 
00047     protected $m_BizObj = null;
00048 
00058     public function __construct($recArray, $bizObj)
00059     {
00060         if ($recArray != null)
00061         {
00062             if (is_array($recArray)) {
00063                 $this->m_var = $recArray;
00064                 $this->m_var_old = $recArray;
00065             }
00066             else if (is_a($recArray,"DataRecord")) {
00067                 $this->m_var = $recArray->toArray();
00068                 $this->m_var_old = $this->m_var;
00069             }
00070         }
00071         else
00072             $this->m_var = $bizObj->newRecord();
00073 
00074         $this->m_BizObj = $bizObj;
00075     }
00076 
00077     // Iterator methods BEGIN---------
00078 
00085     public function get($key)
00086     {
00087         return isset($this->m_var[$key]) ? $this->m_var[$key] : null;
00088     }
00089     
00090     public function getOldValue($key)
00091     {
00092        return isset($this->m_var_old[$key]) ? $this->m_var_old[$key] : null;
00093     }
00094 
00095        public function getDataObj()
00096     {
00097        return $this->m_BizObj;
00098     }
00105     public function set($key, $val)
00106     {
00107         $this->m_var[$key] = $val;
00108 
00109     }
00110 
00116     public function rewind()
00117     { 
00118         reset($this->m_var);
00119     }
00120 
00126     public function current()
00127     { 
00128         return current($this->m_var);
00129     }
00130 
00131 
00137     public function key()
00138     { 
00139         return key($this->m_var);
00140     }
00141 
00147     public function next()
00148     { 
00149         return next($this->m_var);
00150     }
00151 
00157     public function valid()
00158     { 
00159         return $this->current() !== false;
00160     }
00161     
00162     // ArrayAccess methods
00163     
00170     public function offsetExists($key)
00171     { 
00172         return isset($this->m_var[$key]);
00173     }
00174 
00181     public function offsetGet($key)
00182     { 
00183         return $this->get($key);
00184     }
00185 
00192     public function offsetSet($key, $value)
00193     { 
00194         $this->set($key, $value);
00195     }
00196 
00202     public function offsetUnset($key)
00203     { 
00204         unset($this->m_var[$key]);
00205     }
00206 
00216     public function __get($fieldName)
00217     {
00218         return $this->get($fieldName);
00219     }
00220 
00231     public function __set($fieldName, $value)
00232     {
00233         $this->set($fieldName, $value);
00234     }
00235 
00241     public function save()
00242     {
00243         if (count($this->m_var_old) > 0)
00244             $ok = $this->m_BizObj->updateRecord($this->m_var, $this->m_var_old);
00245         else
00246             $ok = $this->m_BizObj->insertRecord($this->m_var);
00247 
00248         // repopulate current record with bizdataobj activerecord
00249         if ($ok)
00250         {
00251             $this->m_var = $this->m_BizObj->getActiveRecord();
00252             $this->m_var_old = $this->m_var;
00253         }
00254 
00255         return $ok;
00256     }
00257 
00263     public function delete()
00264     {
00265         return $this->m_BizObj->deleteRecord($this->m_var);
00266     }
00267 
00273     public function getError()
00274     {
00275         return $this->m_BizObj->getErrorMessage();
00276     }
00277 
00283     public function toArray()
00284     {
00285         return $this->m_var;
00286     }
00287 
00294     public function getRefObject($objName)
00295     {
00296         return $this->m_BizObj->getRefObject($objName);
00297     }
00298 
00299 }
00300 ?>

Generated on Thu Apr 19 2012 17:09:13 for openbiz by  doxygen 1.7.2