Ejemplo n.º 1
0
 public function test_lesson_essay_extract_useranswer()
 {
     // Test that reponseformat is added when not present.
     $answer = 'O:8:"stdClass":6:{s:4:"sent";i:1;s:6:"graded";i:1;s:5:"score";s:1:"1";' . 's:6:"answer";s:64:"<p>This is my answer <b>with bold</b> and <i>italics</i><br></p>";' . 's:12:"answerformat";s:1:"1";s:8:"response";s:10:"Well done!";}';
     $userresponse = new stdClass();
     $userresponse->sent = 1;
     $userresponse->graded = 1;
     $userresponse->score = 1;
     $userresponse->answer = "<p>This is my answer <b>with bold</b> and <i>italics</i><br></p>";
     $userresponse->answerformat = FORMAT_HTML;
     $userresponse->response = "Well done!";
     $userresponse->responseformat = FORMAT_HTML;
     $this->assertEquals($userresponse, lesson_page_type_essay::extract_useranswer($answer));
     // Test that reponseformat is not modified when present.
     $answer = 'O:8:"stdClass":7:{s:4:"sent";i:0;s:6:"graded";i:1;s:5:"score";s:1:"0";' . 's:6:"answer";s:64:"<p>This is my answer <b>with bold</b> and <i>italics</i><br></p>";' . 's:12:"answerformat";s:1:"1";s:8:"response";s:10:"Well done!";s:14:"responseformat";s:1:"2";}';
     $userresponse = new stdClass();
     $userresponse->sent = 0;
     $userresponse->graded = 1;
     $userresponse->score = 0;
     $userresponse->answer = "<p>This is my answer <b>with bold</b> and <i>italics</i><br></p>";
     $userresponse->answerformat = FORMAT_HTML;
     $userresponse->response = "Well done!";
     $userresponse->responseformat = FORMAT_PLAIN;
     $this->assertEquals($userresponse, lesson_page_type_essay::extract_useranswer($answer));
 }
Ejemplo n.º 2
0
         $table->data[] = array($OUTPUT->user_picture($users[$userid], array('courseid' => $course->id)) . $studentname, implode("<br />", $essaylinks), $emaillink);
     }
     // email link for all users
     $url = new moodle_url('/mod/lesson/essay.php', array('id' => $cm->id, 'mode' => 'email', 'sesskey' => sesskey()));
     $emailalllink = html_writer::link($url, get_string('emailallgradedessays', 'lesson'));
     $table->data[] = array(' ', ' ', $emailalllink);
     echo html_writer::table($table);
     break;
 case 'grade':
     // Trigger the essay grade viewed event.
     $event = \mod_lesson\event\essay_attempt_viewed::create(array('objectid' => $attempt->id, 'relateduserid' => $attempt->userid, 'context' => $context, 'courseid' => $course->id));
     $event->add_record_snapshot('lesson_attempts', $attempt);
     $event->trigger();
     // Grading form
     // Expects the following to be set: $attemptid, $answer, $user, $page, $attempt
     $essayinfo = lesson_page_type_essay::extract_useranswer($attempt->useranswer);
     $currentpage = $lesson->load_page($attempt->pageid);
     $mform = new essay_grading_form(null, array('scoreoptions' => $scoreoptions, 'user' => $user));
     $data = new stdClass();
     $data->id = $cm->id;
     $data->attemptid = $attemptid;
     $data->score = $essayinfo->score;
     $data->question = format_text($currentpage->contents, $currentpage->contentsformat, $formattextdefoptions);
     $data->studentanswer = format_text($essayinfo->answer, $essayinfo->answerformat, array('context' => $context, 'para' => true));
     $data->response = $essayinfo->response;
     $data->responseformat = $essayinfo->responseformat;
     $editoroptions = array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'context' => $context);
     $data = file_prepare_standard_editor($data, 'response', $editoroptions, $context, 'mod_lesson', 'essay_responses', $attempt->id);
     $mform->set_data($data);
     $mform->display();
     break;
Ejemplo n.º 3
0
 public function definition()
 {
     global $USER, $OUTPUT;
     $mform = $this->_form;
     $contents = $this->_customdata['contents'];
     $hasattempt = false;
     $attrs = '';
     $useranswer = '';
     $useranswerraw = '';
     if (isset($this->_customdata['lessonid'])) {
         $lessonid = $this->_customdata['lessonid'];
         if (isset($USER->modattempts[$lessonid]->useranswer) && !empty($USER->modattempts[$lessonid]->useranswer)) {
             $attrs = array('disabled' => 'disabled');
             $hasattempt = true;
             $useranswertemp = lesson_page_type_essay::extract_useranswer($USER->modattempts[$lessonid]->useranswer);
             $useranswer = htmlspecialchars_decode($useranswertemp->answer, ENT_QUOTES);
             $useranswerraw = $useranswertemp->answer;
         }
     }
     // Disable shortforms.
     $mform->setDisableShortforms();
     $mform->addElement('header', 'pageheader');
     $mform->addElement('html', $OUTPUT->container($contents, 'contents'));
     $options = new stdClass();
     $options->para = false;
     $options->noclean = true;
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'pageid');
     $mform->setType('pageid', PARAM_INT);
     if ($hasattempt) {
         $mform->addElement('hidden', 'answer', $useranswerraw);
         $mform->setType('answer', PARAM_RAW);
         $mform->addElement('html', $OUTPUT->container(get_string('youranswer', 'lesson'), 'youranswer'));
         $mform->addElement('html', $OUTPUT->container($useranswer, 'reviewessay'));
         $this->add_action_buttons(null, get_string("nextpage", "lesson"));
     } else {
         $mform->addElement('editor', 'answer', get_string('youranswer', 'lesson'), null, null);
         $mform->setType('answer', PARAM_RAW);
         $this->add_action_buttons(null, get_string("submit", "lesson"));
     }
 }