/** * Creates a new InteractionQCM entity. * * * @return \Symfony\Component\HttpFoundation\Response */ public function createAction() { $services = $this->container->get('ujm.exo.qcm_service'); $interQCM = new InteractionQCM(); $form = $this->createForm(new InteractionQCMType($this->container->get('security.token_storage')->getToken()->getUser()), $interQCM); $exoID = $this->container->get('request')->request->get('exercise'); $stepID = $this->container->get('request')->request->get('step'); //Get the lock category $catSer = $this->container->get('ujm.exo_category'); $exercise = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Exercise')->find($exoID); $step = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Step')->find($stepID); $formHandler = new InteractionQCMHandler($form, $this->get('request'), $this->getDoctrine()->getManager(), $this->container->get('ujm.exo_exercise'), $catSer, $this->container->get('security.token_storage')->getToken()->getUser(), $exercise, $step, $this->get('translator')); $qcmHandler = $formHandler->processAdd(); if ($qcmHandler === true) { $categoryToFind = $interQCM->getQuestion()->getCategory(); $titleToFind = $interQCM->getQuestion()->getTitle(); if ($exoID == -1) { return $this->redirect($this->generateUrl('ujm_question_index', ['categoryToFind' => base64_encode($categoryToFind), 'titleToFind' => base64_encode($titleToFind)])); } else { return $this->redirect($this->generateUrl('ujm_exercise_open', ['id' => $exoID]) . '#/steps'); } } if ($qcmHandler == 'infoDuplicateQuestion') { $form->addError(new FormError($this->get('translator')->trans('info_duplicate_question', [], 'ujm_exo'))); } $typeQCM = $services->getTypeQCM(); $formWithError = $this->render('UJMExoBundle:InteractionQCM:new.html.twig', ['entity' => $interQCM, 'form' => $form->createView(), 'error' => true, 'exoID' => $exoID, 'stepID' => $stepID, 'typeQCM' => json_encode($typeQCM)]); $interactionType = $this->container->get('ujm.exo_question')->getTypes(); $formWithError = substr($formWithError, strrpos($formWithError, 'GMT') + 3); return $this->render('UJMExoBundle:Question:new.html.twig', ['formWithError' => $formWithError, 'exoID' => $exoID, 'stepID' => $stepID, 'linkedCategory' => $catSer->getLinkedCategories(), 'locker' => $catSer->getLockCategory(), 'interactionType' => $interactionType]); }
/** * Creates a new InteractionQCM entity. * * @access public * * @return \Symfony\Component\HttpFoundation\Response */ public function createAction() { $services = $this->container->get('ujm.exercise_services'); $interQCM = new InteractionQCM(); $form = $this->createForm(new InteractionQCMType($this->container->get('security.token_storage')->getToken()->getUser()), $interQCM); $exoID = $this->container->get('request')->request->get('exercise'); //Get the lock category $user = $this->container->get('security.token_storage')->getToken()->getUser()->getId(); $Locker = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Category')->getCategoryLocker($user); if (empty($Locker)) { $catLocker = ""; } else { $catLocker = $Locker[0]; } $exercise = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Exercise')->find($exoID); $formHandler = new InteractionQCMHandler($form, $this->get('request'), $this->getDoctrine()->getManager(), $this->container->get('ujm.exercise_services'), $this->container->get('security.token_storage')->getToken()->getUser(), $exercise, $this->get('translator')); $qcmHandler = $formHandler->processAdd(); if ($qcmHandler === TRUE) { $categoryToFind = $interQCM->getInteraction()->getQuestion()->getCategory(); $titleToFind = $interQCM->getInteraction()->getQuestion()->getTitle(); if ($exoID == -1) { return $this->redirect($this->generateUrl('ujm_question_index', array('categoryToFind' => base64_encode($categoryToFind), 'titleToFind' => base64_encode($titleToFind)))); } else { return $this->redirect($this->generateUrl('ujm_exercise_questions', array('id' => $exoID, 'categoryToFind' => $categoryToFind, 'titleToFind' => $titleToFind))); } } if ($qcmHandler == 'infoDuplicateQuestion') { $form->addError(new FormError($this->get('translator')->trans('info_duplicate_question'))); } $typeQCM = $services->getTypeQCM(); $formWithError = $this->render('UJMExoBundle:InteractionQCM:new.html.twig', array('entity' => $interQCM, 'form' => $form->createView(), 'error' => true, 'exoID' => $exoID, 'typeQCM' => json_encode($typeQCM))); $formWithError = substr($formWithError, strrpos($formWithError, 'GMT') + 3); return $this->render('UJMExoBundle:Question:new.html.twig', array('formWithError' => $formWithError, 'exoID' => $exoID, 'linkedCategory' => $this->container->get('ujm.exercise_services')->getLinkedCategories(), 'locker' => $catLocker)); }