/**
  * @EXT\Route(
  *     "/api/session/event/{sessionEvent}/edit",
  *     name="api_put_session_event_edition",
  *     options = {"expose"=true}
  * )
  * @EXT\ParamConverter("user", converter="current_user")
  *
  * Edits a session event
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function putSessionEventEditionAction(SessionEvent $sessionEvent)
 {
     $sessionEventDatas = $this->request->request->get('sessionEventDatas', false);
     $trimmedStartDate = trim($sessionEventDatas['startDate'], 'Zz');
     $trimmedEndDate = trim($sessionEventDatas['endDate'], 'Zz');
     $startDate = new \DateTime($trimmedStartDate);
     $endDate = new \DateTime($trimmedEndDate);
     $sessionEvent->setName($sessionEventDatas['name']);
     $sessionEvent->setStartDate($startDate);
     $sessionEvent->setEndDate($endDate);
     $sessionEvent->setDescription($sessionEventDatas['description']);
     $sessionEvent->setLocationExtra($sessionEventDatas['locationExtra']);
     $sessionEvent->setRegistrationType($sessionEventDatas['registrationType']);
     $sessionEvent->setMaxUsers($sessionEventDatas['maxUsers']);
     $sessionEvent->setLocationResource(null);
     $sessionEvent->setLocation(null);
     if ($sessionEventDatas['location']) {
         $location = $this->locationManager->getLocationById($sessionEventDatas['location']);
         if (!is_null($location)) {
             $sessionEvent->setLocation($location);
         }
     }
     if ($sessionEventDatas['locationResource']) {
         $locationResource = $this->cursusManager->getReservationResourceById($sessionEventDatas['locationResource']);
         if (!is_null($locationResource)) {
             $sessionEvent->setLocationResource($locationResource);
         }
     }
     $sessionEvent->emptyTutors();
     $tutorsIds = $sessionEventDatas['tutors'] ? $sessionEventDatas['tutors'] : [];
     $tutors = $this->userManager->getUsersByIds($tutorsIds);
     foreach ($tutors as $tutor) {
         $sessionEvent->addTutor($tutor);
     }
     $this->cursusManager->persistSessionEvent($sessionEvent);
     $event = new LogSessionEventEditEvent($sessionEvent);
     $this->eventDispatcher->dispatch('log', $event);
     $this->cursusManager->checkPendingSessionEventUsers($sessionEvent);
     if ($sessionEvent->getRegistrationType() === CourseSession::REGISTRATION_AUTO) {
         $this->cursusManager->registerSessionUsersToSessionEvent($sessionEvent);
     }
     $serializedSessionEvent = $this->serializer->serialize($sessionEvent, 'json', SerializationContext::create()->setGroups(['api_user_min']));
     return new JsonResponse($serializedSessionEvent, 200);
 }
Exemplo n.º 2
0
 public function createSessionEvent(CourseSession $session, $name = null, $description = null, $startDate = null, $endDate = null, $location = null, $locationExtra = null, Resource $reservationResource = null, array $tutors = [], $registrationType = CourseSession::REGISTRATION_AUTO, $maxUsers = null)
 {
     $eventName = is_null($name) ? $session->getName() : $name;
     $eventStartDate = is_null($startDate) ? $session->getStartDate() : $startDate;
     $eventEndDate = is_null($endDate) ? $session->getEndDate() : $endDate;
     $sessionEvent = new SessionEvent();
     $sessionEvent->setSession($session);
     $sessionEvent->setName($eventName);
     $sessionEvent->setDescription($description);
     $sessionEvent->setStartDate($eventStartDate);
     $sessionEvent->setEndDate($eventEndDate);
     $sessionEvent->setLocation($location);
     $sessionEvent->setLocationExtra($locationExtra);
     $sessionEvent->setLocationResource($reservationResource);
     $sessionEvent->setRegistrationType($registrationType);
     $sessionEvent->setMaxUsers($maxUsers);
     foreach ($tutors as $tutor) {
         $sessionEvent->addTutor($tutor);
     }
     $this->persistSessionEvent($sessionEvent);
     $event = new LogSessionEventCreateEvent($sessionEvent);
     $this->eventDispatcher->dispatch('log', $event);
     if ($sessionEvent->getRegistrationType() === CourseSession::REGISTRATION_AUTO) {
         $this->registerSessionUsersToSessionEvent($sessionEvent);
     }
     return $sessionEvent;
 }