public function check_answer() { global $PAGE, $CFG; $result = parent::check_answer(); $result->isessayquestion = true; $mform = new lesson_display_answer_form_essay($CFG->wwwroot . '/mod/lesson/continue.php', array('contents' => $this->get_contents())); $data = $mform->get_data(); require_sesskey(); if (!$data) { redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $this->properties->id))); } if (is_array($data->answer)) { $studentanswer = $data->answer['text']; $studentanswerformat = $data->answer['format']; } else { $studentanswer = $data->answer; $studentanswerformat = FORMAT_MOODLE; } if (trim($studentanswer) === '') { $result->noanswer = true; return $result; } $answers = $this->get_answers(); foreach ($answers as $answer) { $result->answerid = $answer->id; $result->newpageid = $answer->jumpto; } $userresponse = new stdClass(); $userresponse->sent = 0; $userresponse->graded = 0; $userresponse->score = 0; $userresponse->answer = $studentanswer; $userresponse->answerformat = $studentanswerformat; $userresponse->response = ""; $result->userresponse = serialize($userresponse); $result->studentanswerformat = $studentanswerformat; $result->studentanswer = $studentanswer; return $result; }