/**
  * @EXT\Route(
  *     "/api/session/{session}/edit",
  *     name="api_put_session_edition",
  *     options = {"expose"=true}
  * )
  * @EXT\ParamConverter("user", converter="current_user")
  *
  * Edits a session
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function putSessionEditionAction(CourseSession $session)
 {
     $sessionDatas = $this->request->request->get('sessionDatas', false);
     $trimmedStartDate = trim($sessionDatas['startDate'], 'Zz');
     $trimmedEndDate = trim($sessionDatas['endDate'], 'Zz');
     $startDate = new \DateTime($trimmedStartDate);
     $endDate = new \DateTime($trimmedEndDate);
     $session->setName($sessionDatas['name']);
     $session->setStartDate($startDate);
     $session->setEndDate($endDate);
     $session->setDescription($sessionDatas['description']);
     $session->setDefaultSession((bool) $sessionDatas['defaultSession']);
     $session->setPublicRegistration((bool) $sessionDatas['publicRegistration']);
     $session->setPublicUnregistration((bool) $sessionDatas['publicUnregistration']);
     $session->setUserValidation((bool) $sessionDatas['userValidation']);
     $session->setMaxUsers($sessionDatas['maxUsers']);
     $session->setOrganizationValidation((bool) $sessionDatas['organizationValidation']);
     $session->setRegistrationValidation((bool) $sessionDatas['registrationValidation']);
     $session->setEventRegistrationType($sessionDatas['eventRegistrationType']);
     $session->setDisplayOrder($sessionDatas['displayOrder']);
     $details = $session->getDetails();
     if (is_null($details)) {
         $details = [];
     }
     $details['color'] = $sessionDatas['color'];
     $session->setDetails($details);
     $cursusIds = $sessionDatas['cursus'] ? $sessionDatas['cursus'] : [];
     $validatorsIds = $sessionDatas['validators'] ? $sessionDatas['validators'] : [];
     $cursus = $this->cursusManager->getCursusByIds($cursusIds);
     $validators = $this->userManager->getUsersByIds($validatorsIds);
     $session->emptyCursus();
     $session->emptyValidators();
     foreach ($cursus as $c) {
         $session->addCursus($c);
     }
     foreach ($validators as $validator) {
         $session->addValidator($validator);
     }
     $this->cursusManager->persistCourseSession($session);
     $event = new LogCourseSessionEditEvent($session);
     $this->eventDispatcher->dispatch('log', $event);
     $serializedSession = $this->serializer->serialize($session, 'json', SerializationContext::create()->setGroups(['api_user_min']));
     return new JsonResponse($serializedSession, 200);
 }
示例#2
0
 public function createCourseSession(Course $course, $name = null, $description = null, array $cursus = [], $creationDate = null, $startDate = null, $endDate = null, $defaultSession = false, $publicRegistration = false, $publicUnregistration = false, $registrationValidation = false, $userValidation = false, $organizationValidation = false, $maxUsers = null, $type = 0, array $validators = [], $eventRegistrationType = CourseSession::REGISTRATION_AUTO, $displayOrder = 500, $color = null)
 {
     if (is_null($creationDate)) {
         $creationDate = new \DateTime();
     }
     $session = new CourseSession();
     if ($name) {
         $session->setName($name);
     }
     foreach ($cursus as $c) {
         $session->addCursus($c);
     }
     $session->setDescription($description);
     $session->setCreationDate($creationDate);
     $session->setDefaultSession((bool) $defaultSession);
     $session->setPublicRegistration((bool) $publicRegistration);
     $session->setPublicUnregistration((bool) $publicUnregistration);
     $session->setRegistrationValidation((bool) $registrationValidation);
     $session->setUserValidation((bool) $userValidation);
     $session->setOrganizationValidation((bool) $organizationValidation);
     $session->setMaxUsers($maxUsers);
     $session->setType($type);
     $session->setEventRegistrationType($eventRegistrationType);
     $session->setDisplayOrder($displayOrder);
     $details = [];
     $details['color'] = $color;
     $total = $this->platformConfigHandler->hasParameter('cursus_session_default_total') ? $this->platformConfigHandler->getParameter('cursus_session_default_total') : null;
     $details['total'] = $total;
     $session->setDetails($details);
     if ($defaultSession) {
         $this->resetDefaultSessionByCourse($course);
     }
     if (is_null($startDate)) {
         $startDate = $creationDate;
     }
     $session->setStartDate($startDate);
     if (is_null($endDate)) {
         $endDate = clone $startDate;
         $endDate->add(new \DateInterval('P' . $course->getDefaultSessionDuration() . 'D'));
     }
     $session->setEndDate($endDate);
     foreach ($validators as $validator) {
         $session->addValidator($validator);
     }
     $this->createCourseSessionFromSession($session, $course);
     if ($course->getWithSessionEvent()) {
         $this->createSessionEvent($session);
     }
     return $session;
 }