/** * Saves an event into the database. * * @param \MicroCMS\Domain\Event $event The event to save */ public function save(Event $event) { $eventData = array('name_event' => $event->getName(), 'desc_event' => $event->getDesc(), 'minimalPrice_event' => $event->getMinimalPrice(), 'startDate_event' => $event->getStartDate(), 'endDate_event' => $event->getEndDate(), 'startHour_event' => $event->getStartHour(), 'endHour_event' => $event->getEndHour(), 'num_ET' => $event->getType(), 'coverImage_event' => $event->getCoverImageLink()); if ($event->getNum()) { // The event has already been saved : update it $this->getDb()->update('event', $eventData, array('num_event' => $event->getNum())); } else { // The event has never been saved : insert it $this->getDb()->insert('event', $eventData); // Get the id of the newly created event and set it on the entity. $id = $this->getDb()->lastInsertId(); $event->setNum($id); } }
/** * Converts an Event object into an associative array for JSON encoding * * @param Event $event Event object * * @return array Associative array whose fields are the event properties. */ private function buildEventArray(Event $event) { $data = array('num' => $event->getNum(), 'name' => $event->getName(), 'desc' => $event->getDesc()); return $data; }