Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-29230 lesson_module: fixed question's answer to have 0 value.

  • Loading branch information...
commit ebc788d13e1ffbf9f37384cc90df9c72f95b8bb0 1 parent 51e1e3d
@rwijaya rwijaya authored
View
6 mod/lesson/locallib.php
@@ -2154,7 +2154,8 @@ public function update($properties, $context = null, $maxbytes = null) {
$this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
}
- if (!empty($this->answers[$i]->answer)) {
+ // we don't need to check for isset here because properties called it's own isset method.
+ if ($this->answers[$i]->answer != '') {
if (isset($properties->jumpto[$i])) {
$this->answers[$i]->jumpto = $properties->jumpto[$i];
}
@@ -2246,8 +2247,7 @@ public function create_answers($properties) {
$answer->response = $properties->response_editor[$i]['text'];
$answer->responseformat = $properties->response_editor[$i]['format'];
}
-
- if (!empty($answer->answer)) {
+ if (isset($answer->answer) && $answer->answer != '') {
if (isset($properties->jumpto[$i])) {
$answer->jumpto = $properties->jumpto[$i];
}
View
5 mod/lesson/pagetypes/matching.php
@@ -120,7 +120,7 @@ public function create_answers($properties) {
$answer->responseformat = $properties->response_editor[$i]['format'];
}
- if (!empty($answer->answer)) {
+ if (isset($answer->answer) && $answer->answer != '') {
if (isset($properties->jumpto[$i])) {
$answer->jumpto = $properties->jumpto[$i];
}
@@ -320,7 +320,8 @@ public function update($properties) {
$this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
}
- if (!empty($this->answers[$i]->answer)) {
+ // we don't need to check for isset here because properties called it's own isset method.
+ if ($this->answers[$i]->answer != '') {
if (isset($properties->jumpto[$i])) {
$this->answers[$i]->jumpto = $properties->jumpto[$i];
}
View
57 mod/lesson/pagetypes/truefalse.php
@@ -144,6 +144,63 @@ public function display_answers(html_table $table) {
}
return $table;
}
+
+ /**
+ * Updates the page and its answers
+ *
+ * @global moodle_database $DB
+ * @global moodle_page $PAGE
+ * @param stdClass $properties
+ * @return bool
+ */
+ public function update($properties) {
+ global $DB, $PAGE;
+ $answers = $this->get_answers();
+ $properties->id = $this->properties->id;
+ $properties->lessonid = $this->lesson->id;
+ $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), get_context_instance(CONTEXT_MODULE, $PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id);
+ $DB->update_record("lesson_pages", $properties);
+
+ // need to reset offset for correct and wrong responses
+ $this->lesson->maxanswers = 2;
+ for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
+ if (!array_key_exists($i, $this->answers)) {
+ $this->answers[$i] = new stdClass;
+ $this->answers[$i]->lessonid = $this->lesson->id;
+ $this->answers[$i]->pageid = $this->id;
+ $this->answers[$i]->timecreated = $this->timecreated;
+ }
+
+ if (!empty($properties->answer_editor[$i]) && is_array($properties->answer_editor[$i])) {
+ $this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
+ $this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
+ }
+ if (!empty($properties->response_editor[$i]) && is_array($properties->response_editor[$i])) {
+ $this->answers[$i]->response = $properties->response_editor[$i]['text'];
+ $this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
+ }
+
+ // we don't need to check for isset here because properties called it's own isset method.
+ if ($this->answers[$i]->answer != '') {
+ if (isset($properties->jumpto[$i])) {
+ $this->answers[$i]->jumpto = $properties->jumpto[$i];
+ }
+ if ($this->lesson->custom && isset($properties->score[$i])) {
+ $this->answers[$i]->score = $properties->score[$i];
+ }
+ 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());
+ }
+ } else if (isset($this->answers[$i]->id)) {
+ $DB->delete_records('lesson_answers', array('id'=>$this->answers[$i]->id));
+ unset($this->answers[$i]);
+ }
+ }
+ return true;
+ }
+
public function stats(array &$pagestats, $tries) {
if(count($tries) > $this->lesson->maxattempts) { // if there are more tries than the max that is allowed, grab the last "legal" attempt
$temp = $tries[$this->lesson->maxattempts - 1];
Please sign in to comment.
Something went wrong with that request. Please try again.