MDL-30995 completion: Fixed up PHPdocs for activity completion
This commit is contained in:
committed by
Ankit Agarwal
parent
23778a4dfa
commit
836375ec8a
+185
-206
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -16,91 +15,135 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains a class used for tracking whether activities have been completed
|
||||
* by students ('completion')
|
||||
* Contains classes, functions and constants used during the tracking
|
||||
* of activity completion for users.
|
||||
*
|
||||
* Completion top-level options (admin setting enablecompletion)
|
||||
*
|
||||
* @package core
|
||||
* @subpackage completion
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core_completion
|
||||
* @category completion
|
||||
* @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();
|
||||
|
||||
/**
|
||||
* Include the required completion libraries
|
||||
*/
|
||||
require_once $CFG->libdir.'/completion/completion_aggregation.php';
|
||||
require_once $CFG->libdir.'/completion/completion_criteria.php';
|
||||
require_once $CFG->libdir.'/completion/completion_completion.php';
|
||||
require_once $CFG->libdir.'/completion/completion_criteria_completion.php';
|
||||
|
||||
|
||||
/** The completion system is enabled in this site/course */
|
||||
/**
|
||||
* The completion system is enabled in this site/course
|
||||
*/
|
||||
define('COMPLETION_ENABLED', 1);
|
||||
/** The completion system is not enabled in this site/course */
|
||||
/**
|
||||
* The completion system is not enabled in this site/course
|
||||
*/
|
||||
define('COMPLETION_DISABLED', 0);
|
||||
|
||||
// Completion tracking options per-activity (course_modules/completion)
|
||||
|
||||
/** Completion tracking is disabled for this activity */
|
||||
/**
|
||||
* Completion tracking is disabled for this activity
|
||||
* This is a completion tracking option per-activity (course_modules/completion)
|
||||
*/
|
||||
define('COMPLETION_TRACKING_NONE', 0);
|
||||
/** Manual completion tracking (user ticks box) is enabled for this activity */
|
||||
|
||||
/**
|
||||
* Manual completion tracking (user ticks box) is enabled for this activity
|
||||
* This is a completion tracking option per-activity (course_modules/completion)
|
||||
*/
|
||||
define('COMPLETION_TRACKING_MANUAL', 1);
|
||||
/** Automatic completion tracking (system ticks box) is enabled for this activity */
|
||||
/**
|
||||
* Automatic completion tracking (system ticks box) is enabled for this activity
|
||||
* This is a completion tracking option per-activity (course_modules/completion)
|
||||
*/
|
||||
define('COMPLETION_TRACKING_AUTOMATIC', 2);
|
||||
|
||||
// Completion state values (course_modules_completion/completionstate)
|
||||
|
||||
/** The user has not completed this activity. */
|
||||
/**
|
||||
* The user has not completed this activity.
|
||||
* This is a completion state value (course_modules_completion/completionstate)
|
||||
*/
|
||||
define('COMPLETION_INCOMPLETE', 0);
|
||||
/** The user has completed this activity. It is not specified whether they have
|
||||
* passed or failed it. */
|
||||
/**
|
||||
* The user has completed this activity. It is not specified whether they have
|
||||
* passed or failed it.
|
||||
* This is a completion state value (course_modules_completion/completionstate)
|
||||
*/
|
||||
define('COMPLETION_COMPLETE', 1);
|
||||
/** The user has completed this activity with a grade above the pass mark. */
|
||||
/**
|
||||
* The user has completed this activity with a grade above the pass mark.
|
||||
* This is a completion state value (course_modules_completion/completionstate)
|
||||
*/
|
||||
define('COMPLETION_COMPLETE_PASS', 2);
|
||||
/** The user has completed this activity but their grade is less than the pass mark */
|
||||
/**
|
||||
* The user has completed this activity but their grade is less than the pass mark
|
||||
* This is a completion state value (course_modules_completion/completionstate)
|
||||
*/
|
||||
define('COMPLETION_COMPLETE_FAIL', 3);
|
||||
|
||||
// Completion effect changes (used only in update_state)
|
||||
|
||||
/** The effect of this change to completion status is unknown. */
|
||||
/**
|
||||
* The effect of this change to completion status is unknown.
|
||||
* A completion effect changes (used only in update_state)
|
||||
*/
|
||||
define('COMPLETION_UNKNOWN', -1);
|
||||
/** The user's grade has changed, so their new state might be
|
||||
* COMPLETION_COMPLETE_PASS or COMPLETION_COMPLETE_FAIL. */
|
||||
// TODO Is this useful?
|
||||
/**
|
||||
* The user's grade has changed, so their new state might be
|
||||
* COMPLETION_COMPLETE_PASS or COMPLETION_COMPLETE_FAIL.
|
||||
* A completion effect changes (used only in update_state)
|
||||
*/
|
||||
define('COMPLETION_GRADECHANGE', -2);
|
||||
|
||||
// Whether view is required to create an activity (course_modules/completionview)
|
||||
|
||||
/** User must view this activity */
|
||||
/**
|
||||
* User must view this activit.
|
||||
* Whether view is required to create an activity (course_modules/completionview)
|
||||
*/
|
||||
define('COMPLETION_VIEW_REQUIRED', 1);
|
||||
/** User does not need to view this activity */
|
||||
/**
|
||||
* User does not need to view this activity
|
||||
* Whether view is required to create an activity (course_modules/completionview)
|
||||
*/
|
||||
define('COMPLETION_VIEW_NOT_REQUIRED', 0);
|
||||
|
||||
// Completion viewed state (course_modules_completion/viewed)
|
||||
|
||||
/** User has viewed this activity */
|
||||
/**
|
||||
* User has viewed this activity.
|
||||
* Completion viewed state (course_modules_completion/viewed)
|
||||
*/
|
||||
define('COMPLETION_VIEWED', 1);
|
||||
/** User has not viewed this activity */
|
||||
/**
|
||||
* User has not viewed this activity.
|
||||
* Completion viewed state (course_modules_completion/viewed)
|
||||
*/
|
||||
define('COMPLETION_NOT_VIEWED', 0);
|
||||
|
||||
// Completion cacheing
|
||||
|
||||
/** Cache expiry time in seconds (10 minutes) */
|
||||
/**
|
||||
* Cache expiry time in seconds (10 minutes)
|
||||
* Completion cacheing
|
||||
*/
|
||||
define('COMPLETION_CACHE_EXPIRY', 10*60);
|
||||
|
||||
// Combining completion condition. This is also the value you should return
|
||||
// if you don't have any applicable conditions. Used for activity completion.
|
||||
/** Completion details should be ORed together and you should return false if
|
||||
none apply */
|
||||
/**
|
||||
* Completion details should be ORed together and you should return false if
|
||||
* none apply.
|
||||
*/
|
||||
define('COMPLETION_OR', false);
|
||||
/** Completion details should be ANDed together and you should return true if
|
||||
none apply */
|
||||
/**
|
||||
* Completion details should be ANDed together and you should return true if
|
||||
* none apply
|
||||
*/
|
||||
define('COMPLETION_AND', true);
|
||||
|
||||
// Course completion criteria aggregation methods
|
||||
define('COMPLETION_AGGREGATION_ALL', 1);
|
||||
define('COMPLETION_AGGREGATION_ANY', 2);
|
||||
/**
|
||||
* Course completion criteria aggregation method.
|
||||
*/
|
||||
define('COMPLETION_AGGREGATION_ALL', 1);
|
||||
/**
|
||||
* Course completion criteria aggregation method.
|
||||
*/
|
||||
define('COMPLETION_AGGREGATION_ANY', 2);
|
||||
|
||||
|
||||
/**
|
||||
@@ -109,48 +152,49 @@ define('COMPLETION_AGGREGATION_ANY', 2);
|
||||
* Does not contain any data, so you can safely construct it multiple times
|
||||
* without causing any problems.
|
||||
*
|
||||
* @package core
|
||||
* @category completion
|
||||
* @copyright 2008 Sam Marshall
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package moodlecore
|
||||
*/
|
||||
class completion_info {
|
||||
|
||||
/**
|
||||
* Course object passed during construction
|
||||
* @access private
|
||||
* @var object
|
||||
* @var stdClass
|
||||
*/
|
||||
private $course;
|
||||
|
||||
/**
|
||||
* Course id
|
||||
* @access public
|
||||
* @var int
|
||||
* @var int
|
||||
*/
|
||||
public $course_id;
|
||||
|
||||
/**
|
||||
* Completion criteria
|
||||
* @access private
|
||||
* @var array
|
||||
* @see completion_info->get_criteria()
|
||||
* Completion criteria {@see completion_info::get_criteria()}
|
||||
* @var array
|
||||
*/
|
||||
private $criteria;
|
||||
|
||||
/**
|
||||
* Return array of aggregation methods
|
||||
* @access public
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
public static function get_aggregation_methods() {
|
||||
return array(
|
||||
COMPLETION_AGGREGATION_ALL => get_string('all'),
|
||||
COMPLETION_AGGREGATION_ANY => get_string('any', 'completion'),
|
||||
COMPLETION_AGGREGATION_ALL => get_string('all'),
|
||||
COMPLETION_AGGREGATION_ANY => get_string('any', 'completion'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs with course details.
|
||||
*
|
||||
* @param object $course Moodle course object. Must have at least ->id, ->enablecompletion
|
||||
* When instantiating a new completion info object you must provide a course
|
||||
* object with at least id, and enablecompletion properties.
|
||||
*
|
||||
* @param stdClass $course Moodle course object.
|
||||
*/
|
||||
public function __construct($course) {
|
||||
$this->course = $course;
|
||||
@@ -160,10 +204,7 @@ class completion_info {
|
||||
/**
|
||||
* Determines whether completion is enabled across entire site.
|
||||
*
|
||||
* Static function.
|
||||
*
|
||||
* @global object
|
||||
* @return int COMPLETION_ENABLED (true) if completion is enabled for the site,
|
||||
* @return bool COMPLETION_ENABLED (true) if completion is enabled for the site,
|
||||
* COMPLETION_DISABLED (false) if it's complete
|
||||
*/
|
||||
public static function is_enabled_for_site() {
|
||||
@@ -175,16 +216,13 @@ class completion_info {
|
||||
* Checks whether completion is enabled in a particular course and possibly
|
||||
* activity.
|
||||
*
|
||||
* @global object
|
||||
* @uses COMPLETION_DISABLED
|
||||
* @uses COMPLETION_ENABLED
|
||||
* @param object $cm Course-module object. If not specified, returns the course
|
||||
* @param stdClass|cm_info $cm Course-module object. If not specified, returns the course
|
||||
* completion enable state.
|
||||
* @return mixed COMPLETION_ENABLED or COMPLETION_DISABLED (==0) in the case of
|
||||
* site and course; COMPLETION_TRACKING_MANUAL, _AUTOMATIC or _NONE (==0)
|
||||
* for a course-module.
|
||||
*/
|
||||
public function is_enabled($cm=null) {
|
||||
public function is_enabled($cm = null) {
|
||||
global $CFG, $DB;
|
||||
|
||||
// First check global completion
|
||||
@@ -214,8 +252,8 @@ class completion_info {
|
||||
/**
|
||||
* Displays the 'Your progress' help icon, if completion tracking is enabled.
|
||||
* Just prints the result of display_help_icon().
|
||||
* @deprecated Use display_help_icon instead.
|
||||
* @return void
|
||||
*
|
||||
* @deprecated since Moodle 2.0 - Use display_help_icon instead.
|
||||
*/
|
||||
public function print_help_icon() {
|
||||
print $this->display_help_icon();
|
||||
@@ -223,7 +261,7 @@ class completion_info {
|
||||
|
||||
/**
|
||||
* Returns the 'Your progress' help icon, if completion tracking is enabled.
|
||||
* @global object
|
||||
*
|
||||
* @return string HTML code for help icon, or blank if not needed
|
||||
*/
|
||||
public function display_help_icon() {
|
||||
@@ -239,10 +277,10 @@ class completion_info {
|
||||
|
||||
/**
|
||||
* Get a course completion for a user
|
||||
* @access public
|
||||
* @param $user_id int User id
|
||||
* @param $criteriatype int Specific criteria type to return
|
||||
* @return false|completion_criteria_completion
|
||||
*
|
||||
* @param int $user_id User id
|
||||
* @param int $criteriatype Specific criteria type to return
|
||||
* @return false|completion_criteria_completion
|
||||
*/
|
||||
public function get_completion($user_id, $criteriatype) {
|
||||
$completions = $this->get_completions($user_id, $criteriatype);
|
||||
@@ -258,10 +296,10 @@ class completion_info {
|
||||
|
||||
/**
|
||||
* Get all course criteria's completion objects for a user
|
||||
* @access public
|
||||
* @param $user_id int User id
|
||||
* @param $criteriatype int optional Specific criteria type to return
|
||||
* @return array
|
||||
*
|
||||
* @param int $user_id User id
|
||||
* @param int $criteriatype Specific criteria type to return (optional)
|
||||
* @return array
|
||||
*/
|
||||
public function get_completions($user_id, $criteriatype = null) {
|
||||
$criterion = $this->get_criteria($criteriatype);
|
||||
@@ -286,10 +324,10 @@ class completion_info {
|
||||
|
||||
/**
|
||||
* Get completion object for a user and a criteria
|
||||
* @access public
|
||||
* @param $user_id int User id
|
||||
* @param $criteria completion_criteria Criteria object
|
||||
* @return completion_criteria_completion
|
||||
*
|
||||
* @param int $user_id User id
|
||||
* @param completion_criteria $criteria Criteria object
|
||||
* @return completion_criteria_completion
|
||||
*/
|
||||
public function get_user_completion($user_id, $criteria) {
|
||||
$params = array(
|
||||
@@ -304,8 +342,7 @@ class completion_info {
|
||||
/**
|
||||
* Check if course has completion criteria set
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
* @return bool Returns true if there are criteria
|
||||
*/
|
||||
public function has_criteria() {
|
||||
$criteria = $this->get_criteria();
|
||||
@@ -313,12 +350,10 @@ class completion_info {
|
||||
return (bool) count($criteria);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get course completion criteria
|
||||
* @access public
|
||||
* @param $criteriatype int optional Specific criteria type to return
|
||||
* @return void
|
||||
*
|
||||
* @param int $criteriatype Specific criteria type to return (optional)
|
||||
*/
|
||||
public function get_criteria($criteriatype = null) {
|
||||
|
||||
@@ -361,9 +396,9 @@ class completion_info {
|
||||
|
||||
/**
|
||||
* Get aggregation method
|
||||
* @access public
|
||||
* @param $criteriatype int optional If none supplied, get overall aggregation method
|
||||
* @return int
|
||||
*
|
||||
* @param int $criteriatype If none supplied, get overall aggregation method (optional)
|
||||
* @return int One of COMPLETION_AGGREGATION_ALL or COMPLETION_AGGREGATION_ANY
|
||||
*/
|
||||
public function get_aggregation_method($criteriatype = null) {
|
||||
$params = array(
|
||||
@@ -382,8 +417,8 @@ class completion_info {
|
||||
|
||||
/**
|
||||
* Get incomplete course completion criteria
|
||||
* @access public
|
||||
* @return void
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_incomplete_criteria() {
|
||||
$incomplete = array();
|
||||
@@ -410,9 +445,9 @@ class completion_info {
|
||||
|
||||
/**
|
||||
* Has the supplied user completed this course
|
||||
* @access public
|
||||
* @param $user_id int User's id
|
||||
* @return boolean
|
||||
*
|
||||
* @param int $user_id User's id
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_course_complete($user_id) {
|
||||
$params = array(
|
||||
@@ -441,14 +476,7 @@ class completion_info {
|
||||
* calling the involved module via modulename_get_completion_state() to check
|
||||
* module-specific conditions.
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @uses COMPLETION_COMPLETE
|
||||
* @uses COMPLETION_INCOMPLETE
|
||||
* @uses COMPLETION_COMPLETE_PASS
|
||||
* @uses COMPLETION_COMPLETE_FAIL
|
||||
* @uses COMPLETION_TRACKING_MANUAL
|
||||
* @param object $cm Course-module
|
||||
* @param stdClass|cm $cm_info Course-module
|
||||
* @param int $possibleresult Expected completion result. If the event that
|
||||
* has just occurred (e.g. add post) can only result in making the activity
|
||||
* complete when it wasn't before, use COMPLETION_COMPLETE. If the event that
|
||||
@@ -509,22 +537,13 @@ class completion_info {
|
||||
* Calculates the completion state for an activity and user.
|
||||
*
|
||||
* Internal function. Not private, so we can unit-test it.
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @global object
|
||||
* @uses COMPLETION_VIEW_REQUIRED
|
||||
* @uses COMPLETION_NOT_VIEWED
|
||||
* @uses COMPLETION_INCOMPLETE
|
||||
* @uses FEATURE_COMPLETION_HAS_RULES
|
||||
* @uses COMPLETION_COMPLETE
|
||||
* @uses COMPLETION_AND
|
||||
* @param object $cm Activity
|
||||
*
|
||||
* @param stdClass|cm_info $cm Activity
|
||||
* @param int $userid ID of user
|
||||
* @param object $current Previous completion information from database
|
||||
* @param stdClass $current Previous completion information from database
|
||||
* @return mixed
|
||||
*/
|
||||
function internal_get_state($cm, $userid, $current) {
|
||||
public function internal_get_state($cm, $userid, $current) {
|
||||
global $USER, $DB, $CFG;
|
||||
|
||||
// Get user ID
|
||||
@@ -590,7 +609,6 @@ class completion_info {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Marks a module as viewed.
|
||||
*
|
||||
@@ -600,10 +618,8 @@ class completion_info {
|
||||
* Note that this function must be called before you print the page header because
|
||||
* it is possible that the navigation block may depend on it. If you call it after
|
||||
* printing the header, it shows a developer debug warning.
|
||||
* @uses COMPLETION_VIEW_NOT_REQUIRED
|
||||
* @uses COMPLETION_VIEWED
|
||||
* @uses COMPLETION_COMPLETE
|
||||
* @param object $cm Activity
|
||||
*
|
||||
* @param stdClass|cm_info $cm Activity
|
||||
* @param int $userid User ID or 0 (default) for current user
|
||||
* @return void
|
||||
*/
|
||||
@@ -634,8 +650,7 @@ class completion_info {
|
||||
* deciding whether completion information should be 'locked' in the module
|
||||
* editing form.
|
||||
*
|
||||
* @global object
|
||||
* @param object $cm Activity
|
||||
* @param cm_info $cm Activity
|
||||
* @return int The number of users who have completion data stored for this
|
||||
* activity, 0 if none
|
||||
*/
|
||||
@@ -656,10 +671,9 @@ class completion_info {
|
||||
* deciding whether completion information should be 'locked' in the completion
|
||||
* settings form and activity completion settings.
|
||||
*
|
||||
* @global object
|
||||
* @param int $user_id Optionally only get course completion data for a single user
|
||||
* @param int $user_id Optionally only get course completion data for a single user
|
||||
* @return int The number of users who have completion data stored for this
|
||||
* course, 0 if none
|
||||
* course, 0 if none
|
||||
*/
|
||||
public function count_course_user_data($user_id = null) {
|
||||
global $DB;
|
||||
@@ -687,7 +701,7 @@ class completion_info {
|
||||
/**
|
||||
* Check if this course's completion criteria should be locked
|
||||
*
|
||||
* @return boolean
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_course_locked() {
|
||||
return (bool) $this->count_course_user_data();
|
||||
@@ -697,9 +711,6 @@ class completion_info {
|
||||
* Deletes all course completion completion data.
|
||||
*
|
||||
* Intended to be used when unlocking completion criteria settings.
|
||||
*
|
||||
* @global object
|
||||
* @return void
|
||||
*/
|
||||
public function delete_course_completion_data() {
|
||||
global $DB;
|
||||
@@ -713,9 +724,7 @@ class completion_info {
|
||||
*
|
||||
* Intended for use only when the activity itself is deleted.
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @param object $cm Activity
|
||||
* @param stdClass|cm_info $cm Activity
|
||||
*/
|
||||
public function delete_all_state($cm) {
|
||||
global $SESSION, $DB;
|
||||
@@ -738,7 +747,7 @@ class completion_info {
|
||||
if ($criterion->moduleinstance == $cm->id) {
|
||||
$acriteria = $criterion;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($acriteria) {
|
||||
@@ -759,10 +768,7 @@ class completion_info {
|
||||
* Resetting state of manual tickbox has same result as deleting state for
|
||||
* it.
|
||||
*
|
||||
* @global object
|
||||
* @uses COMPLETION_TRACKING_MANUAL
|
||||
* @uses COMPLETION_UNKNOWN
|
||||
* @param object $cm Activity
|
||||
* @param stcClass|cm_info $cm Activity
|
||||
*/
|
||||
public function reset_all_state($cm) {
|
||||
global $DB;
|
||||
@@ -799,12 +805,7 @@ class completion_info {
|
||||
* Obtains completion data for a particular activity and user (from the
|
||||
* session cache if available, or by SQL query)
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @global object
|
||||
* @global object
|
||||
* @uses COMPLETION_CACHE_EXPIRY
|
||||
* @param object $cm Activity; only required field is ->id
|
||||
* @param stcClass|cm_info $cm Activity; only required field is ->id
|
||||
* @param bool $wholecourse If true (default false) then, when necessary to
|
||||
* fill the cache, retrieves information from the entire course not just for
|
||||
* this one activity
|
||||
@@ -815,7 +816,7 @@ class completion_info {
|
||||
* Otherwise the method calls get_fast_modinfo itself.
|
||||
* @return object Completion data (record from course_modules_completion)
|
||||
*/
|
||||
public function get_data($cm, $wholecourse=false, $userid=0, $modinfo=null) {
|
||||
public function get_data($cm, $wholecourse = false, $userid = 0, $modinfo = null) {
|
||||
global $USER, $CFG, $SESSION, $DB;
|
||||
|
||||
// Get user ID
|
||||
@@ -926,13 +927,10 @@ class completion_info {
|
||||
*
|
||||
* (Internal function. Not private, so we can unit-test it.)
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @global object
|
||||
* @param object $cm Activity
|
||||
* @param object $data Data about completion for that user
|
||||
* @param stdClass|cm_info $cm Activity
|
||||
* @param stdClass $data Data about completion for that user
|
||||
*/
|
||||
function internal_set_data($cm, $data) {
|
||||
public function internal_set_data($cm, $data) {
|
||||
global $USER, $SESSION, $DB;
|
||||
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
@@ -961,8 +959,6 @@ class completion_info {
|
||||
* Obtains a list of activities for which completion is enabled on the
|
||||
* course. The list is ordered by the section order of those activities.
|
||||
*
|
||||
* @global object
|
||||
* @uses COMPLETION_TRACKING_NONE
|
||||
* @param array $modinfo For unit testing only, supply the value
|
||||
* here. Otherwise the method calls get_fast_modinfo
|
||||
* @return array Array from $cmid => $cm of all activities with completion enabled,
|
||||
@@ -996,15 +992,14 @@ class completion_info {
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks to see if the userid supplied has a tracked role in
|
||||
* this course
|
||||
*
|
||||
* @param $userid User id
|
||||
* @return bool
|
||||
* @param int $userid User id
|
||||
* @return bool
|
||||
*/
|
||||
function is_tracked_user($userid) {
|
||||
public function is_tracked_user($userid) {
|
||||
global $DB;
|
||||
|
||||
$tracked = $this->generate_tracked_user_sql();
|
||||
@@ -1018,18 +1013,17 @@ class completion_info {
|
||||
return $DB->record_exists_sql($sql, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return number of users whose progress is tracked in this course
|
||||
*
|
||||
* Optionally supply a search's where clause, or a group id
|
||||
*
|
||||
* @param string $where Where clause sql
|
||||
* @param array $where_params Where clause params
|
||||
* @param int $groupid Group id
|
||||
* @return int
|
||||
* @param string $where Where clause sql
|
||||
* @param array $where_params Where clause params
|
||||
* @param int $groupid Group id
|
||||
* @return int
|
||||
*/
|
||||
function get_num_tracked_users($where = '', $where_params = array(), $groupid = 0) {
|
||||
public function get_num_tracked_users($where = '', $where_params = array(), $groupid = 0) {
|
||||
global $DB;
|
||||
|
||||
$tracked = $this->generate_tracked_user_sql($groupid);
|
||||
@@ -1045,23 +1039,22 @@ class completion_info {
|
||||
return $DB->count_records_sql($sql, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return array of users whose progress is tracked in this course
|
||||
*
|
||||
* Optionally supply a search's where caluse, group id, sorting, paging
|
||||
*
|
||||
* @param string $where Where clause sql (optional)
|
||||
* @param array $where_params Where clause params (optional)
|
||||
* @param integer $groupid Group ID to restrict to (optional)
|
||||
* @param string $sort Order by clause (optional)
|
||||
* @param integer $limitfrom Result start (optional)
|
||||
* @param integer $limitnum Result max size (optional)
|
||||
* @param string $where Where clause sql (optional)
|
||||
* @param array $where_params Where clause params (optional)
|
||||
* @param integer $groupid Group ID to restrict to (optional)
|
||||
* @param string $sort Order by clause (optional)
|
||||
* @param integer $limitfrom Result start (optional)
|
||||
* @param integer $limitnum Result max size (optional)
|
||||
* @param context $extracontext If set, includes extra user information fields
|
||||
* as appropriate to display for current user in this context
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
function get_tracked_users($where = '', $where_params = array(), $groupid = 0,
|
||||
public function get_tracked_users($where = '', $where_params = array(), $groupid = 0,
|
||||
$sort = '', $limitfrom = '', $limitnum = '', context $extracontext = null) {
|
||||
|
||||
global $DB;
|
||||
@@ -1095,17 +1088,16 @@ class completion_info {
|
||||
return $users ? $users : array(); // In case it returns false
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the SQL for finding tracked users in this course
|
||||
*
|
||||
* Returns an object containing the sql fragment and an array of
|
||||
* bound data params.
|
||||
*
|
||||
* @param integer $groupid
|
||||
* @return object
|
||||
* @param integer $groupid
|
||||
* @return stdClass With two properties, sql (string), and data (array)
|
||||
*/
|
||||
function generate_tracked_user_sql($groupid = 0) {
|
||||
public function generate_tracked_user_sql($groupid = 0) {
|
||||
global $CFG;
|
||||
|
||||
$return = new stdClass();
|
||||
@@ -1186,8 +1178,6 @@ class completion_info {
|
||||
* Users are included (in the first array) even if they do not have
|
||||
* completion progress for any course-module.
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @param bool $sortfirstname If true, sort by first name, otherwise sort by
|
||||
* last name
|
||||
* @param string $where Where clause sql (optional)
|
||||
@@ -1197,7 +1187,7 @@ class completion_info {
|
||||
* @param int $start User to start at if paging (optional)
|
||||
* @param context $extracontext If set, includes extra user information fields
|
||||
* as appropriate to display for current user in this context
|
||||
* @return Object with ->total and ->start (same as $start) and ->users;
|
||||
* @return stdClass with ->total and ->start (same as $start) and ->users;
|
||||
* an array of user objects (like mdl_user id, firstname, lastname)
|
||||
* containing an additional ->progress array of coursemoduleid => completionstate
|
||||
*/
|
||||
@@ -1231,8 +1221,7 @@ class completion_info {
|
||||
{course_modules} cm
|
||||
INNER JOIN {course_modules_completion} cmc ON cm.id=cmc.coursemoduleid
|
||||
WHERE
|
||||
cm.course=? AND cmc.userid $insql
|
||||
", $params);
|
||||
cm.course=? AND cmc.userid $insql", $params);
|
||||
foreach ($rs as $progress) {
|
||||
$progress = (object)$progress;
|
||||
$results[$progress->userid]->progress[$progress->coursemoduleid] = $progress;
|
||||
@@ -1248,13 +1237,10 @@ class completion_info {
|
||||
* been changed. If the changed grade is used to determine completion for
|
||||
* the course-module, then the completion status will be updated.
|
||||
*
|
||||
* @uses COMPLETION_TRACKING_MANUAL
|
||||
* @uses COMPLETION_INCOMPLETE
|
||||
* @param object $cm Course-module for item that owns grade
|
||||
* @param stdClass|cm_info $cm Course-module for item that owns grade
|
||||
* @param grade_item $item Grade item
|
||||
* @param object $grade
|
||||
* @param stdClass $grade
|
||||
* @param bool $deleted
|
||||
* @return void
|
||||
*/
|
||||
public function inform_grade_changed($cm, $item, $grade, $deleted) {
|
||||
// Bail out now if completion is not enabled for course-module, it is enabled
|
||||
@@ -1286,15 +1272,11 @@ class completion_info {
|
||||
*
|
||||
* Internal function. Not private, so we can unit-test it.
|
||||
*
|
||||
* @uses COMPLETION_INCOMPLETE
|
||||
* @uses COMPLETION_COMPLETE_PASS
|
||||
* @uses COMPLETION_COMPLETE_FAIL
|
||||
* @uses COMPLETION_COMPLETE
|
||||
* @param object $item grade_item
|
||||
* @param object $grade grade_grade
|
||||
* @param grade_item $item
|
||||
* @param grade_grade $grade
|
||||
* @return int Completion state e.g. COMPLETION_INCOMPLETE
|
||||
*/
|
||||
function internal_get_grade_state($item, $grade) {
|
||||
public function internal_get_grade_state($item, $grade) {
|
||||
if (!$grade) {
|
||||
return COMPLETION_INCOMPLETE;
|
||||
}
|
||||
@@ -1327,12 +1309,11 @@ class completion_info {
|
||||
* This is to be used only for system errors (things that shouldn't happen)
|
||||
* and not user-level errors.
|
||||
*
|
||||
* @global object
|
||||
* @param string $error Error string (will not be displayed to user unless
|
||||
* debugging is enabled)
|
||||
* @return void Throws moodle_exception Exception with the error string as debug info
|
||||
* @global type $CFG
|
||||
* @param string $error Error string (will not be displayed to user unless debugging is enabled)
|
||||
* @throws moodle_exception Exception with the error string as debug info
|
||||
*/
|
||||
function internal_systemerror($error) {
|
||||
public function internal_systemerror($error) {
|
||||
global $CFG;
|
||||
throw new moodle_exception('err_system','completion',
|
||||
$CFG->wwwroot.'/course/view.php?id='.$this->course->id,null,$error);
|
||||
@@ -1340,12 +1321,10 @@ class completion_info {
|
||||
|
||||
/**
|
||||
* For testing only. Wipes information cached in user session.
|
||||
*
|
||||
* @global object
|
||||
*/
|
||||
static function wipe_session_cache() {
|
||||
public static function wipe_session_cache() {
|
||||
global $SESSION;
|
||||
unset($SESSION->completioncache);
|
||||
unset($SESSION->completioncacheuserid);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user