/**
  * @EXT\Route(
  *     "/api/course/{course}/edit",
  *     name="api_put_course_edition",
  *     options = {"expose"=true}
  * )
  * @EXT\ParamConverter("user", converter="current_user")
  *
  * Edits a course
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function putCourseEditionAction(Course $course)
 {
     $courseDatas = $this->request->request->get('courseDatas', false);
     $course->setTitle($courseDatas['title']);
     $course->setCode($courseDatas['code']);
     $description = $courseDatas['description'] ? $courseDatas['description'] : null;
     $course->setDescription($description);
     $course->setPublicRegistration((bool) $courseDatas['publicRegistration']);
     $course->setPublicUnregistration((bool) $courseDatas['publicUnregistration']);
     $course->setRegistrationValidation((bool) $courseDatas['registrationValidation']);
     $tutorRoleName = $courseDatas['tutorRoleName'] ? $courseDatas['tutorRoleName'] : null;
     $course->setTutorRoleName($tutorRoleName);
     $learnerRoleName = $courseDatas['learnerRoleName'] ? $courseDatas['learnerRoleName'] : null;
     $course->setLearnerRoleName($learnerRoleName);
     if ($courseDatas['workspace']) {
         $worskpace = $this->workspaceManager->getWorkspaceById($courseDatas['workspace']);
         $course->setWorkspace($worskpace);
     } else {
         $course->setWorkspace(null);
     }
     if ($courseDatas['workspaceModel']) {
         $worskpaceModel = $this->workspaceModelManager->getModelById($courseDatas['workspaceModel']);
         $course->setWorkspaceModel($worskpaceModel);
     } else {
         $course->setWorkspaceModel(null);
     }
     if ($this->request->files->get('courseDatas')['icon']) {
         $icon = $this->cursusManager->saveIcon($this->request->files->get('courseDatas')['icon']);
         $course->setIcon($icon);
     }
     $course->setUserValidation((bool) $courseDatas['userValidation']);
     $course->setOrganizationValidation((bool) $courseDatas['organizationValidation']);
     $maxUsers = $courseDatas['maxUsers'] ? $courseDatas['maxUsers'] : null;
     $course->setMaxUsers($maxUsers);
     $course->setDefaultSessionDuration($courseDatas['defaultSessionDuration']);
     $course->setWithSessionEvent((bool) $courseDatas['withSessionEvent']);
     $course->setDisplayOrder($courseDatas['displayOrder']);
     $course->emptyValidators();
     $validators = isset($courseDatas['validators']) && count($courseDatas['validators']) > 0 ? $this->userManager->getUsersByIds($courseDatas['validators']) : [];
     foreach ($validators as $validator) {
         $course->addValidator($validator);
     }
     $this->cursusManager->persistCourse($course);
     $event = new LogCourseEditEvent($course);
     $this->eventDispatcher->dispatch('log', $event);
     $serializedCourse = $this->serializer->serialize($course, 'json', SerializationContext::create()->setGroups(['api_user_min']));
     return new JsonResponse($serializedCourse, 200);
 }
Example #2
0
 public function createCourse($title, $code, $description = null, $publicRegistration = false, $publicUnregistration = false, $registrationValidation = false, $tutorRoleName = null, $learnerRoleName = null, WorkspaceModel $workspaceModel = null, Workspace $workspace = null, $icon = null, $userValidation = false, $organizationValidation = false, $maxUsers = null, $defaultSessionDuration = 1, $withSessionEvent = true, array $validators = [], $displayOrder = 500)
 {
     $course = new Course();
     $course->setTitle($title);
     $course->setCode($code);
     $course->setPublicRegistration((bool) $publicRegistration);
     $course->setPublicUnregistration((bool) $publicUnregistration);
     $course->setRegistrationValidation((bool) $registrationValidation);
     $course->setWorkspaceModel($workspaceModel);
     $course->setWorkspace($workspace);
     $course->setIcon($icon);
     $course->setUserValidation((bool) $userValidation);
     $course->setOrganizationValidation((bool) $organizationValidation);
     $course->setDefaultSessionDuration($defaultSessionDuration);
     $course->setWithSessionEvent((bool) $withSessionEvent);
     $course->setDisplayOrder($displayOrder);
     if ($description) {
         $course->setDescription($description);
     }
     if ($tutorRoleName) {
         $course->setTutorRoleName($tutorRoleName);
     }
     if ($learnerRoleName) {
         $course->setLearnerRoleName($learnerRoleName);
     }
     if ($maxUsers) {
         $course->setMaxUsers($maxUsers);
     }
     foreach ($validators as $validator) {
         $course->addValidator($validator);
     }
     $this->persistCourse($course);
     $event = new LogCourseCreateEvent($course);
     $this->eventDispatcher->dispatch('log', $event);
     return $course;
 }