/** * Updates an calendar event * * @param int $id * @param array $data * * @return bool */ public function updateCalendarEvent($id, array $data) { $eventData = $this->calendarEventsEngine->buildEventData($data); $eventDates = $this->calendarEventsEngine->buildEventDates($data); $cache = $this->cache; $calendarEventRepeatDate = clone $this->calendarEventRepeatDate; $calendarEventRepeatDate->where('calendar_event_id', $id)->delete(); $this->calendarEvent->where('id', $id)->update($eventData); $calendarEvent = $this->calendarEvent->where('id', $id)->firstOrFail(); foreach ($eventDates as $date) { $calendarEventRepeatDate = clone $this->calendarEventRepeatDate; $calendarEventRepeatDate->start = $date['start']; $calendarEventRepeatDate->end = $date['end']; $calendarEventRepeatDate->calendarEvent()->associate($calendarEvent); $calendarEventRepeatDate->save(); unset($calendarEventRepeatDate); } $cache::put(self::CACHE_KEY . $calendarEvent->id, $calendarEvent, $this->cacheTimeToLive); $allEvents = $this->getAllEvents(); $allEvents->put($calendarEvent->id, $calendarEvent); $cache::put(self::ALL_EVENTS_KEY, $allEvents, $this->cacheTimeToLive); return true; }
/** * Tests buildEventData with wrong data */ public function testBuildEventDataException() { $data = ['title' => 'Title', 'description' => 'Description', 'start' => ['date' => '2015-10-02', 'time' => '10:00:00'], 'end' => ['date' => '2015-10-01', 'time' => '11:00:00'], 'text_color' => '#000000', 'border_color' => '#666666', 'background_color' => '#ffffff']; static::setExpectedException('Todstoychev\\CalendarEvents\\Exceptions\\DateDifferenceException', 'Start date bigger then end date!'); $this->calendarEventsEngine->buildEventData($data); }