/** * CarEntity constructor. * * @param string $make * @param string $model * @param int $horsePower * @param string $doors * @param \DateTime $released */ public function __construct(string $make, string $model, int $horsePower, string $doors, \DateTime $released) { parent::__construct(null, new \DateTime(), new \DateTime()); $this->set('make', $make); $this->set('model', $model); $this->set('horsepower', $horsePower); $this->set('doors', $doors); $this->set('released', $released); }
/** * Update entity in the database * * @param Entity $entity Entity object * * @return bool True if row was affected, otherwise false */ public function update(Entity $entity) : bool { if ($entity->isAltered()) { /** * Set modified to now */ $entity->set('modified', new \DateTime()); /** * Get altered columns for SQL command */ $alteredColumns = array_keys($entity->getAlteredColumns()); $stmt = $this->pdo->prepare($this->sqlCommand->updateSetWhere($alteredColumns)); /** * Execute with altered array */ $stmt->execute($entity->alteredToArray(true)); // @todo return true if row is altered } return false; }