コード例 #1
0
 private function checkAnsweredQuestion(Question $question)
 {
     $questionId = $question->getId();
     $answeredQuestions = $this->surveyManager->checkQuestionAnswersByQuestions([$question]);
     if (isset($answeredQuestions[$questionId]) && $answeredQuestions[$questionId]) {
         throw new AccessDeniedException();
     }
 }
コード例 #2
0
 private function checkQuestionRight(Survey $survey, Question $question, $right)
 {
     $this->checkSurveyRight($survey, $right);
     $surveyWorkspaceId = $survey->getResourceNode()->getWorkspace()->getId();
     $questionWorkspaceId = $question->getWorkspace()->getId();
     if ($surveyWorkspaceId !== $questionWorkspaceId) {
         throw new AccessDeniedException();
     }
 }
コード例 #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 createQuestionModel(Question $question)
 {
     $questionType = $question->getType();
     $model = new QuestionModel();
     $model->setTitle($question->getTitle());
     $model->setQuestionType($questionType);
     $model->setWorkspace($question->getWorkspace());
     $details = [];
     switch ($questionType) {
         case 'multiple_choice_single':
         case 'multiple_choice_multiple':
             $choiceQuestion = $this->getMultipleChoiceQuestionByQuestion($question);
             $details['questionType'] = $questionType;
             if ($question->isCommentAllowed()) {
                 $details['withComment'] = 'comment';
                 $details['commentLabel'] = $question->getCommentLabel();
             } else {
                 $details['withComment'] = 'no-comment';
             }
             $horizontal = !is_null($choiceQuestion) && $choiceQuestion->getHorizontal();
             $details['choiceDisplay'] = $horizontal ? 'horizontal' : 'vertical';
             $details['choices'] = [];
             if (!is_null($choiceQuestion)) {
                 $choices = $this->getChoicesByQuestion($question);
                 foreach ($choices as $choice) {
                     $choiceDetails = [];
                     $choiceDetails['other'] = $choice->isOther() ? 'other' : 'not-other';
                     $choiceDetails['content'] = $choice->getContent();
                     $details['choices'][] = $choiceDetails;
                 }
             }
             break;
         case 'open_ended':
         case 'open_ended_bare':
         case 'simple_text':
         default:
             break;
     }
     $model->setDetails($details);
     $this->om->persist($model);
     $this->om->flush();
 }