/** * Saves a Comic into the database. * * @param \Comics\Domain\Comic $comic The Comic to save */ public function save(Comic $comic) { $comicData = array('cmc_serie' => $comic->getSerie(), 'cmc_author_id' => $comic->getAuthorId(), 'cmc_title' => $comic->getTitle(), 'cmc_tome' => $comic->getTome(), 'cmc_release_date' => $comic->getDate(), 'cmc_price' => $comic->getPrice()); // Reverse date format $comicData['cmc_release_date'] = DateHelper::toAmericanFormat($comicData['cmc_release_date']); if ($comic->getId()) { // The Comic has already been saved : update it $this->getDb()->update('c_comics', $comicData, array('cmc_id' => $comic->getId())); } else { // The Comic has never been saved : insert it $this->getDb()->insert('c_comics', $comicData); // Get the id of the newly created comic and set it on the entity. $id = $this->getDb()->lastInsertId(); $comic->setId($id); } }
public function validate($value, Constraint $constraint) { if (!Date\DateHelper::checkDate($value)) { $this->context->buildViolation($constraint->message)->setParameter('%string%', $value)->addViolation(); } }