예제 #1
0
 /**
  * @param Request $request
  * @param string $uriEvent
  * @return Response
  * @throws \Exception
  *
  * @ApiDoc(
  *  description="Update the event with the given uri",
  *  requirements={
  *      {
  *          "name"="uriEvent",
  *          "dataType"="string",
  *          "description"="The uri of the event",
  *      }
  *  },
  *  parameters={
  *      {
  *          "name"="some_property",
  *          "dataType"="string",
  *          "required"=false,
  *          "description"="Some property to update"
  *      }
  *  }
  * )
  */
 public function updateEventAction(Request $request, $uriEvent)
 {
     $rawEvent = $this->get('pmanager')->findById('public', 'calendarobject', $uriEvent);
     if ($rawEvent == null) {
         return $this->buildError('404', 'The event with the given uri could not be found.');
     }
     $params = array();
     $content = $request->getContent();
     if (!empty($content)) {
         $params = json_decode($content, true);
     }
     $event = new Event();
     $event->loadFromCalData($rawEvent->calendarData);
     foreach ($params as $name => $value) {
         $event->__set($name, $value);
     }
     $calendarBackend = new CalendarBackend($this->get('pmanager'), $this->generateUrl('event_read', [], true), $this->get('slugify'));
     $calendarBackend->updateCalendarObject($rawEvent->calendarid, $rawEvent->uri, $event->getVObject()->serialize());
     return $this->buildResponse(['event' => 'updated']);
 }
예제 #2
0
 /**
  * @param Request $request
  * @param string  $slug
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
  */
 public function eventUpdateAction(Request $request, $slug)
 {
     $this->denyAccessUnlessGranted('ROLE_USER', null, 'Unable to access this page!');
     $usr = $this->get('security.token_storage')->getToken()->getUser();
     $username = $usr->getUsernameCanonical();
     $where = Where::create('slug = $*', [$slug]);
     $rawEvents = $this->get('pmanager')->findWhere('public', 'calendarobject', $where);
     if ($rawEvents->count() == 0) {
         return $this->redirectToRoute('event_home');
     }
     $rawEvent = $rawEvents->get(0);
     $event = new Event();
     $event->loadFromCalData($rawEvent->calendarData);
     $form = $this->createForm(new EventType(), $event, ['csrf_protection' => false]);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $vevent = $event->getVObject();
         $calendarBackend = new Calendar($this->get('pmanager'), $this->generateUrl('event_read', [], true), $this->get('slugify'));
         $calendarBackend->updateCalendarObject($rawEvent->calendarid, $rawEvent->uri, $vevent->serialize());
         $this->addFlash('success', "L'événement a bien été modifié.");
         $rawEvent = $this->get('pmanager')->findById('public', 'calendarobject', $event->id);
         return $this->redirectToRoute('event_read', ['slug' => $rawEvent->slug]);
     }
     return $this->render('browser/event_update.html.twig', array('form' => $form->createView(), 'slug' => $slug));
 }