public function cursus($name, Cursus $parent = null, Course $course = null, $order = 0, $blocking = false)
 {
     $cursus = new Cursus();
     $cursus->setTitle($name);
     $cursus->setCode($name);
     $cursus->setDescription($name);
     $cursus->setParent($parent);
     $cursus->setCourse($course);
     $cursus->setCursusOrder($order);
     $cursus->setBlocking($blocking);
     $this->om->persist($cursus);
     return $cursus;
 }
Example #2
0
 private function importCursusChildren(array $parent, array $children, array $courses, array $codes, array &$createdCursus, &$index)
 {
     if (isset($parent['id']) && isset($children[$parent['id']])) {
         foreach ($children[$parent['id']] as $child) {
             $cursus = new Cursus();
             $cursus->setTitle($child['title']);
             $cursus->setDescription($child['description']);
             $cursus->setBlocking($child['blocking']);
             $cursus->setCursusOrder($child['cursus_order']);
             $cursus->setDetails($child['details']);
             if (isset($createdCursus[$parent['id']])) {
                 $cursus->setParent($createdCursus[$parent['id']]);
             }
             if (!empty($child['course']) && isset($courses[$child['course']])) {
                 $cursus->setCourse($courses[$child['course']]);
             }
             if (!empty($child['code'])) {
                 $code = $this->generateValidCode($child['code'], $codes);
                 $cursus->setCode($code);
             }
             $this->om->persist($cursus);
             $createdCursus[$child['id']] = $cursus;
             $index++;
             if ($index % 50 === 0) {
                 $this->om->forceFlush();
             }
             if (isset($children[$child['id']])) {
                 $this->importCursusChildren($child, $children, $courses, $codes, $createdCursus, $index);
             }
         }
     }
 }
 /**
  * @EXT\Route(
  *     "/api/cursus/{cursus}/edit",
  *     name="api_put_cursus_edition",
  *     options = {"expose"=true}
  * )
  * @EXT\ParamConverter("user", converter="current_user")
  *
  * Edits a cursus
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function putCursusEditionAction(Cursus $cursus)
 {
     $cursusDatas = $this->request->request->get('cursusDatas', false);
     $cursus->setTitle($cursusDatas['title']);
     $cursus->setCode($cursusDatas['code']);
     $cursus->setDescription($cursusDatas['description']);
     $cursus->setBlocking((bool) $cursusDatas['blocking']);
     $color = $cursusDatas['color'];
     $details = ['color' => $color];
     $cursus->setDetails($details);
     if ($cursusDatas['workspace']) {
         $worskpace = $this->workspaceManager->getWorkspaceById($cursusDatas['workspace']);
         $cursus->setWorkspace($worskpace);
     }
     if ($this->request->files->get('cursusDatas')['icon']) {
         $icon = $this->cursusManager->saveIcon($this->request->files->get('cursusDatas')['icon']);
         $cursus->setIcon($icon);
     }
     $this->cursusManager->persistCursus($cursus);
     $event = new LogCursusEditEvent($cursus);
     $this->eventDispatcher->dispatch('log', $event);
     $serializedCursus = $this->serializer->serialize($cursus, 'json', SerializationContext::create()->setGroups(['api_workspace_min']));
     return new JsonResponse($serializedCursus, 200);
 }