public function createQuestionPdf() { $dbEntry = entryPeer::retrieveByPK($this->entryId); $title = "Here are the questions from [" . $dbEntry->getName() . "]"; KalturaLog::debug("Questions from [" . $dbEntry->getName() . "]"); $this->pdf->addTitle($title, $this->titleStyle); $questionType = QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_QUESTION); $questions = CuePointPeer::retrieveByEntryId($this->entryId, array($questionType)); //arange the array so that the questions will be the key for the array $questArray = array(); foreach ($questions as $question) { $questArray[$question->getName()] = $question; } //sort the array alphabetically according to its key; i.e. the question ksort($questArray, SORT_LOCALE_STRING); $questNum = 0; foreach ($questArray as $question) { $questNum += 1; $this->pdf->addList($questNum, $question->getName(), $this->listWithAddLineBeforeStyle); $this->pdf->addHeadline(6, "Optional Answers:", $this->heading6Style); $ansNum = 0; foreach ($question->getOptionalAnswers() as $optionalAnswer) { $ansNum += 1; $this->pdf->addList($ansNum, $optionalAnswer->getText(), $this->indentListStyle); } } }
/** * @param $entryId * @return int */ public function calculateScore() { $finalScore = 0; $answerType = QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_ANSWER); $answers = CuePointPeer::retrieveByEntryId($this->getEntryId(), array($answerType)); foreach ($answers as $answer) { /** * @var AnswerCuePoint $answer */ $question = CuePointPeer::retrieveByPK($answer->getParentId()); /** * @var QuestionCuePoint $question */ $optionalAnswers = $question->getOptionalAnswers(); foreach ($optionalAnswers as $optionalAnswer) { /** * @var kOptionalAnswer $optionalAnswer */ if ($optionalAnswer->getKey() === $answer->getAnswerKey()) { if ($optionalAnswer->getIsCorrect()) { $finalScore += $optionalAnswer->getWeight(); } } } } return $finalScore; }
public function calculateScoreAndCorrectAnswers() { //TODO when we have indexing of CuePoints in the sphinx we don't need the answerIds in the custom_data since we can just get the answers of the specific userEntry $answerIds = $this->getAnswerIds(); $questionType = QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_QUESTION); $questions = CuePointPeer::retrieveByEntryId($this->getEntryId(), array($questionType)); $totalPoints = 0; $userPoints = 0; $numOfCorrectAnswers = 0; foreach ($questions as $question) { $optionalAnswers = $question->getOptionalAnswers(); $answers = array(); if (isset($answerIds[$question->getId()])) { $answerId = $answerIds[$question->getId()]; //TODO change to retrieveByPks (multiple, only one query, no need for multiple) $currAnswer = CuePointPeer::retrieveByPK($answerId); if ($currAnswer->getIsCorrect()) { $numOfCorrectAnswers++; } $answers[] = $currAnswer; } list($totalForQuestion, $userPointsForQuestion) = $this->getCorrectAnswerWeight($optionalAnswers, $answers); $totalPoints += $totalForQuestion; $userPoints += $userPointsForQuestion; } $score = $totalPoints ? $userPoints / $totalPoints : 0; return array($score, $numOfCorrectAnswers); }
public function createQuestionPdf() { $dbEntry = entryPeer::retrieveByPK($this->entryId); $title = "Here are the questions from [" . $dbEntry->getName() . "]"; $this->pdf->addTitle($title, $this->titleStyle); $questionType = QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_QUESTION); $questions = CuePointPeer::retrieveByEntryId($this->entryId, array($questionType)); $questNum = 0; foreach ($questions as $question) { $questNum += 1; $this->pdf->addList($questNum, $question->getName(), $this->listWithAddLineBeforeStyle); $this->pdf->addHeadline(6, "Optional Answers:", $this->heading6Style); $ansNum = 0; foreach ($question->getOptionalAnswers() as $optionalAnswer) { $ansNum += 1; $this->pdf->addList($ansNum, $optionalAnswer->getText(), $this->indentListStyle); } } }
public function calculateScore() { $answerIds = $this->getAnswerIds(); $questionType = QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_QUESTION); $questions = CuePointPeer::retrieveByEntryId($this->getEntryId(), array($questionType)); $totalPoints = 0; $userPoints = 0; foreach ($questions as $question) { $optionalAnswers = $question->getOptionalAnswers(); $answers = array(); if (isset($answerIds[$question->getId()])) { $answerId = $answerIds[$question->getId()]; $currAnswer = CuePointPeer::retrieveByPK($answerId); $answers[] = $currAnswer; } list($totalForQuestion, $userPointsForQuestion) = $this->getCorrectAnswerWeight($optionalAnswers, $answers); $totalPoints += $totalForQuestion; $userPoints += $userPointsForQuestion; } return $totalPoints ? $userPoints / $totalPoints : 0; }
/** * Applies default values to this object. * This method should be called from the object's constructor (or equivalent initialization method). * @see __construct() */ public function applyDefaultValues() { $this->setType(QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_ANSWER)); }