/**
  * @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);
 }
Ejemplo n.º 2
0
 public function repeatSessionEvent(SessionEvent $sessionEvent, $iteration, \DateTime $until = null, $duration = null)
 {
     $createdSessionEvents = [];
     $dateInterval = new \DateInterval('P1D');
     $session = $sessionEvent->getSession();
     $description = $sessionEvent->getDescription();
     $location = $sessionEvent->getLocation();
     $locationResource = $sessionEvent->getLocationResource();
     $name = $sessionEvent->getName();
     $eventStartDate = $sessionEvent->getStartDate();
     $endDate = $sessionEvent->getEndDate();
     $tutors = $sessionEvent->getTutors();
     $index = 1;
     $year = intval($eventStartDate->format('Y'));
     $month = intval($eventStartDate->format('m'));
     $day = intval($eventStartDate->format('d'));
     $hour = intval($eventStartDate->format('H'));
     $minute = intval($eventStartDate->format('i'));
     $startDate = new \DateTime();
     $startDate->setTimezone(new \DateTimeZone('GMT'));
     $startDate->setDate($year, $month, $day);
     $startDate->setTime($hour, $minute);
     if (is_null($until) && !is_null($duration) && $duration > 0) {
         $until = clone $startDate;
         $daysToAdd = 7 * $duration;
         $until->add(new \DateInterval('P' . $daysToAdd . 'D'));
     }
     if (!is_null($until)) {
         $untilYear = intval($until->format('Y'));
         $untilMonth = intval($until->format('m'));
         $untilDay = intval($until->format('d'));
         $formattedUntil = new \DateTime();
         $formattedUntil->setTimezone(new \DateTimeZone('GMT'));
         $formattedUntil->setDate($untilYear, $untilMonth, $untilDay);
         $formattedUntil->setTime(23, 59, 59);
         $this->om->startFlushSuite();
         for ($startDate->add($dateInterval); $startDate < $formattedUntil; $startDate->add($dateInterval)) {
             $eventStartDate->add($dateInterval);
             $endDate->add($dateInterval);
             $day = $startDate->format('l');
             if ($iteration[$day]) {
                 $newStartDate = clone $eventStartDate;
                 $newEndDate = clone $endDate;
                 $newSessionEvent = new SessionEvent();
                 $newSessionEvent->setSession($session);
                 $newSessionEvent->setDescription($description);
                 $newSessionEvent->setLocation($location);
                 $newSessionEvent->setLocationResource($locationResource);
                 $newSessionEvent->setStartDate($newStartDate);
                 $newSessionEvent->setEndDate($newEndDate);
                 $newSessionEvent->setName($name . " [{$index}]");
                 foreach ($tutors as $tutor) {
                     $newSessionEvent->addTutor($tutor);
                 }
                 ++$index;
                 $this->persistSessionEvent($newSessionEvent);
                 $createdSessionEvents[] = $newSessionEvent;
                 if ($index % 300 === 0) {
                     $this->om->forceFlush();
                 }
             }
         }
         $this->om->endFlushSuite();
     }
     return $createdSessionEvents;
 }