コード例 #1
0
 /**
  * @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);
 }