/** * Creates a new InteractionMatching entity. * * @access public * * @return \Symfony\Component\HttpFoundation\Response */ public function createAction() { $services = $this->container->get('ujm.exercise_services'); $interMatching = new InteractionMatching(); $form = $this->createForm(new InteractionMatchingType($this->container->get('security.token_storage')->getToken()->getUser()), $interMatching); $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 InteractionMatchingHandler($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')); $matchingHandler = $formHandler->processAdd(); if ($matchingHandler === TRUE) { $categoryToFind = $interMatching->getInteraction()->getQuestion()->getCategory(); $titleToFind = $interMatching->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 ($matchingHandler == 'infoDuplicateQuestion') { $form->addError(new FormError($this->get('translator')->trans('info_duplicate_question'))); } $typeMatching = $services->getTypeMatching(); $formWithError = $this->render('UJMExoBundle:InteractionMatching:new.html.twig', array('entity' => $interMatching, 'form' => $form->createView(), 'error' => true, 'exoID' => $exoID, 'typeMatching' => json_encode($typeMatching))); $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)); }
/** * Creates a new InteractionMatching entity. * * * @return \Symfony\Component\HttpFoundation\Response */ public function createAction() { $interMatchSer = $this->container->get('ujm.exo_InteractionMatching'); $interMatching = new InteractionMatching(); $form = $this->createForm(new InteractionMatchingType($this->container->get('security.token_storage')->getToken()->getUser()), $interMatching); $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 InteractionMatchingHandler($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')); $matchingHandler = $formHandler->processAdd(); if ($matchingHandler === true) { $categoryToFind = $interMatching->getQuestion()->getCategory(); $titleToFind = $interMatching->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 ($matchingHandler == 'infoDuplicateQuestion') { $form->addError(new FormError($this->get('translator')->trans('info_duplicate_question', [], 'ujm_exo'))); } $typeMatching = $interMatchSer->getTypeMatching(); $formWithError = $this->render('UJMExoBundle:InteractionMatching:new.html.twig', ['entity' => $interMatching, 'form' => $form->createView(), 'error' => true, 'exoID' => $exoID, 'stepID' => $stepID, 'typeMatching' => json_encode($typeMatching)]); $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]); }