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