Merge branch 'MDL-71144-master' of git://github.com/rezaies/moodle

This commit is contained in:
Sara Arjona 2021-04-23 13:16:01 +02:00
commit 12f64a02c9
24 changed files with 897 additions and 517 deletions

View File

@ -19,6 +19,9 @@ information provided here is intended especially for developers.
- Given the manual completion button of "<Activity name>" overridden by "<User>" is displayed as "<Status>"
- overridden_activity_completion_condition_displayed_as
- Given the "<Completion condition>" completion condition of "<Activity name>" overridden by "<User>" is displayed as "<Status>"
* *_get_completion_state() callback functions have been deprecated and should no longer be used. Plugins that define custom
completion rules must implement the mod_[modname]\completion\custom_completion class that extends the
\core_completion\activity_custom_completion base class.
=== 3.7 ===
* External function core_completion_external::get_activities_completion_status new returns the following additional field:

View File

@ -562,10 +562,10 @@ class completion_info {
* if a forum provides options for marking itself 'completed' once a user makes
* N posts, this function should be called every time a user makes a new post.
* [After the post has been saved to the database]. When calling, you do not
* need to pass in the new completion state. Instead this function carries out
* completion calculation by checking grades and viewed state itself, and
* calling the involved module via modulename_get_completion_state() to check
* module-specific conditions.
* need to pass in the new completion state. Instead this function carries out completion
* calculation by checking grades and viewed state itself, and calling the involved module
* via mod_{modulename}\\completion\\custom_completion::get_overall_completion_state() to
* check module-specific conditions.
*
* @param stdClass|cm_info $cm Course-module
* @param int $possibleresult Expected completion result. If the event that
@ -701,12 +701,16 @@ class completion_info {
}
} else {
// Fallback to the get_completion_state callback.
$cmcompletionclass = "mod_{$cminfo->modname}\\completion\\custom_completion";
$function = $cminfo->modname . '_get_completion_state';
if (!function_exists($function)) {
$this->internal_systemerror("Module {$cminfo->modname} claims to support
FEATURE_COMPLETION_HAS_RULES but does not have required
{$cminfo->modname}_get_completion_state function");
$this->internal_systemerror("Module {$cminfo->modname} claims to support FEATURE_COMPLETION_HAS_RULES " .
"but does not implement the custom completion class $cmcompletionclass which extends " .
"\core_completion\activity_custom_completion.");
}
debugging("*_get_completion_state() callback functions such as $function have been deprecated and should no " .
"longer be used. Please implement the custom completion class $cmcompletionclass which extends " .
"\core_completion\activity_custom_completion.", DEBUG_DEVELOPER);
if (!$function($this->course, $cminfo, $userid, COMPLETION_AND)) {
return COMPLETION_INCOMPLETE;
}

View File

@ -0,0 +1,59 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of deprecated mod_assign functions.
*
* @package mod_assign
* @copyright 2021 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Obtains the automatic completion state for this module based on any conditions
* in assign settings.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_assign\completion\custom_completion
* @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 assign_get_completion_state($course, $cm, $userid, $type) {
global $CFG;
// No need to call debugging here. Deprecation debugging notice already being called in \completion_info::internal_get_state().
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$assign = new assign(null, $cm, $course);
// If completion option is enabled, evaluate it and return true/false.
if ($assign->get_instance()->completionsubmit) {
if ($assign->get_instance()->teamsubmission) {
$submission = $assign->get_group_submission($userid, 0, false);
} else {
$submission = $assign->get_user_submission($userid, false);
}
return $submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED;
} else {
// Completion option is not enabled so just return $type.
return $type;
}
}

View File

@ -25,6 +25,8 @@
*/
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/deprecatedlib.php');
/**
* Adds an assignment instance
*
@ -1293,36 +1295,6 @@ function assign_user_outline($course, $user, $coursemodule, $assignment) {
return $result;
}
/**
* Obtains the automatic completion state for this module based on any conditions
* in assign 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 assign_get_completion_state($course, $cm, $userid, $type) {
global $CFG, $DB;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$assign = new assign(null, $cm, $course);
// If completion option is enabled, evaluate it and return true/false.
if ($assign->get_instance()->completionsubmit) {
if ($assign->get_instance()->teamsubmission) {
$submission = $assign->get_group_submission($userid, 0, false);
} else {
$submission = $assign->get_user_submission($userid, false);
}
return $submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED;
} else {
// Completion option is not enabled so just return $type.
return $type;
}
}
/**
* Serves intro attachment files.
*

View File

@ -0,0 +1,55 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of deprecated mod_choice functions.
*
* @package mod_choice
* @copyright 2021 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Obtains the automatic completion state for this choice based on any conditions
* in forum settings.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_choice\completion\custom_completion
* @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 choice_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 choice details.
$choice = $DB->get_record('choice', array('id' => $cm->instance), '*',
MUST_EXIST);
// If completion option is enabled, evaluate it and return true/false.
if ($choice->completionsubmit) {
return $DB->record_exists('choice_answers', array(
'choiceid' => $choice->id, 'userid' => $userid));
} else {
// Completion option is not enabled so just return $type.
return $type;
}
}

View File

@ -62,6 +62,8 @@ global $CHOICE_DISPLAY;
$CHOICE_DISPLAY = array (CHOICE_DISPLAY_HORIZONTAL => get_string('displayhorizontal', 'choice'),
CHOICE_DISPLAY_VERTICAL => get_string('displayvertical','choice'));
require_once(__DIR__ . '/deprecatedlib.php');
/// Standard functions /////////////////////////////////////////////////////////
/**
@ -887,33 +889,6 @@ function choice_extend_settings_navigation(settings_navigation $settings, naviga
}
}
/**
* Obtains the automatic completion state for this choice based on any conditions
* in forum 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 choice_get_completion_state($course, $cm, $userid, $type) {
global $CFG,$DB;
// Get choice details
$choice = $DB->get_record('choice', array('id'=>$cm->instance), '*',
MUST_EXIST);
// If completion option is enabled, evaluate it and return true/false
if($choice->completionsubmit) {
return $DB->record_exists('choice_answers', array(
'choiceid'=>$choice->id, 'userid'=>$userid));
} else {
// Completion option is not enabled so just return $type
return $type;
}
}
/**
* Return a list of page types
* @param string $pagetype current page type

View File

@ -0,0 +1,63 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of deprecated mod_data functions.
*
* @package mod_data
* @copyright 2021 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Obtains the automatic completion state for this database item based on any conditions
* on its settings. The call for this is in completion lib where the modulename is appended
* to the function name. This is why there are unused parameters.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_data\completion\custom_completion
* @since Moodle 3.3
* @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 data_get_completion_state($course, $cm, $userid, $type) {
global $DB, $PAGE;
// No need to call debugging here. Deprecation debugging notice already being called in \completion_info::internal_get_state().
$result = $type; // Default return value
// Get data details.
if (isset($PAGE->cm->id) && $PAGE->cm->id == $cm->id) {
$data = $PAGE->activityrecord;
} else {
$data = $DB->get_record('data', array('id' => $cm->instance), '*', MUST_EXIST);
}
// If completion option is enabled, evaluate it and return true/false.
if ($data->completionentries) {
$numentries = data_numentries($data, $userid);
// Check the number of entries required against the number of entries already made.
if ($numentries >= $data->completionentries) {
$result = true;
} else {
$result = false;
}
}
return $result;
}

View File

@ -35,6 +35,9 @@ define ('DATA_TIMEMODIFIED', -4);
define ('DATA_TAGS', -5);
define ('DATA_CAP_EXPORT', 'mod/data:viewalluserpresets');
// Users having assigned the default role "Non-editing teacher" can export database records
// Using the mod/data capability "viewalluserpresets" existing in Moodle 1.9.x.
// In Moodle >= 2, new roles may be introduced and used instead.
define('DATA_PRESET_COMPONENT', 'mod_data');
define('DATA_PRESET_FILEAREA', 'site_presets');
@ -43,9 +46,7 @@ define('DATA_PRESET_CONTEXT', SYSCONTEXTID);
define('DATA_EVENT_TYPE_OPEN', 'open');
define('DATA_EVENT_TYPE_CLOSE', 'close');
// Users having assigned the default role "Non-editing teacher" can export database records
// Using the mod/data capability "viewalluserpresets" existing in Moodle 1.9.x.
// In Moodle >= 2, new roles may be introduced and used instead.
require_once(__DIR__ . '/deprecatedlib.php');
/**
* @package mod_data
@ -4469,40 +4470,6 @@ function data_update_completion_state($data, $course, $cm) {
}
}
/**
* Obtains the automatic completion state for this database item based on any conditions
* on its settings. The call for this is in completion lib where the modulename is appended
* to the function name. This is why there are unused parameters.
*
* @since Moodle 3.3
* @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 data_get_completion_state($course, $cm, $userid, $type) {
global $DB, $PAGE;
$result = $type; // Default return value
// Get data details.
if (isset($PAGE->cm->id) && $PAGE->cm->id == $cm->id) {
$data = $PAGE->activityrecord;
} else {
$data = $DB->get_record('data', array('id' => $cm->instance), '*', MUST_EXIST);
}
// If completion option is enabled, evaluate it and return true/false.
if ($data->completionentries) {
$numentries = data_numentries($data, $userid);
// Check the number of entries required against the number of entries already made.
if ($numentries >= $data->completionentries) {
$result = true;
} else {
$result = false;
}
}
return $result;
}
/**
* Mark the activity completed (if required) and trigger the course_module_viewed event.
*

View File

@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of deprecated mod_feedback functions.
*
* @package mod_feedback
* @copyright 2021 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Obtains the automatic completion state for this feedback based on the condition
* in feedback settings.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_feedback\completion\custom_completion
* @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 feedback_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 feedback details.
$feedback = $DB->get_record('feedback', array('id' => $cm->instance), '*', MUST_EXIST);
// If completion option is enabled, evaluate it and return true/false.
if ($feedback->completionsubmit) {
$params = array('userid' => $userid, 'feedback' => $feedback->id);
return $DB->record_exists('feedback_completed', $params);
} else {
// Completion option is not enabled so just return $type.
return $type;
}
}

View File

@ -42,6 +42,8 @@ define('FEEDBACK_DEFAULT_PAGE_COUNT', 20);
define('FEEDBACK_EVENT_TYPE_OPEN', 'open');
define('FEEDBACK_EVENT_TYPE_CLOSE', 'close');
require_once(__DIR__ . '/deprecatedlib.php');
/**
* @uses FEATURE_GROUPS
* @uses FEATURE_GROUPINGS
@ -511,32 +513,6 @@ function feedback_print_recent_mod_activity($activity, $courseid, $detail, $modn
return;
}
/**
* Obtains the automatic completion state for this feedback based on the condition
* in feedback 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 feedback_get_completion_state($course, $cm, $userid, $type) {
global $CFG, $DB;
// Get feedback details
$feedback = $DB->get_record('feedback', array('id'=>$cm->instance), '*', MUST_EXIST);
// If completion option is enabled, evaluate it and return true/false
if ($feedback->completionsubmit) {
$params = array('userid'=>$userid, 'feedback'=>$feedback->id);
return $DB->record_exists('feedback_completed', $params);
} else {
// Completion option is not enabled so just return $type
return $type;
}
}
/**
* Print a detailed representation of what a user has done with
* a given particular instance of this module, for user activity reports.

View File

@ -1689,3 +1689,71 @@ function forum_get_user_grades($forum, $userid = 0) {
$rm = new rating_manager();
return $rm->get_user_grades($ratingoptions);
}
/**
* Obtains the automatic completion state for this forum based on any conditions
* in forum settings.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_forum\completion\custom_completion
* @global object
* @global object
* @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. (If no conditions, then return
* value depends on comparison type)
*/
function forum_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 forum details.
if (!($forum = $DB->get_record('forum', array('id' => $cm->instance)))) {
throw new Exception("Can't find forum {$cm->instance}");
}
$result = $type; // Default return value.
$postcountparams = array('userid' => $userid, 'forumid' => $forum->id);
$postcountsql = "
SELECT
COUNT(1)
FROM
{forum_posts} fp
INNER JOIN {forum_discussions} fd ON fp.discussion=fd.id
WHERE
fp.userid=:userid AND fd.forum=:forumid";
if ($forum->completiondiscussions) {
$value = $forum->completiondiscussions <=
$DB->count_records('forum_discussions', array('forum' => $forum->id, 'userid' => $userid));
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
if ($forum->completionreplies) {
$value = $forum->completionreplies <=
$DB->get_field_sql($postcountsql . ' AND fp.parent<>0', $postcountparams);
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
if ($forum->completionposts) {
$value = $forum->completionposts <= $DB->get_field_sql($postcountsql, $postcountparams);
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
return $result;
}

View File

@ -373,69 +373,6 @@ function forum_supports($feature) {
}
}
/**
* Obtains the automatic completion state for this forum based on any conditions
* in forum settings.
*
* @global object
* @global object
* @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. (If no conditions, then return
* value depends on comparison type)
*/
function forum_get_completion_state($course,$cm,$userid,$type) {
global $CFG,$DB;
// Get forum details
if (!($forum=$DB->get_record('forum',array('id'=>$cm->instance)))) {
throw new Exception("Can't find forum {$cm->instance}");
}
$result=$type; // Default return value
$postcountparams=array('userid'=>$userid,'forumid'=>$forum->id);
$postcountsql="
SELECT
COUNT(1)
FROM
{forum_posts} fp
INNER JOIN {forum_discussions} fd ON fp.discussion=fd.id
WHERE
fp.userid=:userid AND fd.forum=:forumid";
if ($forum->completiondiscussions) {
$value = $forum->completiondiscussions <=
$DB->count_records('forum_discussions',array('forum'=>$forum->id,'userid'=>$userid));
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
if ($forum->completionreplies) {
$value = $forum->completionreplies <=
$DB->get_field_sql( $postcountsql.' AND fp.parent<>0',$postcountparams);
if ($type==COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
if ($forum->completionposts) {
$value = $forum->completionposts <= $DB->get_field_sql($postcountsql,$postcountparams);
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
return $result;
}
/**
* Create a message-id string to use in the custom headers of forum notification emails
*

View File

@ -0,0 +1,61 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of deprecated mod_glossary functions.
*
* @package mod_glossary
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Obtains the automatic completion state for this glossary based on any conditions
* in glossary settings.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_glossary\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. (If no conditions, then return value depends on comparison type)
*/
function glossary_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 glossary details.
if (!($glossary = $DB->get_record('glossary', array('id' => $cm->instance)))) {
throw new Exception("Can't find glossary {$cm->instance}");
}
$result = $type; // Default return value.
if ($glossary->completionentries) {
$value = $glossary->completionentries <=
$DB->count_records('glossary_entries', array('glossaryid' => $glossary->id, 'userid' => $userid, 'approved' => 1));
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
return $result;
}

View File

@ -49,6 +49,8 @@ define('GLOSSARY_CONTINUOUS', 'continuous');
define('GLOSSARY_DICTIONARY', 'dictionary');
define('GLOSSARY_FULLWITHOUTAUTHOR', 'fullwithoutauthor');
require_once(__DIR__ . '/deprecatedlib.php');
/// STANDARD FUNCTIONS ///////////////////////////////////////////////////////////
/**
* @global object
@ -3095,42 +3097,6 @@ function glossary_supports($feature) {
}
}
/**
* Obtains the automatic completion state for this glossary based on any conditions
* in glossary settings.
*
* @global object
* @global object
* @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. (If no conditions, then return
* value depends on comparison type)
*/
function glossary_get_completion_state($course,$cm,$userid,$type) {
global $CFG, $DB;
// Get glossary details
if (!($glossary=$DB->get_record('glossary',array('id'=>$cm->instance)))) {
throw new Exception("Can't find glossary {$cm->instance}");
}
$result=$type; // Default return value
if ($glossary->completionentries) {
$value = $glossary->completionentries <=
$DB->count_records('glossary_entries',array('glossaryid'=>$glossary->id, 'userid'=>$userid, 'approved'=>1));
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
return $result;
}
function glossary_extend_navigation($navigation, $course, $module, $cm) {
global $CFG, $DB;

View File

@ -0,0 +1,73 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of deprecated mod_lesson functions.
*
* @package mod_lesson
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @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;
}

View File

@ -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.
*

View File

@ -18,7 +18,12 @@ declare(strict_types=1);
namespace mod_quiz\completion;
use context_module;
use core_completion\activity_custom_completion;
use grade_grade;
use grade_item;
use quiz;
use quiz_access_manager;
/**
* Activity custom completion subclass for the quiz activity.
@ -32,6 +37,75 @@ use core_completion\activity_custom_completion;
*/
class custom_completion extends activity_custom_completion {
/**
* Check passing grade (or no attempts left) requirement for completion.
*
* @return bool True if the passing grade (or no attempts left) requirement is disabled or met.
*/
protected function check_passing_grade_or_all_attempts(): bool {
global $CFG;
require_once($CFG->libdir . '/gradelib.php');
$completionpassorattempts = $this->cm->customdata['customcompletionrules']['completionpassorattemptsexhausted'];
if (empty($completionpassorattempts['completionpass'])) {
return true;
}
// Check for passing grade.
$item = grade_item::fetch([
'courseid' => $this->cm->get_course()->id,
'itemtype' => 'mod',
'itemmodule' => 'quiz',
'iteminstance' => $this->cm->instance,
'outcomeid' => null
]);
if ($item) {
$grades = grade_grade::fetch_users_grades($item, [$this->userid], false);
if (!empty($grades[$this->userid]) && $grades[$this->userid]->is_passed($item)) {
return true;
}
}
// If a passing grade is required and exhausting all available attempts is not accepted for completion,
// then this quiz is not complete.
if (empty($completionpassorattempts['completionattemptsexhausted'])) {
return false;
}
// Check if all attempts are used up.
$attempts = quiz_get_user_attempts($this->cm->instance, $this->userid, 'finished', true);
if (!$attempts) {
return false;
}
$lastfinishedattempt = end($attempts);
$context = context_module::instance($this->cm->id);
$quizobj = quiz::create($this->cm->instance, $this->userid);
$accessmanager = new quiz_access_manager(
$quizobj,
time(),
has_capability('mod/quiz:ignoretimelimits', $context, $this->userid, false)
);
return $accessmanager->is_finished(count($attempts), $lastfinishedattempt);
}
/**
* Check minimum attempts requirement for completion.
*
* @return bool True if minimum attempts requirement is disabled or met.
*/
protected function check_min_attempts() {
$minattempts = $this->cm->customdata['customcompletionrules']['completionminattempts'];
if (!$minattempts) {
return true;
}
// Check if the user has done enough attempts.
$attempts = quiz_get_user_attempts($this->cm->instance, $this->userid, 'finished', true);
return $minattempts <= count($attempts);
}
/**
* Fetches the completion state for a given completion rule.
*
@ -39,23 +113,14 @@ class custom_completion extends activity_custom_completion {
* @return int The completion state.
*/
public function get_state(string $rule): int {
global $DB;
$this->validate_rule($rule);
$quiz = $DB->get_record('quiz', ['id' => $this->cm->instance], '*', MUST_EXIST);
switch ($rule) {
case 'completionpassorattemptsexhausted':
$status = quiz_completion_check_passing_grade_or_all_attempts(
$this->cm->get_course(),
$this->cm,
$this->userid,
$quiz
);
$status = static::check_passing_grade_or_all_attempts();
break;
case 'completionminattempts':
$status = quiz_completion_check_min_attempts($this->userid, $quiz);
$status = static::check_min_attempts();
break;
}

134
mod/quiz/deprecatedlib.php Normal file
View File

@ -0,0 +1,134 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of deprecated mod_quiz functions.
*
* @package mod_quiz
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Internal function used in quiz_get_completion_state. Check passing grade (or no attempts left) requirement for completion.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_quiz\completion\custom_completion
* @param stdClass $course
* @param cm_info|stdClass $cm
* @param int $userid
* @param stdClass $quiz
* @return bool True if the passing grade (or no attempts left) requirement is disabled or met.
* @throws coding_exception
*/
function quiz_completion_check_passing_grade_or_all_attempts($course, $cm, $userid, $quiz) {
global $CFG;
debugging('quiz_completion_check_passing_grade_or_all_attempts has been deprecated.', DEBUG_DEVELOPER);
if (!$quiz->completionpass) {
return true;
}
// Check for passing grade.
require_once($CFG->libdir . '/gradelib.php');
$item = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod',
'itemmodule' => 'quiz', 'iteminstance' => $cm->instance, 'outcomeid' => null));
if ($item) {
$grades = grade_grade::fetch_users_grades($item, array($userid), false);
if (!empty($grades[$userid]) && $grades[$userid]->is_passed($item)) {
return true;
}
}
// If a passing grade is required and exhausting all available attempts is not accepted for completion,
// then this quiz is not complete.
if (!$quiz->completionattemptsexhausted) {
return false;
}
// Check if all attempts are used up.
$attempts = quiz_get_user_attempts($quiz->id, $userid, 'finished', true);
if (!$attempts) {
return false;
}
$lastfinishedattempt = end($attempts);
$context = context_module::instance($cm->id);
$quizobj = quiz::create($quiz->id, $userid);
$accessmanager = new quiz_access_manager($quizobj, time(),
has_capability('mod/quiz:ignoretimelimits', $context, $userid, false));
return $accessmanager->is_finished(count($attempts), $lastfinishedattempt);
}
/**
* Internal function used in quiz_get_completion_state. Check minimum attempts requirement for completion.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_quiz\completion\custom_completion
* @param int $userid
* @param stdClass $quiz
* @return bool True if minimum attempts requirement is disabled or met.
*/
function quiz_completion_check_min_attempts($userid, $quiz) {
debugging('quiz_completion_check_min_attempts has been deprecated.', DEBUG_DEVELOPER);
if (empty($quiz->completionminattempts)) {
return true;
}
// Check if the user has done enough attempts.
$attempts = quiz_get_user_attempts($quiz->id, $userid, 'finished', true);
return $quiz->completionminattempts <= count($attempts);
}
/**
* Obtains the automatic completion state for this quiz on any conditions
* in quiz settings, such as if all attempts are used or a certain grade is achieved.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_quiz\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. (If no conditions, then return
* value depends on comparison type)
*/
function quiz_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().
$quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST);
if (!$quiz->completionattemptsexhausted && !$quiz->completionpass && !$quiz->completionminattempts) {
return $type;
}
if (!quiz_completion_check_passing_grade_or_all_attempts($course, $cm, $userid, $quiz)) {
return false;
}
if (!quiz_completion_check_min_attempts($userid, $quiz)) {
return false;
}
return true;
}

View File

@ -69,6 +69,8 @@ define('QUIZ_NAVMETHOD_SEQ', 'sequential');
define('QUIZ_EVENT_TYPE_OPEN', 'open');
define('QUIZ_EVENT_TYPE_CLOSE', 'close');
require_once(__DIR__ . '/deprecatedlib.php');
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
@ -1893,102 +1895,6 @@ function quiz_get_navigation_options() {
);
}
/**
* Internal function used in quiz_get_completion_state. Check passing grade (or no attempts left) requirement for completion.
*
* @param object $course
* @param object $cm
* @param int $userid
* @param object $quiz
* @return bool True if the passing grade (or no attempts left) requirement is disabled or met.
* @throws coding_exception
*/
function quiz_completion_check_passing_grade_or_all_attempts($course, $cm, $userid, $quiz) {
global $CFG;
if (!$quiz->completionpass) {
return true;
}
// Check for passing grade.
require_once($CFG->libdir . '/gradelib.php');
$item = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod',
'itemmodule' => 'quiz', 'iteminstance' => $cm->instance, 'outcomeid' => null));
if ($item) {
$grades = grade_grade::fetch_users_grades($item, array($userid), false);
if (!empty($grades[$userid]) && $grades[$userid]->is_passed($item)) {
return true;
}
}
// If a passing grade is required and exhausting all available attempts is not accepted for completion,
// then this quiz is not complete.
if (!$quiz->completionattemptsexhausted) {
return false;
}
// Check if all attempts are used up.
$attempts = quiz_get_user_attempts($quiz->id, $userid, 'finished', true);
if (!$attempts) {
return false;
}
$lastfinishedattempt = end($attempts);
$context = context_module::instance($cm->id);
$quizobj = quiz::create($quiz->id, $userid);
$accessmanager = new quiz_access_manager($quizobj, time(),
has_capability('mod/quiz:ignoretimelimits', $context, $userid, false));
return $accessmanager->is_finished(count($attempts), $lastfinishedattempt);
}
/**
* Internal function used in quiz_get_completion_state. Check minimum attempts requirement for completion.
*
* @param int $userid
* @param object $quiz
* @return bool True if minimum attempts requirement is disabled or met.
* @throws coding_exception
*/
function quiz_completion_check_min_attempts($userid, $quiz) {
if (empty($quiz->completionminattempts)) {
return true;
}
// Check if the user has done enough attempts.
$attempts = quiz_get_user_attempts($quiz->id, $userid, 'finished', true);
return $quiz->completionminattempts <= count($attempts);
}
/**
* Obtains the automatic completion state for this quiz on any conditions
* in quiz settings, such as if all attempts are used or a certain grade is achieved.
*
* @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. (If no conditions, then return
* value depends on comparison type)
*/
function quiz_get_completion_state($course, $cm, $userid, $type) {
global $DB;
$quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST);
if (!$quiz->completionattemptsexhausted && !$quiz->completionpass && !$quiz->completionminattempts) {
return $type;
}
if (!quiz_completion_check_passing_grade_or_all_attempts($course, $cm, $userid, $quiz)) {
return false;
}
if (!quiz_completion_check_min_attempts($userid, $quiz)) {
return false;
}
return true;
}
/**
* Check if the module has any update that affects the current user since a given time.
*

View File

@ -253,6 +253,12 @@ class mod_quiz_lib_testcase extends advanced_testcase {
// Check the results.
$this->assertFalse(quiz_get_completion_state($course, $cm, $failstudent->id, 'return'));
$this->assertDebuggingCalledCount(3, [
'quiz_completion_check_passing_grade_or_all_attempts has been deprecated.',
'quiz_completion_check_min_attempts has been deprecated.',
'quiz_completion_check_passing_grade_or_all_attempts has been deprecated.',
]);
}
/**
@ -306,6 +312,14 @@ class mod_quiz_lib_testcase extends advanced_testcase {
// Check the results. Quiz is completed by $exhauststudent because there are no remaining attempts.
$this->assertTrue(quiz_get_completion_state($course, $cm, $exhauststudent->id, 'return'));
$this->assertDebuggingCalledCount(5, [
'quiz_completion_check_passing_grade_or_all_attempts has been deprecated.',
'quiz_completion_check_min_attempts has been deprecated.',
'quiz_completion_check_passing_grade_or_all_attempts has been deprecated.',
'quiz_completion_check_passing_grade_or_all_attempts has been deprecated.',
'quiz_completion_check_min_attempts has been deprecated.',
]);
}
/**
@ -346,6 +360,13 @@ class mod_quiz_lib_testcase extends advanced_testcase {
// Check the results. Quiz is completed by $student because two attempts were done.
$this->assertTrue(quiz_get_completion_state($course, $cm, $student->id, 'return'));
$this->assertDebuggingCalledCount(4, [
'quiz_completion_check_passing_grade_or_all_attempts has been deprecated.',
'quiz_completion_check_min_attempts has been deprecated.',
'quiz_completion_check_passing_grade_or_all_attempts has been deprecated.',
'quiz_completion_check_min_attempts has been deprecated.',
]);
}
/**
@ -392,6 +413,13 @@ class mod_quiz_lib_testcase extends advanced_testcase {
// Check the results. Quiz is completed by $student because two attempts were done AND a passing grade was obtained.
$this->assertTrue(quiz_get_completion_state($course, $cm, $student->id, 'return'));
$this->assertDebuggingCalledCount(4, [
'quiz_completion_check_passing_grade_or_all_attempts has been deprecated.',
'quiz_completion_check_min_attempts has been deprecated.',
'quiz_completion_check_passing_grade_or_all_attempts has been deprecated.',
'quiz_completion_check_min_attempts has been deprecated.',
]);
}
public function test_quiz_get_user_attempts() {

139
mod/scorm/deprecatedlib.php Normal file
View File

@ -0,0 +1,139 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of deprecated mod_scorm functions.
*
* @package mod_scorm
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Obtains the automatic completion state for this scorm based on any conditions
* in scorm settings.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_scorm\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. (If no conditions, then return
* value depends on comparison type)
*/
function scorm_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().
$result = $type;
// Get scorm.
if (!$scorm = $DB->get_record('scorm', array('id' => $cm->instance))) {
print_error('cannotfindscorm');
}
// Only check for existence of tracks and return false if completionstatusrequired or completionscorerequired
// this means that if only view is required we don't end up with a false state.
if ($scorm->completionstatusrequired !== null || $scorm->completionscorerequired !== null) {
// Get user's tracks data.
$tracks = $DB->get_records_sql(
"
SELECT
id,
scoid,
element,
value
FROM
{scorm_scoes_track}
WHERE
scormid = ?
AND userid = ?
AND element IN
(
'cmi.core.lesson_status',
'cmi.completion_status',
'cmi.success_status',
'cmi.core.score.raw',
'cmi.score.raw'
)
",
array($scorm->id, $userid)
);
if (!$tracks) {
return completion_info::aggregate_completion_states($type, $result, false);
}
}
// Check for status.
if ($scorm->completionstatusrequired !== null) {
// Get status.
$statuses = array_flip(scorm_status_options());
$nstatus = 0;
// Check any track for these values.
$scostatus = array();
foreach ($tracks as $track) {
if (!in_array($track->element, array('cmi.core.lesson_status', 'cmi.completion_status', 'cmi.success_status'))) {
continue;
}
if (array_key_exists($track->value, $statuses)) {
$scostatus[$track->scoid] = true;
$nstatus |= $statuses[$track->value];
}
}
if (!empty($scorm->completionstatusallscos)) {
// Iterate over all scos and make sure each has a lesson_status.
$scos = $DB->get_records('scorm_scoes', array('scorm' => $scorm->id, 'scormtype' => 'sco'));
foreach ($scos as $sco) {
if (empty($scostatus[$sco->id])) {
return completion_info::aggregate_completion_states($type, $result, false);
}
}
return completion_info::aggregate_completion_states($type, $result, true);
} else if ($scorm->completionstatusrequired & $nstatus) {
return completion_info::aggregate_completion_states($type, $result, true);
} else {
return completion_info::aggregate_completion_states($type, $result, false);
}
}
// Check for score.
if ($scorm->completionscorerequired !== null) {
$maxscore = -1;
foreach ($tracks as $track) {
if (!in_array($track->element, array('cmi.core.score.raw', 'cmi.score.raw'))) {
continue;
}
if (strlen($track->value) && floatval($track->value) >= $maxscore) {
$maxscore = floatval($track->value);
}
}
if ($scorm->completionscorerequired <= $maxscore) {
return completion_info::aggregate_completion_states($type, $result, true);
} else {
return completion_info::aggregate_completion_states($type, $result, false);
}
}
return $result;
}

View File

@ -19,6 +19,7 @@
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/** SCORM_TYPE_LOCAL = local */
define('SCORM_TYPE_LOCAL', 'local');
@ -53,6 +54,8 @@ define('SCORM_DISPLAY_ATTEMPTSTATUS_ENTRY', 3);
define('SCORM_EVENT_TYPE_OPEN', 'open');
define('SCORM_EVENT_TYPE_CLOSE', 'close');
require_once(__DIR__ . '/deprecatedlib.php');
/**
* Return an array of status options
*
@ -1146,118 +1149,6 @@ function scorm_version_check($scormversion, $version='') {
return false;
}
/**
* Obtains the automatic completion state for this scorm based on any conditions
* in scorm 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. (If no conditions, then return
* value depends on comparison type)
*/
function scorm_get_completion_state($course, $cm, $userid, $type) {
global $DB;
$result = $type;
// Get scorm.
if (!$scorm = $DB->get_record('scorm', array('id' => $cm->instance))) {
print_error('cannotfindscorm');
}
// Only check for existence of tracks and return false if completionstatusrequired or completionscorerequired
// this means that if only view is required we don't end up with a false state.
if ($scorm->completionstatusrequired !== null ||
$scorm->completionscorerequired !== null) {
// Get user's tracks data.
$tracks = $DB->get_records_sql(
"
SELECT
id,
scoid,
element,
value
FROM
{scorm_scoes_track}
WHERE
scormid = ?
AND userid = ?
AND element IN
(
'cmi.core.lesson_status',
'cmi.completion_status',
'cmi.success_status',
'cmi.core.score.raw',
'cmi.score.raw'
)
",
array($scorm->id, $userid)
);
if (!$tracks) {
return completion_info::aggregate_completion_states($type, $result, false);
}
}
// Check for status.
if ($scorm->completionstatusrequired !== null) {
// Get status.
$statuses = array_flip(scorm_status_options());
$nstatus = 0;
// Check any track for these values.
$scostatus = array();
foreach ($tracks as $track) {
if (!in_array($track->element, array('cmi.core.lesson_status', 'cmi.completion_status', 'cmi.success_status'))) {
continue;
}
if (array_key_exists($track->value, $statuses)) {
$scostatus[$track->scoid] = true;
$nstatus |= $statuses[$track->value];
}
}
if (!empty($scorm->completionstatusallscos)) {
// Iterate over all scos and make sure each has a lesson_status.
$scos = $DB->get_records('scorm_scoes', array('scorm' => $scorm->id, 'scormtype' => 'sco'));
foreach ($scos as $sco) {
if (empty($scostatus[$sco->id])) {
return completion_info::aggregate_completion_states($type, $result, false);
}
}
return completion_info::aggregate_completion_states($type, $result, true);
} else if ($scorm->completionstatusrequired & $nstatus) {
return completion_info::aggregate_completion_states($type, $result, true);
} else {
return completion_info::aggregate_completion_states($type, $result, false);
}
}
// Check for score.
if ($scorm->completionscorerequired !== null) {
$maxscore = -1;
foreach ($tracks as $track) {
if (!in_array($track->element, array('cmi.core.score.raw', 'cmi.score.raw'))) {
continue;
}
if (strlen($track->value) && floatval($track->value) >= $maxscore) {
$maxscore = floatval($track->value);
}
}
if ($scorm->completionscorerequired <= $maxscore) {
return completion_info::aggregate_completion_states($type, $result, true);
} else {
return completion_info::aggregate_completion_states($type, $result, false);
}
}
return $result;
}
/**
* Register the ability to handle drag and drop file uploads
* @return array containing details of the files / types the mod can handle

View File

@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of deprecated mod_survey functions.
*
* @package mod_survey
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Obtains the automatic completion state for this survey based on the condition
* in feedback settings.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_survey\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 survey_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 survey details.
$survey = $DB->get_record('survey', array('id' => $cm->instance), '*', MUST_EXIST);
// If completion option is enabled, evaluate it and return true/false.
if ($survey->completionsubmit) {
$params = array('userid' => $userid, 'survey' => $survey->id);
return $DB->record_exists('survey_answers', $params);
} else {
// Completion option is not enabled so just return $type.
return $type;
}
}

View File

@ -55,6 +55,7 @@ define("SURVEY_COLLES_PREFERRED_ACTUAL", "3");
define("SURVEY_ATTLS", "4");
define("SURVEY_CIQ", "5");
require_once(__DIR__ . '/deprecatedlib.php');
// STANDARD FUNCTIONS ////////////////////////////////////////////////////////
/**
@ -1029,32 +1030,6 @@ function survey_save_answers($survey, $answersrawdata, $course, $context) {
$event->trigger();
}
/**
* Obtains the automatic completion state for this survey based on the condition
* in feedback 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 survey_get_completion_state($course, $cm, $userid, $type) {
global $DB;
// Get survey details.
$survey = $DB->get_record('survey', array('id' => $cm->instance), '*', MUST_EXIST);
// If completion option is enabled, evaluate it and return true/false.
if ($survey->completionsubmit) {
$params = array('userid' => $userid, 'survey' => $survey->id);
return $DB->record_exists('survey_answers', $params);
} else {
// Completion option is not enabled so just return $type.
return $type;
}
}
/**
* Check if the module has any update that affects the current user since a given time.
*