From a2bf666a0ca3ed18117ef8a29bf924b621cb8984 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Wed, 31 Mar 2021 00:41:55 +1100 Subject: [PATCH] MDL-71144 mod_lesson: Deprecate lesson_get_completion_state() --- mod/lesson/deprecatedlib.php | 73 ++++++++++++++++++++++++++++++++++++ mod/lesson/lib.php | 47 +---------------------- 2 files changed, 74 insertions(+), 46 deletions(-) create mode 100644 mod/lesson/deprecatedlib.php diff --git a/mod/lesson/deprecatedlib.php b/mod/lesson/deprecatedlib.php new file mode 100644 index 00000000000..e7255972c7c --- /dev/null +++ b/mod/lesson/deprecatedlib.php @@ -0,0 +1,73 @@ +. + +/** + * List of deprecated mod_lesson functions. + * + * @package mod_lesson + * @copyright 2021 Shamim Rezaie + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Obtains the automatic completion state for this lesson based on any conditions + * in lesson settings. + * + * @deprecated since Moodle 3.11 + * @todo MDL-71196 Final deprecation in Moodle 4.3 + * @see \mod_lesson\completion\custom_completion + * @param stdClass $course Course + * @param cm_info|stdClass $cm course-module + * @param int $userid User ID + * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) + * @return bool True if completed, false if not, $type if conditions not set. + */ +function lesson_get_completion_state($course, $cm, $userid, $type) { + global $DB; + + // No need to call debugging here. Deprecation debugging notice already being called in \completion_info::internal_get_state(). + + // Get lesson details. + $lesson = $DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST); + + $result = $type; // Default return value. + // If completion option is enabled, evaluate it and return true/false. + if ($lesson->completionendreached) { + $value = $DB->record_exists('lesson_timer', array('lessonid' => $lesson->id, 'userid' => $userid, 'completed' => 1)); + if ($type == COMPLETION_AND) { + $result = $result && $value; + } else { + $result = $result || $value; + } + } + if ($lesson->completiontimespent != 0) { + $duration = $DB->get_field_sql( + "SELECT SUM(lessontime - starttime) + FROM {lesson_timer} + WHERE lessonid = :lessonid + AND userid = :userid", + array('userid' => $userid, 'lessonid' => $lesson->id)); + if (!$duration) { + $duration = 0; + } + if ($type == COMPLETION_AND) { + $result = $result && ($lesson->completiontimespent < $duration); + } else { + $result = $result || ($lesson->completiontimespent < $duration); + } + } + return $result; +} diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 45444fcc958..071b4eadc4d 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -29,6 +29,7 @@ defined('MOODLE_INTERNAL') || die(); define('LESSON_EVENT_TYPE_OPEN', 'open'); define('LESSON_EVENT_TYPE_CLOSE', 'close'); +require_once(__DIR__ . '/deprecatedlib.php'); /* Do not include any libraries here! */ /** @@ -997,52 +998,6 @@ function lesson_supports($feature) { } } -/** - * Obtains the automatic completion state for this lesson based on any conditions - * in lesson settings. - * - * @param object $course Course - * @param object $cm course-module - * @param int $userid User ID - * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) - * @return bool True if completed, false if not, $type if conditions not set. - */ -function lesson_get_completion_state($course, $cm, $userid, $type) { - global $CFG, $DB; - - // Get lesson details. - $lesson = $DB->get_record('lesson', array('id' => $cm->instance), '*', - MUST_EXIST); - - $result = $type; // Default return value. - // If completion option is enabled, evaluate it and return true/false. - if ($lesson->completionendreached) { - $value = $DB->record_exists('lesson_timer', array( - 'lessonid' => $lesson->id, 'userid' => $userid, 'completed' => 1)); - if ($type == COMPLETION_AND) { - $result = $result && $value; - } else { - $result = $result || $value; - } - } - if ($lesson->completiontimespent != 0) { - $duration = $DB->get_field_sql( - "SELECT SUM(lessontime - starttime) - FROM {lesson_timer} - WHERE lessonid = :lessonid - AND userid = :userid", - array('userid' => $userid, 'lessonid' => $lesson->id)); - if (!$duration) { - $duration = 0; - } - if ($type == COMPLETION_AND) { - $result = $result && ($lesson->completiontimespent < $duration); - } else { - $result = $result || ($lesson->completiontimespent < $duration); - } - } - return $result; -} /** * This function extends the settings navigation block for the site. *