Пример #1
0
 /**
  * Saves (updates or inserts) the row.
  * @param array $data
  * @return bool success?
  */
 public function save($data = null)
 {
     $hasPrimary = $this->getPrimary(false);
     if ($hasPrimary) {
         if (0 == $this->selection->createSelectionInstance()->wherePrimary($hasPrimary)->limit(1)->count('*')) {
             goto INSERT_ROW;
         }
         $res = $this->update($data);
     } else {
         INSERT_ROW:
         if ($data === null) {
             $data = $this->modified;
         }
         $res = $this->selection->insert($data);
         if ($res instanceof ActiveRow) {
             $this->data = $res->toArray();
         }
         $this->modified = array();
     }
     if ($res === false) {
         trigger_error('Data could not be saved: unknown reason', E_USER_WARNING);
     } else {
         $res = true;
     }
     return $res;
 }
Пример #2
0
 public function insert($data)
 {
     if ($data instanceof \Traversable && !$data instanceof Selection) {
         $data = iterator_to_array($data);
     }
     if (Arrays::isList($data)) {
         foreach (array_keys($data) as $key) {
             $data[$key][$this->column] = $this->active;
         }
     } else {
         $data[$this->column] = $this->active;
     }
     return parent::insert($data);
 }