Permalink
Browse files

Revert "MDL-32870 mod_lesson: added support for files to question ans…

…wers and responses"

This reverts commit d92f768.
  • Loading branch information...
danpoltawski committed Oct 2, 2014
1 parent 4540343 commit be6779d0c4dde7ffbf6caf9429e5f7045ab59580
@@ -190,8 +190,6 @@ protected function define_structure() {
// Annotate the file areas in user by the lesson module.
$lesson->annotate_files('mod_lesson', 'mediafile', null);
$page->annotate_files('mod_lesson', 'page_contents', 'id');
$answer->annotate_files('mod_lesson', 'page_answers', 'id');
$answer->annotate_files('mod_lesson', 'page_responses', 'id');
// Prepare and return the structure we have just created for the lesson module.
return $this->prepare_activity_structure($lesson);
@@ -55,7 +55,6 @@ static public function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('lesson_pages', array('contents'), 'lesson_page');
$contents[] = new restore_decode_content('lesson_answers', array('answer', 'response'), 'lesson_answer');
return $contents;
}
@@ -105,7 +105,7 @@ protected function process_lesson_answer($data) {
// Set a dummy mapping to get the old ID so that it can be used by get_old_parentid when
// processing attempts. It will be corrected in after_execute
$this->set_mapping('lesson_answer', $data->id, 0, true); // Has related fileareas.
$this->set_mapping('lesson_answer', $data->id, 0);
// Answers need to be processed in order, so we store them in an
// instance variable and insert them in the after_execute stage
@@ -186,7 +186,7 @@ protected function after_execute() {
ksort($this->answers);
foreach ($this->answers as $answer) {
$newitemid = $DB->insert_record('lesson_answers', $answer);
$this->set_mapping('lesson_answer', $answer->id, $newitemid, true);
$this->set_mapping('lesson_answer', $answer->id, $newitemid);
// Update the lesson attempts to use the newly created answerid
$DB->set_field('lesson_attempts', 'answerid', $newitemid, array(
@@ -199,8 +199,6 @@ protected function after_execute() {
$this->add_related_files('mod_lesson', 'mediafile', null);
// Add lesson page files, by lesson_page itemname
$this->add_related_files('mod_lesson', 'page_contents', 'lesson_page');
$this->add_related_files('mod_lesson', 'page_answers', 'lesson_answer');
$this->add_related_files('mod_lesson', 'page_responses', 'lesson_answer');
// Remap all the restored prevpageid and nextpageid now that we have all the pages and their mappings
$rs = $DB->get_recordset('lesson_pages', array('lessonid' => $this->task->get_activityid()),
View
@@ -85,31 +85,6 @@
$data->id = $cm->id;
$editoroptions['context'] = $context;
$data = file_prepare_standard_editor($data, 'contents', $editoroptions, $context, 'mod_lesson', 'page_contents', $editpage->id);
$answerscount = 0;
$answers = $editpage->get_answers();
foreach ($answers as $answer) {
$answereditor = 'answer_editor['.$answerscount.']';
if (is_array($data->$answereditor)) {
$answerdata = $data->$answereditor;
$answerdraftid = file_get_submitted_draft_itemid($answereditor);
$answertext = file_prepare_draft_area($answerdraftid, $PAGE->cm->context->id,
'mod_lesson', 'page_answers', $answer->id, $editoroptions, $answerdata['text']);
$data->$answereditor = array('text' => $answertext, 'format' => $answerdata['format'], 'itemid' => $answerdraftid);
}
$responseeditor = 'response_editor['.$answerscount.']';
if (is_array($data->$responseeditor)) {
$responsedata = $data->$responseeditor;
$responsedraftid = file_get_submitted_draft_itemid($responseeditor);
$responsetext = file_prepare_draft_area($responsedraftid, $PAGE->cm->context->id,
'mod_lesson', 'page_responses', $answer->id, $editoroptions, $responsedata['text']);
$data->$responseeditor = array('text' => $responsetext, 'format' => $responsedata['format'],
'itemid' => $responsedraftid);
}
$answerscount++;
}
$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')));
@@ -336,9 +336,7 @@
$string['page-mod-lesson-x'] = 'Any lesson page';
$string['page-mod-lesson-view'] = 'View or preview lesson page';
$string['page-mod-lesson-edit'] = 'Edit lesson page';
$string['pageanswers'] = 'Page answers';
$string['pagecontents'] = 'Page contents';
$string['pageresponses'] = 'Page responses';
$string['pages'] = 'Pages';
$string['pagetitle'] = 'Page title';
$string['password'] = 'Password';
View
@@ -865,13 +865,6 @@ function lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownl
}
$fullpath = "/$context->id/mod_lesson/$filearea/$pageid/".implode('/', $args);
} else if ($filearea === 'page_answers' || $filearea === 'page_responses') {
$itemid = (int)array_shift($args);
if (!$pageanswers = $DB->get_record('lesson_answers', array('id' => $itemid))) {
return false;
}
$fullpath = "/$context->id/mod_lesson/$filearea/$itemid/".implode('/', $args);
} else if ($filearea === 'mediafile') {
if (count($args) > 1) {
// Remove the itemid when it appears to be part of the arguments. If there is only one argument
@@ -904,8 +897,6 @@ function lesson_get_file_areas() {
$areas = array();
$areas['page_contents'] = get_string('pagecontents', 'mod_lesson');
$areas['mediafile'] = get_string('mediafile', 'mod_lesson');
$areas['page_answers'] = get_string('pageanswers', 'mod_lesson');
$areas['page_responses'] = get_string('pageresponses', 'mod_lesson');
return $areas;
}
View
@@ -790,19 +790,8 @@ public function custom_definition() {}
if ($label === null) {
$label = get_string('answer', 'lesson');
}
if ($this->qtype != 'multichoice' && $this->qtype != 'matching') {
$this->_form->addElement('editor', 'answer_editor['.$count.']', $label,
array('rows' => '4', 'columns' => '80'), array('noclean' => true));
$this->_form->setDefault('answer_editor['.$count.']', array('text' => '', 'format' => FORMAT_MOODLE));
} else {
$this->_form->addElement('editor', 'answer_editor['.$count.']', $label,
array('rows' => '4', 'columns' => '80'),
array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->_customdata['maxbytes']));
$this->_form->setType('answer_editor['.$count.']', PARAM_RAW);
$this->_form->setDefault('answer_editor['.$count.']', array('text' => '', 'format' => FORMAT_HTML));
}
$this->_form->addElement('editor', 'answer_editor['.$count.']', $label, array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
$this->_form->setDefault('answer_editor['.$count.']', array('text'=>'', 'format'=>FORMAT_MOODLE));
if ($required) {
$this->_form->addRule('answer_editor['.$count.']', get_string('required'), 'required', null, 'client');
}
@@ -819,12 +808,8 @@ public function custom_definition() {}
if ($label === null) {
$label = get_string('response', 'lesson');
}
$this->_form->addElement('editor', 'response_editor['.$count.']', $label,
array('rows' => '4', 'columns' => '80'),
array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->_customdata['maxbytes']));
$this->_form->setType('response_editor['.$count.']', PARAM_RAW);
$this->_form->setDefault('response_editor['.$count.']', array('text' => '', 'format' => FORMAT_HTML));
$this->_form->addElement('editor', 'response_editor['.$count.']', $label, array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
$this->_form->setDefault('response_editor['.$count.']', array('text'=>'', 'format'=>FORMAT_MOODLE));
if ($required) {
$this->_form->addRule('response_editor['.$count.']', get_string('required'), 'required', null, 'client');
}
@@ -1876,8 +1861,6 @@ public function properties() {
$context = context_module::instance($cm->id);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'mod_lesson', 'page_contents', $this->properties->id);
$fs->delete_area_files($context->id, 'mod_lesson', 'page_answers', $this->properties->id);
$fs->delete_area_files($context->id, 'mod_lesson', 'page_responses', $this->properties->id);
// repair the hole in the linkage
if (!$this->properties->prevpageid && !$this->properties->nextpageid) {
@@ -1975,7 +1958,7 @@ public function properties() {
* @return stdClass Returns the result of the attempt
*/
final public function record_attempt($context) {
global $DB, $USER, $OUTPUT, $PAGE;
global $DB, $USER, $OUTPUT;
/**
* This should be overridden by each page type to actually check the response
@@ -2081,9 +2064,6 @@ public function properties() {
$options->noclean = true;
$options->para = true;
$options->overflowdiv = true;
$result->response = file_rewrite_pluginfile_urls($result->response, 'pluginfile.php', $context->id,
'mod_lesson', 'page_responses', $result->answerid);
$result->feedback = $OUTPUT->box(format_text($this->get_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
@@ -2166,51 +2146,6 @@ public function callback_on_view($canmanage) {
return true;
}
/**
* save editor answers files and update answer record
*
* @param object $context
* @param int $maxbytes
* @param object $answer
* @param object $answereditor
* @param object $responseeditor
*/
public function save_answers_files($context, $maxbytes, &$answer, $answereditor = '', $responseeditor = '') {
global $DB;
if (isset($answereditor['itemid'])) {
$answer->answer = file_save_draft_area_files($answereditor['itemid'],
$context->id, 'mod_lesson', 'page_answers', $answer->id,
array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes),
$answer->answer, null);
$DB->set_field('lesson_answers', 'answer', $answer->answer, array('id' => $answer->id));
}
if (isset($responseeditor['itemid'])) {
$answer->response = file_save_draft_area_files($responseeditor['itemid'],
$context->id, 'mod_lesson', 'page_responses', $answer->id,
array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes),
$answer->response, null);
$DB->set_field('lesson_answers', 'response', $answer->response, array('id' => $answer->id));
}
}
/**
* Rewrite urls in answer and response of a question answer
*
* @param object $answer
* @return object answer with rewritten urls
*/
public static function rewrite_answers_urls($answer) {
global $PAGE;
$context = context_module::instance($PAGE->cm->id);
$answer->answer = file_rewrite_pluginfile_urls($answer->answer, 'pluginfile.php', $context->id,
'mod_lesson', 'page_answers', $answer->id);
$answer->response = file_rewrite_pluginfile_urls($answer->response, 'pluginfile.php', $context->id,
'mod_lesson', 'page_responses', $answer->id);
return $answer;
}
/**
* Updates a lesson page and its answers within the database
*
@@ -2266,10 +2201,6 @@ public function update($properties, $context = null, $maxbytes = null) {
$DB->update_record("lesson_answers", $this->answers[$i]->properties());
}
// Save files in answers and responses.
$this->save_answers_files($context, $maxbytes, $this->answers[$i],
$properties->answer_editor[$i], $properties->response_editor[$i]);
} else if (isset($this->answers[$i]->id)) {
$DB->delete_records('lesson_answers', array('id'=>$this->answers[$i]->id));
unset($this->answers[$i]);
@@ -2329,16 +2260,13 @@ public function is_unanswered($nretakes) {
* @return array
*/
public function create_answers($properties) {
global $DB, $PAGE;
global $DB;
// now add the answers
$newanswer = new stdClass;
$newanswer->lessonid = $this->lesson->id;
$newanswer->pageid = $this->properties->id;
$newanswer->timecreated = $this->properties->timecreated;
$cm = get_coursemodule_from_instance('lesson', $this->lesson->id, $this->lesson->course);
$context = context_module::instance($cm->id);
$answers = array();
for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
@@ -2361,13 +2289,6 @@ public function create_answers($properties) {
$answer->score = $properties->score[$i];
}
$answer->id = $DB->insert_record("lesson_answers", $answer);
if (isset($properties->response_editor[$i])) {
$this->save_answers_files($context, $PAGE->course->maxbytes, $answer,
$properties->answer_editor[$i], $properties->response_editor[$i]);
} else {
$this->save_answers_files($context, $PAGE->course->maxbytes, $answer,
$properties->answer_editor[$i]);
}
$answers[$answer->id] = new lesson_page_answer($answer);
} else {
break;
@@ -96,16 +96,13 @@ protected function make_answer_form($attempt=null) {
}
public function create_answers($properties) {
global $DB, $PAGE;
global $DB;
// now add the answers
$newanswer = new stdClass;
$newanswer->lessonid = $this->lesson->id;
$newanswer->pageid = $this->properties->id;
$newanswer->timecreated = $this->properties->timecreated;
$cm = get_coursemodule_from_instance('lesson', $this->lesson->id, $this->lesson->course);
$context = context_module::instance($cm->id);
$answers = array();
// need to add two to offset correct response and wrong response
@@ -130,8 +127,6 @@ public function create_answers($properties) {
if (isset($answer->answer) && $answer->answer != '') {
$answer->id = $DB->insert_record("lesson_answers", $answer);
$this->save_answers_files($context, $PAGE->course->maxbytes,
$answer, $properties->answer_editor[$i]);
$answers[$answer->id] = new lesson_page_answer($answer);
} else if ($i < 2) {
$answer->id = $DB->insert_record("lesson_answers", $answer);
@@ -164,9 +159,6 @@ public function check_answer() {
$response = $data->response;
$getanswers = $this->get_answers();
foreach ($getanswers as $key => $answer) {
$getanswers[$key] = parent::rewrite_answers_urls($answer);
}
$correct = array_shift($getanswers);
$wrong = array_shift($getanswers);
@@ -341,19 +333,13 @@ public function update($properties, $context = null, $maxbytes = null) {
} else {
$DB->update_record("lesson_answers", $this->answers[$i]->properties());
}
// Save files in answers and responses.
$this->save_answers_files($context, $maxbytes, $this->answers[$i],
$properties->answer_editor[$i], $properties->response_editor[$i]);
} else if ($i < 2) {
if (!isset($this->answers[$i]->id)) {
$this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]);
} else {
$DB->update_record("lesson_answers", $this->answers[$i]->properties());
}
// Save files in answers and responses.
$this->save_answers_files( $context, $maxbytes, $this->answers[$i],
$properties->answer_editor[$i], $properties->response_editor[$i]);
} else if (isset($this->answers[$i]->id)) {
$DB->delete_records('lesson_answers', array('id'=>$this->answers[$i]->id));
unset($this->answers[$i]);
@@ -474,21 +460,12 @@ class lesson_add_page_form_matching extends lesson_add_page_form_base {
public function custom_definition() {
$this->_form->addElement('header', 'correctresponse', get_string('correctresponse', 'lesson'));
$this->_form->addElement('editor', 'answer_editor[0]', get_string('correctresponse', 'lesson'),
array('rows' => '4', 'columns' => '80'),
array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->_customdata['maxbytes']));
$this->_form->setType('answer_editor[0]', PARAM_RAW);
$this->_form->setDefault('answer_editor[0]', array('text' => '', 'format' => FORMAT_HTML));
$this->_form->addElement('editor', 'answer_editor[0]', get_string('correctresponse', 'lesson'), array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
$this->add_jumpto(0, get_string('correctanswerjump','lesson'), LESSON_NEXTPAGE);
$this->add_score(0, get_string("correctanswerscore", "lesson"), 1);
$this->_form->addElement('header', 'wrongresponse', get_string('wrongresponse', 'lesson'));
$this->_form->addElement('editor', 'answer_editor[1]', get_string('wrongresponse', 'lesson'),
array('rows' => '4', 'columns' => '80'),
array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->_customdata['maxbytes']));
$this->_form->setType('answer_editor[1]', PARAM_RAW);
$this->_form->setDefault('answer_editor[1]', array('text' => '', 'format' => FORMAT_HTML));
$this->_form->addElement('editor', 'answer_editor[1]', get_string('wrongresponse', 'lesson'), array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
$this->add_jumpto(1, get_string('wronganswerjump','lesson'), LESSON_THISPAGE);
$this->add_score(1, get_string("wronganswerscore", "lesson"), 0);
@@ -511,7 +488,7 @@ public function custom_definition() {
class lesson_display_answer_form_matching extends moodleform {
public function definition() {
global $USER, $OUTPUT, $PAGE;
global $USER, $OUTPUT;
$mform = $this->_form;
$answers = $this->_customdata['answers'];
$useranswers = $this->_customdata['useranswers'];
@@ -552,9 +529,6 @@ public function definition() {
// Temporary fixed until MDL-38885 gets integrated
$mform->setType('response', PARAM_TEXT);
}
$context = context_module::instance($PAGE->cm->id);
$answer->answer = file_rewrite_pluginfile_urls($answer->answer, 'pluginfile.php', $context->id,
'mod_lesson', 'page_answers', $answer->id);
$mform->addElement('select', $responseid, format_text($answer->answer,$answer->answerformat,$options), $responseoptions, $disabled);
$mform->setType($responseid, PARAM_TEXT);
if ($hasattempt) {
Oops, something went wrong.

0 comments on commit be6779d

Please sign in to comment.