/** * @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 \Symfony\Component\HttpFoundation\RedirectResponse */ public function eventDeleteAction(Request $request, $slug) { $this->denyAccessUnlessGranted('ROLE_USER', null, 'Unable to access this page!'); $v = $request->query->get('v'); $u = $request->query->get('u'); $usr = $this->get('security.token_storage')->getToken()->getUser(); $where = Where::create('slug = $*', [$slug]); $events = $this->get('pmanager')->findWhere('public', 'calendarobject', $where); if ($events->count() == 0) { if ($v == "calendar_read") { return $this->redirectToRoute('calendar_read', ['slug' => $u]); } return $this->redirectToRoute('event_home'); } $event = $events->get(0); $calendar = $this->get('pmanager')->findById('public', 'calendar', $event->calendarid); if ($calendar->principaluri != 'principals/' . $usr->getUsernameCanonical()) { $this->addFlash('danger', 'Cet événement ne fait pas parti de vos calendriers.'); if ($v == "calendar_read") { return $this->redirectToRoute('calendar_read', ['slug' => $u]); } return $this->redirectToRoute('event_read', ['uri' => $slug]); } $calendarBackend = new Calendar($this->get('pmanager')); $calendarBackend->deleteCalendarObject($event->calendarid, $event->uri); $this->addFlash('success', 'L\'événement a bien été supprimé.'); if ($v == "calendar_read") { return $this->redirectToRoute('calendar_read', ['slug' => $u]); } return $this->redirectToRoute('event_home'); }