public function save(AnnouncementPrice $announcementPrice) { if ($announcementPrice->isValid()) { $announcementPrice->isNew() ? $this->add($announcementPrice) : $this->modify($announcementPrice); } else { throw new RuntimeException('Les prix pour l\'annonce doivent être valide pour être enregistrée'); } }
protected function modify(AnnouncementPrice $announcementPrice) { $q = $this->dao->prepare('UPDATE ' . $this->table() . ' SET HALF_DAY = :halfDay, DAY = :day, WEEK_END = :weekEnd, WEEK = :week, FORTNIGHT = :fortnight, IS_ACTIVE = :isActive, ANNOUNCEMENT_ID = :announcementId, CONTACT_GROUP_ID = :contactGroupId WHERE ID = :id'); $q->bindValue(':halfDay', $announcementPrice->getHalfDay()); $q->bindValue(':day', $announcementPrice->getDay()); $q->bindValue(':weekEnd', $announcementPrice->getWeekEnd()); $q->bindValue(':week', $announcementPrice->getWeek()); $q->bindValue(':fortnight', $announcementPrice->getFortnight()); $q->bindValue(':isActive', $announcementPrice->getIsActive()); $q->bindValue(':announcementId', $announcementPrice->getAnnouncementId(), PDO::PARAM_INT); $q->bindValue(':contactGroupId', $announcementPrice->getContactGroupId(), PDO::PARAM_INT); $q->bindValue(':id', $announcementPrice->id(), PDO::PARAM_INT); $q->execute(); }
private function initAnnouncementPriceArray() { $announcementPriceArray = array(); foreach ($this->_listOfGroupsEndField as $group => $field) { $price = new AnnouncementPrice(); $price->setContactGroupId($group); $announcementPriceArray[] = $price; } return $announcementPriceArray; }