Beispiel #1
0
 /**
  * this method performs both insert and update
  * this only runs a query if data has changed
  * this updates dbData through the orig refrence
  * saving behavior is determined by the contents of the orig array
  *	if empty orig insert else update
  * after a save all objects that refrence this orig data will be refcrenced to the new data
  *
  * @return bool or int affected rows
  */
 public function save()
 {
     $res = true;
     $changedData = $this->changedData();
     if (count($changedData)) {
         if (!empty($this->orig)) {
             $res = dbHelper::updateQry($this->tableName, $changedData, array($this->primaryKey => $this->data[$this->primaryKey])) ? true : false;
             $this->orig = $this->data;
         } else {
             //if this row has been deleted but someone else saves data to it this will automatically restore the row from $data
             $res = dbHelper::insertQry($this->tableName, $this->data) ? true : false;
             $this->data[$this->primaryKey] = db::insertID();
             dbData::addRow($this->tableName, $this->primaryKey, $this->data);
             $this->orig =& dbData::rowRefrence($this->tableName, $this->primaryKey, $this->data[$this->primaryKey]);
         }
     }
     return $res;
 }