コード例 #1
0
 /**
  * Update the given entity in the database.
  *
  * @param  AbstractEntity $entity
  * @return AbstractEntity
  */
 public function update(AbstractEntity $entity)
 {
     if ($this->updatedTimestampColumn) {
         $entity->exchangeArray([$this->updatedTimestampColumn => time()]);
     }
     if ($this->updatedDatetimeColumn) {
         $entity->exchangeArray([$this->updatedDatetimeColumn => date('Y-m-d H:i:s')]);
     }
     $this->updateRow($entity);
     return $entity;
 }
コード例 #2
0
ファイル: EmailEntity.php プロジェクト: bodetree/synapse-base
 /**
  * {@inheritDoc}
  */
 public function exchangeArray(array $values)
 {
     $entity = parent::exchangeArray($values);
     $entity->setCreated(time());
     $entity->setStatus(self::STATUS_PENDING);
     return $entity;
 }
コード例 #3
0
 /**
  * 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()]);
     }
 }