public function save(AnnouncementUnavailability $announcementUnavailability) { if ($announcementUnavailability->isValid()) { $announcementUnavailability->isNew() ? $this->add($announcementUnavailability) : $this->modify($announcementUnavailability); } else { throw new RuntimeException('Les indisponibilités pour l\'annonce doivent être valide pour être enregistrée'); } }
protected function modify(AnnouncementUnavailability $announcementUnavailability) { $q = $this->dao->prepare('UPDATE ' . $this->table() . ' SET DATE = :date, DATE_OPTION = :option, ANNOUNCEMENT_ID = :announcementId WHERE ID = :id'); $q->bindValue(':date', $announcementUnavailability->getDate()); $q->bindValue(':option', $announcementUnavailability->getOption()); $q->bindValue(':announcementId', $announcementUnavailability->getAnnouncementId(), PDO::PARAM_INT); $q->bindValue(':id', $announcementUnavailability->id(), PDO::PARAM_INT); $q->execute(); }
private function parseIndisponibilities(HTTPRequest $request, Announcement $announce) { if ($request->postData('date-list') != '') { $unavailabilities = array(); $dates = $request->postData('date-list'); $dates = explode(',', $dates); foreach ($dates as $date) { $unavailability = new AnnouncementUnavailability(); $unavailability->setDate($date); $unavailability->setDateOption($request->postData($date)); $unavailability->setAnnouncementId($announce->id()); $unavailabilities[] = $unavailability; } return $unavailabilities; } return null; }