/**
  * @EXT\Route(
  *     "/survey/{survey}/model/{model}/details/retrieve",
  *     name="claro_survey_retrieve_model_details",
  *     options={"expose"=true}
  * )
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function retrieveModelDetailsAction(Survey $survey, QuestionModel $model)
 {
     $canEdit = $this->hasSurveyRight($survey, 'EDIT');
     $workspaceIdA = $survey->getResourceNode()->getWorkspace()->getId();
     $workspaceIdB = $model->getWorkspace()->getId();
     if (!$canEdit || $workspaceIdA !== $workspaceIdB) {
         throw new AccessDeniedException();
     }
     return new Response(json_encode($model->getDetails()), 200);
 }
Example #2
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();
 }