コード例 #1
0
ファイル: table.php プロジェクト: NavaINT1876/ccustoms
 /**
  * Save a record in table using the given data
  *
  * This method should always receive an object, which is usually the object representing
  * the table record populated with the changed data. If it's a new item (id=0) the system
  * will do an insert, otherwise it will perform an update
  *
  * @param object $object The object containing the data to be stored
  *
  * @since 1.0.0
  */
 public function save($object)
 {
     // init vars
     $vars = get_object_vars($object);
     $fields = $this->getTableColumns();
     foreach ($fields as $key => $value) {
         $fields[$key] = array_key_exists($key, $vars) ? (string) $vars[$key] : null;
     }
     // insert or update database
     $obj = (object) $fields;
     $key = $this->key;
     if ($obj->{$key}) {
         // update object
         $this->database->updateObject($this->name, $obj, $key);
     } else {
         // insert object
         $this->database->insertObject($this->name, $obj, $key);
         // set insert id
         $object->{$key} = $obj->{$key};
     }
 }