MDL-23197 ugly hack that adds editor support into lesson answers and responses - no files support planned for 2.0, sorry
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="mod/lesson/db" VERSION="20100629" COMMENT="XMLDB file for Moodle mod/lesson"
|
||||
<XMLDB PATH="mod/lesson/db" VERSION="20100720" COMMENT="XMLDB file for Moodle mod/lesson"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -86,8 +86,10 @@
|
||||
<FIELD NAME="flags" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="score" NEXT="timecreated"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="flags" NEXT="timemodified"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated" NEXT="answer"/>
|
||||
<FIELD NAME="answer" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="timemodified" NEXT="response"/>
|
||||
<FIELD NAME="response" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="answer"/>
|
||||
<FIELD NAME="answer" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="timemodified" NEXT="answerformat"/>
|
||||
<FIELD NAME="answerformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="answer" NEXT="response"/>
|
||||
<FIELD NAME="response" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="answerformat" NEXT="responseformat"/>
|
||||
<FIELD NAME="responseformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="response"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="lessonid"/>
|
||||
|
||||
@@ -156,6 +156,7 @@ function xmldb_lesson_upgrade($oldversion) {
|
||||
$dbman->drop_table($table);
|
||||
upgrade_mod_savepoint(true, 2009120800, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009120801) {
|
||||
|
||||
/// Define field contentsformat to be added to lesson_pages
|
||||
@@ -182,6 +183,53 @@ function xmldb_lesson_upgrade($oldversion) {
|
||||
upgrade_mod_savepoint(true, 2009120801, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010072000) {
|
||||
// Define field answerformat to be added to lesson_answers
|
||||
$table = new xmldb_table('lesson_answers');
|
||||
$field = new xmldb_field('answerformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'answer');
|
||||
|
||||
// Launch add field answerformat
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
// lesson savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010072000, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010072001) {
|
||||
// Define field responseformat to be added to lesson_answers
|
||||
$table = new xmldb_table('lesson_answers');
|
||||
$field = new xmldb_field('responseformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'response');
|
||||
|
||||
// Launch add field responseformat
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
// lesson savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010072001, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010072003) {
|
||||
$rs = $DB->get_recordset('lesson_answers', array());
|
||||
foreach ($rs as $answer) {
|
||||
$flags = intval($answer->flags);
|
||||
$update = false;
|
||||
if ($flags & 1) {
|
||||
$answer->answer = text_to_html($answer->answer, false, false, true);
|
||||
$answer->answerformat = FORMAT_HTML;
|
||||
$update = true;
|
||||
}
|
||||
if ($flags & 2) {
|
||||
$answer->response = text_to_html($answer->response, false, false, true);
|
||||
$answer->responseformat = FORMAT_HTML;
|
||||
$update = true;
|
||||
}
|
||||
if ($update) {
|
||||
$DB->update_record('lesson_answers', $answer);
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
upgrade_mod_savepoint(true, 2010072003, 'lesson');
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+13
-11
@@ -57,13 +57,15 @@ if ($edit) {
|
||||
|
||||
$jumpto = lesson_page::get_jumptooptions($pageid, $lesson);
|
||||
$manager = lesson_page_type_manager::get($lesson);
|
||||
$mform = $manager->get_page_form($qtype, array('editoroptions'=>null, 'jumpto'=>$jumpto, 'lesson'=>$lesson, 'edit'=>$edit, 'maxbytes'=>$PAGE->course->maxbytes));
|
||||
$editoroptions = array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes);
|
||||
$mform = $manager->get_page_form($qtype, array('editoroptions'=>$editoroptions, 'jumpto'=>$jumpto, 'lesson'=>$lesson, 'edit'=>$edit, 'maxbytes'=>$PAGE->course->maxbytes));
|
||||
|
||||
if ($edit) {
|
||||
$properties = $editpage->properties();
|
||||
$properties->pageid = $editpage->id;
|
||||
$properties->id = $cm->id;
|
||||
$mform->set_data($properties, $context, $editpage->id);
|
||||
$data = $editpage->properties();
|
||||
$data->pageid = $editpage->id;
|
||||
$data->id = $cm->id;
|
||||
$data = file_prepare_standard_editor($data, 'contents', $editoroptions, $context, 'mod_lesson', 'page_contents', $editpage->id);
|
||||
$mform->set_data($data);
|
||||
$PAGE->navbar->add(get_string('edit'), new moodle_url('/mod/lesson/edit.php', array('id'=>$id)));
|
||||
$PAGE->navbar->add(get_string('editingquestionpage', 'lesson', get_string($mform->qtypestring, 'lesson')));
|
||||
} else {
|
||||
@@ -72,12 +74,12 @@ if ($edit) {
|
||||
// IT SHOULD ALWAYS CALL require_sesskey();
|
||||
$mform->construction_override($pageid, $lesson);
|
||||
|
||||
$defaultpage = new stdClass;
|
||||
$defaultpage->id = $cm->id;
|
||||
$defaultpage->pageid = $pageid;
|
||||
$defaultpage->qtype = $qtype;
|
||||
$defaultpage->contentsformat = FORMAT_HTML;
|
||||
$mform->set_data($defaultpage);
|
||||
$data = new stdClass;
|
||||
$data->id = $cm->id;
|
||||
$data->pageid = $pageid;
|
||||
$data->qtype = $qtype;
|
||||
$data = file_prepare_standard_editor($data, 'contents', $editoroptions, null);
|
||||
$mform->set_data($data);
|
||||
$PAGE->navbar->add(get_string('addanewpage', 'lesson'), $PAGE->url);
|
||||
if ($qtype !== 'unknown') {
|
||||
$PAGE->navbar->add(get_string($mform->qtypestring, 'lesson'));
|
||||
|
||||
@@ -191,7 +191,7 @@ switch ($mode) {
|
||||
|
||||
// Set rest of the message values
|
||||
$currentpage = $lesson->load_page($attempt->pageid);
|
||||
$a->question = format_text($currentpage->contents, FORMAT_MOODLE, $options);
|
||||
$a->question = format_text($currentpage->contents, $currentpage->contentsformat, $options);
|
||||
$a->response = s($essayinfo->answer);
|
||||
$a->comment = s($essayinfo->response);
|
||||
|
||||
|
||||
+23
-39
@@ -2150,9 +2150,9 @@ abstract class lesson_page extends lesson_base {
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
$options->para = true;
|
||||
$result->feedback = $OUTPUT->box(format_text($this->properties->contents, FORMAT_MOODLE, $options), 'generalbox boxaligncenter');
|
||||
$result->feedback .= '<div class="correctanswer generalbox"><em>'.get_string("youranswer", "lesson").'</em> : '.format_text($result->studentanswer, FORMAT_MOODLE, $options);
|
||||
$result->feedback .= $OUTPUT->box(format_text($result->response, FORMAT_MOODLE, $options), $class);
|
||||
$result->feedback = $OUTPUT->box(format_text($this->properties->contents, $this->properties->contentsformat, $options), 'generalbox boxaligncenter');
|
||||
$result->feedback .= '<div class="correctanswer generalbox"><em>'.get_string("youranswer", "lesson").'</em> : '.$result->studentanswer; // already in clean html
|
||||
$result->feedback .= $OUTPUT->box($result->response, $class); // already conerted to HTML
|
||||
echo "</div>";
|
||||
}
|
||||
}
|
||||
@@ -2262,10 +2262,12 @@ abstract class lesson_page extends lesson_base {
|
||||
$this->answers[$i]->pageid = $this->id;
|
||||
$this->answers[$i]->timecreated = $this->timecreated;
|
||||
}
|
||||
if (!empty($properties->answer[$i])) {
|
||||
$this->answers[$i]->answer = format_text($properties->answer[$i], FORMAT_PLAIN);
|
||||
if (isset($properties->response[$i])) {
|
||||
$this->answers[$i]->response = format_text($properties->response[$i], FORMAT_PLAIN);
|
||||
if (!empty($properties->answer_editor[$i])) {
|
||||
$this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
|
||||
$this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
|
||||
if (isset($properties->response_editor[$i])) {
|
||||
$this->answers[$i]->response = $properties->response_editor[$i]['text'];
|
||||
$this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
|
||||
}
|
||||
if (isset($properties->jumpto[$i])) {
|
||||
$this->answers[$i]->jumpto = $properties->jumpto[$i];
|
||||
@@ -2348,10 +2350,12 @@ abstract class lesson_page extends lesson_base {
|
||||
|
||||
for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
|
||||
$answer = clone($newanswer);
|
||||
if (!empty($properties->answer[$i])) {
|
||||
$answer->answer = format_text($properties->answer[$i], FORMAT_PLAIN);
|
||||
if (isset($properties->response[$i])) {
|
||||
$answer->response = format_text($properties->response[$i], FORMAT_PLAIN);
|
||||
if (!empty($properties->answer_editor[$i])) {
|
||||
$answer->answer = $properties->answer_editor[$i]['text'];
|
||||
$answer->answerformat = $properties->answer_editor[$i]['format'];
|
||||
if (isset($properties->response_editor[$i])) {
|
||||
$answer->response = $properties->response_editor[$i]['text'];
|
||||
$answer->responseformat = $properties->response_editor[$i]['format'];
|
||||
}
|
||||
if (isset($properties->jumpto[$i])) {
|
||||
$answer->jumpto = $properties->jumpto[$i];
|
||||
@@ -2432,8 +2436,8 @@ abstract class lesson_page extends lesson_base {
|
||||
if (count($this->answers)>0) {
|
||||
$count = 0;
|
||||
foreach ($this->answers as $answer) {
|
||||
$properties->{'answer['.$count.']'} = $answer->answer;
|
||||
$properties->{'response['.$count.']'} = $answer->response;
|
||||
$properties->{'answer_editor['.$count.']'} = array('text'=>$answer->answer, 'format'=>$answer->answerformat);
|
||||
$properties->{'response_editor['.$count.']'} = array('text'=>$answer->response, 'format'=>$answer->responseformat);
|
||||
$properties->{'jumpto['.$count.']'} = $answer->jumpto;
|
||||
$properties->{'score['.$count.']'} = $answer->score;
|
||||
$count++;
|
||||
@@ -2912,18 +2916,6 @@ abstract class lesson_add_page_form_base extends moodleform {
|
||||
*/
|
||||
public function custom_definition() {}
|
||||
|
||||
/**
|
||||
* Sets the data for the form... but modifies if first for the editor then
|
||||
* calls the parent method
|
||||
*
|
||||
* @param stdClass $data An object containing properties to set
|
||||
* @param int $pageid
|
||||
*/
|
||||
public final function set_data($data, $context=null, $pageid=null) {
|
||||
$data = file_prepare_standard_editor($data, 'contents', $this->editoroptions, $context, 'mod_lesson', 'page_contents', $pageid);
|
||||
parent::set_data($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this is a standard page or a special page
|
||||
* @return bool
|
||||
@@ -3012,30 +3004,22 @@ abstract class lesson_add_page_form_base extends moodleform {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function: Adds a textarea element
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $count The count of the element to add
|
||||
* @param string|null $label
|
||||
*/
|
||||
protected final function add_textarea($name, $count, $label) {
|
||||
$this->_form->addElement('textarea', $name.'['.$count.']', $label, array('rows'=>5, 'cols'=>70, 'width'=>630, 'height'=>300));
|
||||
}
|
||||
/**
|
||||
* Convenience function: Adds an answer textarea
|
||||
* Convenience function: Adds an answer editor
|
||||
*
|
||||
* @param int $count The count of the element to add
|
||||
*/
|
||||
protected final function add_answer($count) {
|
||||
$this->add_textarea('answer', $count, get_string('answer', 'lesson'));
|
||||
$this->_form->addElement('editor', 'answer_editor['.$count.']', get_string('answer', 'lesson'), null, array('noclean'=>true));
|
||||
$this->_form->setDefault('answer_editor['.$count.']', array('text'=>'', 'format'=>FORMAT_MOODLE));
|
||||
}
|
||||
/**
|
||||
* Convenience function: Adds an response textarea
|
||||
* Convenience function: Adds an response editor
|
||||
*
|
||||
* @param int $count The count of the element to add
|
||||
*/
|
||||
protected final function add_response($count) {
|
||||
$this->add_textarea('response', $count, get_string('response', 'lesson'));
|
||||
$this->_form->addElement('editor', 'response_editor['.$count.']', get_string('response', 'lesson'), null, array('noclean'=>true));
|
||||
$this->_form->setDefault('response_editor['.$count.']', array('text'=>'', 'format'=>FORMAT_MOODLE));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -174,7 +174,7 @@ class lesson_page_type_branchtable extends lesson_page {
|
||||
foreach ($answers as $answer) {
|
||||
$cells = array();
|
||||
$cells[] = "<span class=\"label\">".get_string("branch", "lesson")." $i<span>: ";
|
||||
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->answer, $answer->answerformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
|
||||
$cells = array();
|
||||
|
||||
@@ -102,10 +102,12 @@ class lesson_page_type_matching extends lesson_page {
|
||||
$this->lesson->maxanswers = $this->lesson->maxanswers + 2;
|
||||
for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
|
||||
$answer = clone($newanswer);
|
||||
if (!empty($properties->answer[$i])) {
|
||||
$answer->answer = format_text($properties->answer[$i], FORMAT_PLAIN);
|
||||
if (isset($properties->response[$i])) {
|
||||
$answer->response = format_text($properties->response[$i], FORMAT_PLAIN);
|
||||
if (!empty($properties->answer_editor[$i])) {
|
||||
$answer->answer = $properties->answer_editor[$i]['text'];
|
||||
$answer->answerformat = $properties->answer_editor[$i]['format'];
|
||||
if (isset($properties->response_editor[$i])) {
|
||||
$answer->response = $properties->response_editor[$i]['text'];
|
||||
$answer->responseformat = $properties->response_editor[$i]['format'];
|
||||
}
|
||||
if (isset($properties->jumpto[$i])) {
|
||||
$answer->jumpto = $properties->jumpto[$i];
|
||||
@@ -128,6 +130,11 @@ class lesson_page_type_matching extends lesson_page {
|
||||
|
||||
public function check_answer() {
|
||||
global $CFG;
|
||||
|
||||
$formattextdefoptions = new object();
|
||||
$formattextdefoptions->noclean = true;
|
||||
$formattextdefoptions->para = false;
|
||||
|
||||
$result = parent::check_answer();
|
||||
|
||||
$mform = $this->make_answer_form();
|
||||
@@ -176,7 +183,7 @@ class lesson_page_type_matching extends lesson_page {
|
||||
$userresponse[] = $answer->id;
|
||||
}
|
||||
if ((int)$answer->id === (int)$key) {
|
||||
$result->studentanswer .= '<br />'.$answer->answer.' = '.$value;
|
||||
$result->studentanswer .= '<br />'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,7 +192,7 @@ class lesson_page_type_matching extends lesson_page {
|
||||
if ($ncorrect == count($answers)-2) { // dont count correct/wrong responses in the total.
|
||||
foreach ($answers as $answer) {
|
||||
if ($answer->response == NULL && $answer->answer != NULL) {
|
||||
$result->response = $answer->answer;
|
||||
$result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -201,7 +208,7 @@ class lesson_page_type_matching extends lesson_page {
|
||||
foreach ($answers as $answer) {
|
||||
if ($answer->response == NULL && $answer->answer != NULL) {
|
||||
if ($t == 1) {
|
||||
$result->response = $answer->answer;
|
||||
$result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
|
||||
break;
|
||||
}
|
||||
$t++;
|
||||
@@ -238,7 +245,7 @@ class lesson_page_type_matching extends lesson_page {
|
||||
} else {
|
||||
$cells[] = "<span class=\"label\">".get_string("wrongresponse", "lesson").'</span>';
|
||||
}
|
||||
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->answer, $answer->answerformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
}
|
||||
$n++;
|
||||
@@ -255,12 +262,12 @@ class lesson_page_type_matching extends lesson_page {
|
||||
} else {
|
||||
$cells[] = '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
|
||||
}
|
||||
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->answer, $answer->answerformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
|
||||
$cells = array();
|
||||
$cells[] = '<span class="label">'.get_string("matchesanswer", "lesson")." $i</span>: ";
|
||||
$cells[] = format_text($answer->response, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->response, $answer->responseformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
}
|
||||
|
||||
@@ -311,10 +318,12 @@ class lesson_page_type_matching extends lesson_page {
|
||||
$this->answers[$i]->pageid = $this->id;
|
||||
$this->answers[$i]->timecreated = $this->timecreated;
|
||||
}
|
||||
if (!empty($properties->answer[$i])) {
|
||||
$this->answers[$i]->answer = format_text($properties->answer[$i], FORMAT_PLAIN);
|
||||
if (isset($properties->response[$i])) {
|
||||
$this->answers[$i]->response = format_text($properties->response[$i], FORMAT_PLAIN);
|
||||
if (!empty($properties->answer_editor[$i])) {
|
||||
$this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
|
||||
$this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
|
||||
if (isset($properties->response_editor[$i])) {
|
||||
$this->answers[$i]->response = $properties->response[$i]['text'];
|
||||
$this->answers[$i]->responseformat = $properties->response[$i]['format'];
|
||||
}
|
||||
if (isset($properties->jumpto[$i])) {
|
||||
$this->answers[$i]->jumpto = $properties->jumpto[$i];
|
||||
@@ -495,7 +504,7 @@ class lesson_display_answer_form_matching extends moodleform {
|
||||
foreach ($answers as $answer) {
|
||||
$mform->addElement('html', '<div class="answeroption">');
|
||||
if ($answer->response != NULL) {
|
||||
$mform->addElement('select', 'response['.$answer->id.']', format_text($answer->answer,FORMAT_MOODLE,$options), $responseoptions);
|
||||
$mform->addElement('select', 'response['.$answer->id.']', format_text($answer->answer,$answer->answerformat,$options), $responseoptions);
|
||||
$mform->setType('response['.$answer->id.']', PARAM_TEXT);
|
||||
if (isset($USER->modattempts[$lessonid])) {
|
||||
$mform->setDefault('response['.$answer->id.']', htmlspecialchars(trim($answers[$useranswers[$t]]->response)));
|
||||
|
||||
@@ -209,6 +209,9 @@ class lesson_page_type_multichoice extends lesson_page {
|
||||
}
|
||||
} else {
|
||||
// only one answer allowed
|
||||
$formattextdefoptions = new object();
|
||||
$formattextdefoptions->noclean = true;
|
||||
$formattextdefoptions->para = false;
|
||||
|
||||
if (empty($data->answerid) && !is_int($data->answerid)) {
|
||||
$result->noanswer = true;
|
||||
@@ -229,8 +232,8 @@ class lesson_page_type_multichoice extends lesson_page {
|
||||
}
|
||||
}
|
||||
$result->newpageid = $answer->jumpto;
|
||||
$result->response = trim($answer->response);
|
||||
$result->userresponse = $answer->answer;
|
||||
$result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
|
||||
$result->userresponse = foramt_text($answer->answer, $answer->answerformat, $formattextdefoptions);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -261,12 +264,12 @@ class lesson_page_type_multichoice extends lesson_page {
|
||||
} else {
|
||||
$cells[] = '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
|
||||
}
|
||||
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->answer, $answer->answerformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
|
||||
$cells = array();
|
||||
$cells[] = "<span class=\"label\">".get_string("response", "lesson")." $i</span>";
|
||||
$cells[] = format_text($answer->response, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->response, $answer->responseformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
|
||||
$cells = array();
|
||||
@@ -355,9 +358,9 @@ class lesson_page_type_multichoice extends lesson_page {
|
||||
$data = "<input type=\"checkbox\" readonly=\"readonly\" name=\"answer[$i]\" value=\"0\" disabled=\"disabled\" />";
|
||||
}
|
||||
if (($answer->score > 0 && $this->lesson->custom) || ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto) && !$this->lesson->custom)) {
|
||||
$data = "<div class=highlight>".$data.' '.format_text($answer->answer,FORMAT_MOODLE,$formattextdefoptions)."</div>";
|
||||
$data = "<div class=highlight>".$data.' '.format_text($answer->answer,$answer->answerformat,$formattextdefoptions)."</div>";
|
||||
} else {
|
||||
$data .= format_text($answer->answer,FORMAT_MOODLE,$formattextdefoptions);
|
||||
$data .= format_text($answer->answer,$answer->answerformat,$formattextdefoptions);
|
||||
}
|
||||
} else {
|
||||
if ($useranswer != NULL and $answer->id == $useranswer->answerid) {
|
||||
@@ -386,7 +389,7 @@ class lesson_page_type_multichoice extends lesson_page {
|
||||
if (($answer->score > 0 && $this->lesson->custom) || ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto) && !$this->lesson->custom)) {
|
||||
$data = "<div class=\"highlight\">".$data.' '.format_text($answer->answer,FORMAT_MOODLE,$formattextdefoptions)."</div>";
|
||||
} else {
|
||||
$data .= format_text($answer->answer,FORMAT_MOODLE,$formattextdefoptions);
|
||||
$data .= format_text($answer->answer,$answer->answerformat,$formattextdefoptions);
|
||||
}
|
||||
}
|
||||
if (isset($pagestats[$this->properties->id][$answer->id])) {
|
||||
@@ -450,7 +453,7 @@ class lesson_display_answer_form_multichoice_singleanswer extends moodleform {
|
||||
$i = 0;
|
||||
foreach ($answers as $answer) {
|
||||
$mform->addElement('html', '<div class="answeroption">');
|
||||
$mform->addElement('radio','answerid',null,format_text(trim($answer->answer), FORMAT_MOODLE, $options),$answer->id);
|
||||
$mform->addElement('radio','answerid',null,format_text($answer->answer, $answer->answerformat, $options),$answer->id);
|
||||
$mform->setType('answer'.$i, PARAM_INT);
|
||||
if (isset($USER->modattempts[$lessonid]) && $answer->id == $attempt->answerid) {
|
||||
$mform->setDefault('answerid', true);
|
||||
@@ -488,7 +491,7 @@ class lesson_display_answer_form_multichoice_multianswer extends moodleform {
|
||||
$i = 0;
|
||||
foreach ($answers as $answer) {
|
||||
$mform->addElement('html', '<div class="answeroption">');
|
||||
$mform->addElement('checkbox','answer['.$i.']',null,format_text(trim($answer->answer), FORMAT_MOODLE, $options),$answer->id);
|
||||
$mform->addElement('checkbox','answer['.$i.']',null,format_text($answer->answer, $answer->answerformat, $options),$answer->id);
|
||||
$mform->setType('answer'.$i, PARAM_INT);
|
||||
if (isset($USER->modattempts[$lessonid]) && $answer->id == $attempt->answerid) {
|
||||
$mform->setDefault('answer['.$i.']', true);
|
||||
|
||||
@@ -128,12 +128,12 @@ class lesson_page_type_numerical extends lesson_page {
|
||||
} else {
|
||||
$cells[] = '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
|
||||
}
|
||||
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->answer, $answer->answerformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
|
||||
$cells = array();
|
||||
$cells[] = "<span class=\"label\">".get_string("response", "lesson")." $i</span>";
|
||||
$cells[] = format_text($answer->response, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->response, $answer->responseformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
|
||||
$cells = array();
|
||||
|
||||
@@ -190,12 +190,12 @@ class lesson_page_type_shortanswer extends lesson_page {
|
||||
} else {
|
||||
$cells[] = '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
|
||||
}
|
||||
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->answer, $answer->answerformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
|
||||
$cells = array();
|
||||
$cells[] = "<span class=\"label\">".get_string("response", "lesson")." $i</span>";
|
||||
$cells[] = format_text($answer->response, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->response, $answer->responseformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
|
||||
$cells = array();
|
||||
|
||||
@@ -60,6 +60,10 @@ class lesson_page_type_truefalse extends lesson_page {
|
||||
}
|
||||
public function check_answer() {
|
||||
global $DB, $CFG;
|
||||
$formattextdefoptions = new object();
|
||||
$formattextdefoptions->noclean = true;
|
||||
$formattextdefoptions->para = false;
|
||||
|
||||
$answers = $this->get_answers();
|
||||
shuffle($answers);
|
||||
$params = array('answers'=>$answers, 'lessonid'=>$this->lesson->id, 'contents'=>$this->get_contents());
|
||||
@@ -75,9 +79,7 @@ class lesson_page_type_truefalse extends lesson_page {
|
||||
return $result;
|
||||
}
|
||||
$result->answerid = $answerid;
|
||||
if (!$answer = $DB->get_record("lesson_answers", array("id" => $result->answerid))) {
|
||||
print_error("Continue: answer record not found");
|
||||
}
|
||||
$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;
|
||||
}
|
||||
@@ -89,14 +91,14 @@ class lesson_page_type_truefalse extends lesson_page {
|
||||
}
|
||||
}
|
||||
$result->newpageid = $answer->jumpto;
|
||||
$result->response = trim($answer->response);
|
||||
$result->studentanswer = $result->userresponse = $answer->answer;
|
||||
$result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
|
||||
$result->studentanswer = $result->userresponse = $result->response;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function display_answers(html_table $table) {
|
||||
$answers = $this->get_answers();
|
||||
$options = new stdClass;
|
||||
$options = new object();
|
||||
$options->noclean = true;
|
||||
$options->para = false;
|
||||
$i = 1;
|
||||
@@ -113,12 +115,12 @@ class lesson_page_type_truefalse extends lesson_page {
|
||||
} else {
|
||||
$cells[] = '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
|
||||
}
|
||||
$cells[] = format_text($answer->answer, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->answer, $answer->answerformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
|
||||
$cells = array();
|
||||
$cells[] = "<span class=\"label\">".get_string("response", "lesson")." $i</span>";
|
||||
$cells[] = format_text($answer->response, FORMAT_MOODLE, $options);
|
||||
$cells[] = format_text($answer->response, $answer->responseformat, $options);
|
||||
$table->data[] = new html_table_row($cells);
|
||||
|
||||
$cells = array();
|
||||
@@ -172,8 +174,9 @@ class lesson_page_type_truefalse extends lesson_page {
|
||||
|
||||
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) {
|
||||
$answers = $this->get_answers();
|
||||
$formattextdefoptions = new stdClass;
|
||||
$formattextdefoptions->para = false; //I'll use it widely in this page
|
||||
$formattextdefoptions = new obejct(); //I'll use it widely in this page
|
||||
$formattextdefoptions->para = false;
|
||||
$formattextdefoptions->noclean = true;
|
||||
foreach ($answers as $answer) {
|
||||
if ($this->properties->qoption) {
|
||||
if ($useranswer == NULL) {
|
||||
@@ -192,7 +195,7 @@ class lesson_page_type_truefalse extends lesson_page {
|
||||
$answerdata->response = get_string("thatsthewronganswer", "lesson");
|
||||
}
|
||||
} else {
|
||||
$answerdata->response = $answer->response;
|
||||
$answerdata->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
|
||||
}
|
||||
}
|
||||
if (!isset($answerdata->score)) {
|
||||
@@ -209,9 +212,9 @@ class lesson_page_type_truefalse extends lesson_page {
|
||||
$data = "<input type=\"checkbox\" readonly=\"readonly\" name=\"answer[$i]\" value=\"0\" disabled=\"disabled\" />";
|
||||
}
|
||||
if (($answer->score > 0 && $this->lesson->custom) || ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto) && !$this->lesson->custom)) {
|
||||
$data .= "<div class=highlight>".format_text($answer->answer,FORMAT_MOODLE,$formattextdefoptions)."</div>";
|
||||
$data .= "<div class=highlight>".format_text($answer->answer, $answer->answerformat, $formattextdefoptions)."</div>";
|
||||
} else {
|
||||
$data .= format_text($answer->answer,FORMAT_MOODLE,$formattextdefoptions);
|
||||
$data .= format_text($answer->answer, $answer->answerformat, $formattextdefoptions);
|
||||
}
|
||||
} else {
|
||||
if ($useranswer != NULL and $answer->id == $useranswer->answerid) {
|
||||
@@ -224,7 +227,7 @@ class lesson_page_type_truefalse extends lesson_page {
|
||||
$answerdata->response = get_string("thatsthewronganswer", "lesson");
|
||||
}
|
||||
} else {
|
||||
$answerdata->response = $answer->response;
|
||||
$answerdata->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
|
||||
}
|
||||
if ($this->lesson->custom) {
|
||||
$answerdata->score = get_string("pointsearned", "lesson").": ".$answer->score;
|
||||
@@ -238,9 +241,9 @@ class lesson_page_type_truefalse extends lesson_page {
|
||||
$data = "<input type=\"checkbox\" readonly=\"readonly\" name=\"answer[$i]\" value=\"0\" disabled=\"disabled\" />";
|
||||
}
|
||||
if (($answer->score > 0 && $this->lesson->custom) || ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto) && !$this->lesson->custom)) {
|
||||
$data .= "<div class=\"highlight\">".format_text($answer->answer,FORMAT_MOODLE,$formattextdefoptions)."</div>";
|
||||
$data .= "<div class=\"highlight\">".format_text($answer->answer, $answer->answerformat, $formattextdefoptions)."</div>";
|
||||
} else {
|
||||
$data .= format_text($answer->answer,FORMAT_MOODLE,$formattextdefoptions);
|
||||
$data .= format_text($answer->answer, $answer->answerformat, $formattextdefoptions);
|
||||
}
|
||||
}
|
||||
if (isset($pagestats[$this->properties->id][$answer->id])) {
|
||||
@@ -289,7 +292,7 @@ class lesson_display_answer_form_truefalse extends moodleform {
|
||||
|
||||
$mform->addElement('header', 'pageheader', $OUTPUT->box($contents, 'contents'));
|
||||
|
||||
$options = new stdClass;
|
||||
$options = new object();
|
||||
$options->para = false;
|
||||
$options->noclean = true;
|
||||
|
||||
@@ -302,7 +305,7 @@ class lesson_display_answer_form_truefalse extends moodleform {
|
||||
$i = 0;
|
||||
foreach ($answers as $answer) {
|
||||
$mform->addElement('html', '<div class="answeroption">');
|
||||
$mform->addElement('radio','answerid',null,format_text(trim($answer->answer), FORMAT_MOODLE, $options),$answer->id);
|
||||
$mform->addElement('radio', 'answerid', null, format_text($answer->answer, $answer->answerformat, $options), $answer->id);
|
||||
$mform->setType('answerid', PARAM_INT);
|
||||
if (isset($USER->modattempts[$lessonid]) && $answer->id == $attempt->answerid) {
|
||||
$mform->setDefault('answerid', true);
|
||||
|
||||
@@ -281,7 +281,7 @@ class mod_lesson_renderer extends plugin_renderer_base {
|
||||
$cell = new html_table_cell();
|
||||
$cell->colspan = 2;
|
||||
$cell->style = 'text-align:center';
|
||||
$cell->text = format_text($page->contents, FORMAT_MOODLE, $options);
|
||||
$cell->text = format_text($page->contents, $page->contentsformat, $options);
|
||||
$pagetable->data[] = new html_table_row(array($cell));
|
||||
|
||||
$cell = new html_table_cell();
|
||||
|
||||
@@ -428,7 +428,7 @@ if ($action == 'reportoverview') {
|
||||
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
$answerpage->contents = format_text($page->contents, FORMAT_MOODLE, $options);
|
||||
$answerpage->contents = format_text($page->contents, $page->contentsformat, $options);
|
||||
|
||||
$answerpage->qtype = $qtypes[$page->qtype].$page->option_description_string();
|
||||
$answerpage->grayout = $page->grayout;
|
||||
@@ -552,7 +552,7 @@ if ($action == 'reportoverview') {
|
||||
$table->data[] = $modified;
|
||||
}
|
||||
if ($page->answerdata->response != NULL) {
|
||||
$table->data[] = array($fontstart.get_string("response", "lesson").": <br />".$fontend.$fontstart2.format_text($page->answerdata->response,FORMAT_MOODLE,$formattextdefoptions).$fontend2, " ");
|
||||
$table->data[] = array($fontstart.get_string("response", "lesson").": <br />".$fontend.$fontstart2.format_text($page->answerdata->response,$page->answerdata->responseformat,$formattextdefoptions).$fontend2, " ");
|
||||
}
|
||||
$table->data[] = array($page->answerdata->score, " ");
|
||||
} else {
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
|
||||
**/
|
||||
|
||||
$module->version = 2009120801; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->requires = 2008072401; // Requires this Moodle version
|
||||
$module->version = 2010072003; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->requires = 2010071800; // Requires this Moodle version
|
||||
$module->cron = 0; // Period for cron to check this module (secs)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user