Ejemplo n.º 1
0
 public function check_answer()
 {
     global $DB, $CFG;
     $formattextdefoptions = new stdClass();
     $formattextdefoptions->noclean = true;
     $formattextdefoptions->para = false;
     $answers = $this->get_answers();
     shuffle($answers);
     $params = array('answers' => $answers, 'lessonid' => $this->lesson->id, 'contents' => $this->get_contents());
     $mform = new lesson_display_answer_form_truefalse($CFG->wwwroot . '/mod/lesson/continue.php', $params);
     $data = $mform->get_data();
     require_sesskey();
     $result = parent::check_answer();
     if (empty($data->answerid)) {
         $result->noanswer = true;
         return $result;
     }
     $result->answerid = $data->answerid;
     $answer = $DB->get_record("lesson_answers", array("id" => $result->answerid), '*', MUST_EXIST);
     if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) {
         $result->correctanswer = true;
     }
     if ($this->lesson->custom) {
         if ($answer->score > 0) {
             $result->correctanswer = true;
         } else {
             $result->correctanswer = false;
         }
     }
     $result->newpageid = $answer->jumpto;
     $result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
     $result->studentanswer = $result->userresponse = $answer->answer;
     return $result;
 }