Example #1
0
 public function importCourses(array $datas)
 {
     $courses = array();
     $i = 0;
     $usedCodes = $this->getAllCoursesCodes();
     $this->om->startFlushSuite();
     foreach ($datas as $data) {
         $course = new Course();
         $code = $this->generateValidCode($data['code'], $usedCodes);
         $course->setCode($code);
         $course->setTitle($data['title']);
         $course->setDescription($data['description']);
         $course->setPublicRegistration($data['publicRegistration']);
         $course->setPublicUnregistration($data['publicUnregistration']);
         $course->setRegistrationValidation($data['registrationValidation']);
         if (isset($data['icon'])) {
             $course->setIcon($data['icon']);
         }
         $this->om->persist($course);
         $courses[$data['id']] = $course;
         $i++;
         if ($i % 50 === 0) {
             $this->om->forceFlush();
         }
     }
     $this->om->endFlushSuite();
     return $courses;
 }
 /**
  * @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);
 }