/** * Update an entity's DB row by its ID. * Set the updated timestamp column if it exists. * * @param AbstractEntity $entity */ protected function patchRow(AbstractEntity $entity) { $values = $entity->getChangedDbValues(); if (empty($values)) { return; } $query = $this->getSqlObject()->update()->set($values)->where($this->getPrimaryKeyWheres($entity)); $this->execute($query); }
/** * Insert an entity's DB row using the given values. * Set the ID on the entity from the query result. * * @param AbstractEntity $entity */ protected function insertRow(AbstractEntity $entity) { $values = $entity->getDbValues(); $columns = array_keys($values); if ($this->autoIncrementColumn && !array_key_exists($this->autoIncrementColumn, $values)) { throw new LogicException('auto_increment column ' . $this->autoIncrementColumn . ' not found'); } $query = $this->getSqlObject()->insert()->columns($columns)->values($values); $statement = $this->getSqlObject()->prepareStatementForSqlObject($query); $result = $statement->execute(); if ($this->autoIncrementColumn && !$values[$this->autoIncrementColumn]) { $entity->exchangeArray([$this->autoIncrementColumn => $result->getGeneratedValue()]); } }
/** * {@inheritDoc} */ public function exchangeArray(array $values) { $entity = parent::exchangeArray($values); $entity->setCreated(time()); $entity->setStatus(self::STATUS_PENDING); return $entity; }
/** * Update an entity's DB row by its ID. * Set the updated timestamp column if it exists. * * @param AbstractEntity $entity * @param array $values Values to set on the entity */ protected function updateRow(AbstractEntity $entity) { $values = $entity->getDbValues(); $query = $this->getSqlObject()->update()->set($values)->where($this->getPrimaryKeyWheres($entity)); $this->execute($query); }
/** * Get a wheres array for finding the row that matches an entity * * @return array */ protected function getPrimaryKeyWheres(AbstractEntity $entity) { $wheres = []; $arrayCopy = $entity->getArrayCopy(); foreach ($this->primaryKey as $keyColumn) { $wheres[$keyColumn] = $arrayCopy[$keyColumn]; } return $wheres; }
public function __construct(array $data = []) { $data['record_type'] = $this->recordType; parent::__construct($data); }