コード例 #1
0
 /**
  * (non-PHPdoc)
  * @see WPCW_quiz_base::renderForm_toString()
  */
 function renderForm_toString($parentQuiz, $questionNum, $selectedAnswer, $showAsError, $errorToShow = false)
 {
     // Process all answers to give them an index. Count must be 1 indexed to avoid disappearing
     // due to 0 evaluating to false.
     if ($this->quizItem->question_data_answers) {
         // Extract answers into raw format.
         $this->answerListRaw = WPCW_quizzes_decodeAnswers($this->quizItem->question_data_answers);
         // If the user has requested the answers to be randomized, then use this. This function
         // with automatically check and handle the randomization and update $this->answerListRaw.
         $this->processAnswersWithRandomOption();
         // Got answers, so break up into a list of answer => value
         if ($this->answerListRaw) {
             $this->answerList = array();
             $this->answerImageList = array();
             foreach ($this->answerListRaw as $idx => $answerItem) {
                 $answerKey = 'ans_' . $idx;
                 // Reversing the answer value to key here..
                 $this->answerList[trim($answerItem['answer'])] = $answerKey;
                 // Store the image if we have one.
                 if (isset($answerItem['image'])) {
                     $this->answerImageList[$answerKey] = $answerItem['image'];
                 }
             }
         }
     }
     // end of answer check
     // Add the hint if there is one
     if ($this->quizItem->question_answer_hint) {
         $this->extraQuizHTMLAfter .= sprintf('<div class="wpcw_fe_quiz_q_hint">%s</div>', nl2br(htmlspecialchars($this->quizItem->question_answer_hint)));
     }
     // Handover to parent. All multiple choice answers are prefixed with 'ans_'.
     return parent::renderForm_toString_withClass($parentQuiz, $questionNum, 'ans_' . $selectedAnswer, $showAsError, 'wpcw_fe_quiz_q_multi', $errorToShow);
 }
コード例 #2
0
 /**
  * Get the associated image for a multi-choice question based on the selected answer.
  * 
  * @param Object $question The question object.
  * @param Mixed $answerIdx If specified, the index of the raw answer.
  * 
  * @return String The answer for the question.
  */
 function fetch_quizzes_getImageForAnswer($question, $answerIdx)
 {
     // Multi-choice questions have images, no others do.
     if ('multi' != $question->question_type) {
         return false;
     }
     // Turn list of answers into array then use 1-indexing to get the image of the result.
     $answerListRaw = WPCW_quizzes_decodeAnswers($question->question_data_answers);
     $imageURL = false;
     // Just double check that the selected answer is valid.
     // 2013-12-06 - Added <= rather than < count for the final answer to accept the final answer.
     // Because it's 1-indexed, not 0 indexed.
     if ($answerIdx >= 0 && $answerIdx <= count($answerListRaw) && isset($answerListRaw[$answerIdx])) {
         if (isset($answerListRaw[$answerIdx]['image'])) {
             $imageURL = $answerListRaw[$answerIdx]['image'];
         }
     }
     return $imageURL;
 }