예제 #1
0
 /**
  * @EXT\Route(
  *     "/survey/{survey}/question/order/update/relation/{relation}/with/{otherRelation}/mode/{mode}",
  *     name="claro_survey_update_question_order",
  *     options={"expose"=true}
  * )
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function updateQuestionOrderAction(Survey $survey, SurveyQuestionRelation $relation, SurveyQuestionRelation $otherRelation, $mode)
 {
     $this->checkSurveyRight($survey, 'EDIT');
     if ($relation->getSurvey()->getId() === $survey->getId() && $otherRelation->getSurvey()->getId() === $survey->getId()) {
         $newOrder = $otherRelation->getQuestionOrder();
         if ($mode === 'next') {
             $this->surveyManager->updateQuestionOrder($survey, $relation, $newOrder);
         } else {
             $relation->setQuestionOrder($newOrder + 1);
             $this->surveyManager->persistSurveyQuestionRelation($relation);
         }
         return new Response('success', 204);
     } else {
         return new Response('Forbidden', 403);
     }
 }
예제 #2
0
 /**
  * @DI\Observe("copy_claroline_survey")
  *
  * @param CopyResourceEvent $event
  */
 public function onCopy(CopyResourceEvent $event)
 {
     $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) {
         $newRelation = new SurveyQuestionRelation();
         $newRelation->setSurvey($copy);
         $newRelation->setQuestion($relation->getQuestion());
         $newRelation->setQuestionOrder($relation->getQuestionOrder());
         $this->om->persist($newRelation);
     }
     $event->setCopy($copy);
     $event->stopPropagation();
 }
예제 #3
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();
 }
예제 #4
0
 public function updateQuestionOrder(Survey $survey, SurveyQuestionRelation $relation, $questionOrder)
 {
     $this->updateQuestionOrderBySurvey($survey, $questionOrder);
     $relation->setQuestionOrder($questionOrder);
     $this->om->persist($relation);
     $this->om->flush();
 }