public static function create(Question $question, $container) { if (isset(self::$mappings[$question->getType()])) { return new self::$mappings[$question->getType()]($question, $container); } else { throw new \RuntimeException("Could not create question of type " . $question->getType()); } }
public function getQuestionStats(Question $question, $participants) { $complete = array(); foreach ($question->getAnswers() as $answer) { $trueCount = 0; $falseCount = 0; foreach ($participants as $participant) { foreach ($participant->getAnswers() as $participantAnswer) { // Do not count opinion in stats. if ($participantAnswer->getOpinion() != null) { continue; } if ($participantAnswer->getAnswer()->getId() == $answer->getId()) { if ($participantAnswer->getChecked() == true) { $trueCount++; } else { $falseCount++; } if ($question->getType() == 'SINGLE') { break; } } } } array_push($complete, new AnswerStat($trueCount, $falseCount, $answer->getContent())); } return $complete; }
/** * @param Question $question * @return array */ private function prepareQuestion(Question $question) { $questionData = array(); $questionData['id'] = $question->getId(); $questionData['title'] = $question->getTitle(); $questionData['content'] = $question->getContent(); $questionData['type'] = $question->getType(); $questionData['nextQuestionId'] = $question->getNextQuestionId(); $questionData['tickLength'] = $question->getTickLength(); /** * @var PotentialAnswer $potentialAnswer */ foreach ($question->getPotentialAnswers() as $potentialAnswer) { $questionData['potentialAnswers'][] = array('id' => $potentialAnswer->getId(), 'answer' => $potentialAnswer->getAnswer(), 'questionId' => $question->getId(), 'nextQuestionId' => $potentialAnswer->getNextQuestionId(), 'realAnswer' => $potentialAnswer->getRealAnswer()); } /** * @var QuestionAttachment $attachment */ foreach ($question->getAttachments() as $attachment) { $questionData['attachments'][] = array('id' => $attachment->getId(), 'title' => $attachment->getTitle(), 'path' => $attachment->getPath(), 'description' => $attachment->getDescription(), 'questionId' => $question->getId()); } return $questionData; }
private function getAnswer(Question $question, User $user) { switch ($question->getType()) { case Question::GROUP_FIX: return $this->parseGroupFixAnswer($question, $user); break; case Question::REGISTRATION: return $this->parseRegistrationAnswer($question, $user); break; default: $repository = $this->getDoctrine()->getRepository('AppBundle:Answer'); /** * @var Answer $answer */ $answer = $repository->findOneBy(array('question_id' => $question->getId(), 'created_by' => $user->getId())); return $answer->getAnswer(); } }
private function getAnswer(Question $question, User $user) { switch ($question->getType()) { case Question::GROUP_FIX: return $this->parseGroupFixAnswer($question, $user); break; case Question::REGISTRATION: return $this->parseRegistrationAnswer($question, $user); break; default: return $this->parseRegularAnswer($question, $user); } }