/** * @param string $uriEvent * * @return Response * @throws \Exception * * @ApiDoc( * description="Delete the event with the given uri", * requirements={ * { * "name"="uriEvent", * "dataType"="string", * "description"="The uri of the event", * } * }, * ) */ public function deleteEventAction($uriEvent) { $event = $this->get('pmanager')->findById('public', 'calendarobject', $uriEvent); if ($event == null) { return $this->buildError('404', 'The event with the given uri could not be found.'); } $calendarBackend = new CalendarBackend($this->get('pmanager')); $calendarBackend->deleteCalendarObject($event->calendarid, $event->uri); return $this->buildResponse(['event' => 'deleted']); }
/** * @param string $slug * * @return RedirectResponse */ public function calendarDeleteAction($slug) { $this->denyAccessUnlessGranted('ROLE_USER', null, 'Unable to access this page!'); $usr = $this->get('security.token_storage')->getToken()->getUser(); $where = Where::create('slug = $*', [$slug]); $calendars = $this->get('pmanager')->findWhere('public', 'calendar', $where); if ($calendars->count() == 0) { return $this->redirectToRoute('calendar_home'); } $calendar = $calendars->get(0); if ($calendar->principaluri != 'principals/' . $usr->getUsernameCanonical()) { $this->addFlash('danger', 'Ce calendrier ne vous appartient pas.'); return $this->redirectToRoute('calendar_read', ['slug' => $slug]); } $calendarBackend = new Calendar($this->get('pmanager')); $calendarBackend->deleteCalendar($calendar->uid); $this->addFlash('success', 'Le calendrier "' . $calendar->displayName . '" a bien été supprimé.'); return $this->redirectToRoute('calendar_home'); }