/**
  * @EXT\Route(
  *     "/survey/{survey}/question/title/create",
  *     name="claro_survey_question_title_create"
  * )
  * @EXT\Template("ClarolineSurveyBundle:Survey:questionTitleCreateForm.html.twig")
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function questionTitleCreateAction(Survey $survey)
 {
     $this->checkSurveyRight($survey, 'EDIT');
     $question = new Question();
     $question->setTitle('TITLE');
     $form = $this->formFactory->create(new QuestionTitleType(), $question);
     $form->handleRequest($this->request->getCurrentRequest());
     if ($form->isValid()) {
         $question->setType('title');
         $question->setWorkspace($survey->getResourceNode()->getWorkspace());
         $question->setCommentAllowed(false);
         $this->surveyManager->persistQuestion($question);
         $this->surveyManager->createSurveyQuestionRelation($survey, $question);
         return new RedirectResponse($this->router->generate('claro_survey_management', ['survey' => $survey->getId()]));
     }
     return ['form' => $form->createView(), 'survey' => $survey];
 }
Example #2
0
 /**
  * @DI\Observe("copy_claroline_survey")
  *
  * @param CopyResourceEvent $event
  */
 public function onCopy(CopyResourceEvent $event)
 {
     $workspace = $event->getParent()->getWorkspace();
     $survey = $event->getResource();
     $copy = new Survey();
     $copy->setPublished($survey->isPublished());
     $copy->setClosed($survey->isClosed());
     $copy->setHasPublicResult($survey->getHasPublicResult());
     $copy->setAllowAnswerEdition($survey->getAllowAnswerEdition());
     $copy->setStartDate($survey->getStartDate());
     $copy->setEndDate($survey->getEndDate());
     $this->om->persist($copy);
     $relations = $survey->getQuestionRelations();
     foreach ($relations as $relation) {
         $question = $relation->getQuestion();
         $type = $question->getType();
         $copyQuestion = new Question();
         $copyQuestion->setTitle($question->getTitle());
         $copyQuestion->setQuestion($question->getQuestion());
         $copyQuestion->setWorkspace($workspace);
         $copyQuestion->setType($type);
         $copyQuestion->setCommentAllowed($question->isCommentAllowed());
         $copyQuestion->setCommentLabel($question->getCommentLabel());
         $this->om->persist($copyQuestion);
         switch ($type) {
             case 'multiple_choice_single':
             case 'multiple_choice_multiple':
                 $multiChoiceQuestion = $this->surveyManager->getMultipleChoiceQuestionByQuestion($question);
                 $choices = $multiChoiceQuestion->getChoices();
                 $copyMultiQuestion = new MultipleChoiceQuestion();
                 $copyMultiQuestion->setHorizontal($multiChoiceQuestion->getHorizontal());
                 $copyMultiQuestion->setQuestion($copyQuestion);
                 foreach ($choices as $choice) {
                     $copyChoice = new Choice();
                     $copyChoice->setContent($choice->getContent());
                     $copyChoice->setOther($choice->isOther());
                     $copyChoice->setChoiceQuestion($copyMultiQuestion);
                     $this->om->persist($copyChoice);
                 }
                 $this->om->persist($copyMultiQuestion);
                 break;
             case 'open-ended':
             default:
                 break;
         }
         $copyRelation = new SurveyQuestionRelation();
         $copyRelation->setSurvey($copy);
         $copyRelation->setQuestion($copyQuestion);
         $copyRelation->setQuestionOrder($relation->getQuestionOrder());
         $this->om->persist($copyRelation);
     }
     $event->setCopy($copy);
     $event->stopPropagation();
 }