diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 8d50af0f459..0d089adbaf1 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -323,7 +323,7 @@ function lesson_grade($lesson, $ntries, $userid = 0) { $attempt = end($attempts); // If essay question, handle it, otherwise add to score if ($page->requires_manual_grading()) { - $useranswerobj = unserialize($attempt->useranswer); + $useranswerobj = unserialize_object($attempt->useranswer); if (isset($useranswerobj->score)) { $earned += $useranswerobj->score; } @@ -2919,11 +2919,11 @@ class lesson extends lesson_base { if ($dependentlesson = $DB->get_record('lesson', array('id' => $this->properties->dependency))) { // Lesson exists, so we can proceed. - $conditions = unserialize($this->properties->conditions); + $conditions = unserialize_object($this->properties->conditions); // Assume false for all. $errors = array(); // Check for the timespent condition. - if ($conditions->timespent) { + if (!empty($conditions->timespent)) { $timespent = false; if ($attempttimes = $DB->get_records('lesson_timer', array("userid" => $USER->id, "lessonid" => $dependentlesson->id))) { // Go through all the times and test to see if any of them satisfy the condition. @@ -2939,7 +2939,7 @@ class lesson extends lesson_base { } } // Check for the gradebetterthan condition. - if ($conditions->gradebetterthan) { + if (!empty($conditions->gradebetterthan)) { $gradebetterthan = false; if ($studentgrades = $DB->get_records('lesson_grades', array("userid" => $USER->id, "lessonid" => $dependentlesson->id))) { // Go through all the grades and test to see if any of them satisfy the condition. @@ -2954,7 +2954,7 @@ class lesson extends lesson_base { } } // Check for the completed condition. - if ($conditions->completed) { + if (!empty($conditions->completed)) { if (!$DB->count_records('lesson_grades', array('userid' => $USER->id, 'lessonid' => $dependentlesson->id))) { $errors[] = get_string('completederror', 'lesson'); } diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index be2cca26a53..e2a4e404e06 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -358,10 +358,10 @@ class mod_lesson_mod_form extends moodleform_mod { **/ public function data_preprocessing(&$defaultvalues) { if (isset($defaultvalues['conditions'])) { - $conditions = unserialize($defaultvalues['conditions']); - $defaultvalues['timespent'] = $conditions->timespent; - $defaultvalues['completed'] = $conditions->completed; - $defaultvalues['gradebetterthan'] = $conditions->gradebetterthan; + $conditions = unserialize_object($defaultvalues['conditions']); + $defaultvalues['timespent'] = $conditions->timespent ?? 0; + $defaultvalues['completed'] = !empty($conditions->completed); + $defaultvalues['gradebetterthan'] = $conditions->gradebetterthan ?? 0; } // Set up the completion checkbox which is not part of standard data. diff --git a/mod/lesson/pagetypes/essay.php b/mod/lesson/pagetypes/essay.php index 41b3d6fada8..0cde105b50c 100644 --- a/mod/lesson/pagetypes/essay.php +++ b/mod/lesson/pagetypes/essay.php @@ -56,9 +56,9 @@ class lesson_page_type_essay extends lesson_page { * @return object */ static public function extract_useranswer($useranswer) { - $essayinfo = unserialize($useranswer); + $essayinfo = unserialize_object($useranswer); if (!isset($essayinfo->responseformat)) { - $essayinfo->response = text_to_html($essayinfo->response, false, false); + $essayinfo->response = text_to_html($essayinfo->response ?? '', false, false); $essayinfo->responseformat = FORMAT_HTML; } return $essayinfo; @@ -150,7 +150,7 @@ class lesson_page_type_essay extends lesson_page { $editoroptions['context'], 'mod_lesson', 'essay_answers', $attempt->id); // Update the student response to have the modified link. - $useranswer = unserialize($attempt->useranswer); + $useranswer = unserialize_object($attempt->useranswer); $useranswer->answer = $formdata->answer; $useranswer->answerformat = $formdata->answerformat; $attempt->useranswer = serialize($useranswer);