Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Public Member Functions | |
__construct ($course) | |
Constructs with course details. More... | |
clear_criteria () | |
Clear old course completion criteria. | |
count_course_user_data ($user_id=null) | |
Determines how much course completion data exists for a course. More... | |
count_user_data ($cm) | |
Determines how much completion data exists for an activity. More... | |
delete_all_completion_data () | |
Deletes all activity and course completion data for an entire course (the below delete_all_state function does this for a single activity). More... | |
delete_all_state ($cm) | |
Deletes completion state related to an activity for all users. More... | |
delete_course_completion_data () | |
Deletes all course completion completion data. More... | |
display_help_icon () | |
Returns the 'Your progress' help icon, if completion tracking is enabled. More... | |
get_activities () | |
Obtains a list of activities for which completion is enabled on the course. More... | |
get_aggregation_method ($criteriatype=null) | |
Get aggregation method. More... | |
get_completion ($user_id, $criteriatype) | |
Get a course completion for a user. More... | |
get_completions ($user_id, $criteriatype=null) | |
Get all course criteria's completion objects for a user. More... | |
get_criteria ($criteriatype=null) | |
Get course completion criteria. More... | |
get_data ($cm, $wholecourse=false, $userid=0, $modinfo=null) | |
Obtains completion data for a particular activity and user (from the completion cache if available, or by SQL query) More... | |
get_incomplete_criteria () | |
get_num_tracked_users ($where='', $whereparams=array(), $groupid=0) | |
Returns the number of users whose progress is tracked in this course. More... | |
get_progress_all ($where='', $where_params=array(), $groupid=0, $sort='', $pagesize='', $start='', context $extracontext=null) | |
Obtains progress information across a course for all users on that course, or for all users in a specific group. More... | |
get_tracked_users ($where='', $whereparams=array(), $groupid=0, $sort='', $limitfrom='', $limitnum='', context $extracontext=null) | |
Return array of users whose progress is tracked in this course. More... | |
get_user_completion ($user_id, $criteria) | |
Get completion object for a user and a criteria. More... | |
has_activities () | |
Return whether or not the course has activities with completion enabled. More... | |
has_criteria () | |
Check if course has completion criteria set. More... | |
inform_grade_changed ($cm, $item, $grade, $deleted) | |
Called by grade code to inform the completion system when a grade has been changed. More... | |
internal_get_state ($cm, $userid, $current) | |
Calculates the completion state for an activity and user. More... | |
internal_set_data ($cm, $data) | |
Updates completion data for a particular coursemodule and user (user is determined from $data). More... | |
type | internal_systemerror ($error) |
This is to be used only for system errors (things that shouldn't happen) and not user-level errors. More... | |
is_course_complete ($user_id) | |
Has the supplied user completed this course. More... | |
is_course_locked () | |
Check if this course's completion criteria should be locked. More... | |
is_enabled ($cm=null) | |
Checks whether completion is enabled in a particular course and possibly activity. More... | |
is_tracked_user ($userid) | |
Checks to see if the userid supplied has a tracked role in this course. More... | |
print_help_icon () | |
Displays the 'Your progress' help icon, if completion tracking is enabled. More... | |
reset_all_state ($cm) | |
Recalculates completion state related to an activity for all users. More... | |
set_module_viewed ($cm, $userid=0) | |
Marks a module as viewed. More... | |
update_state ($cm, $possibleresult=COMPLETION_UNKNOWN, $userid=0, $override=false) | |
Updates (if necessary) the completion state of activity $cm for the given user. More... | |
user_can_override_completion ($user) | |
Check whether the supplied user can override the activity completion statuses within the current course. More... | |
Static Public Member Functions | |
static | aggregate_completion_states ($type, $old, $new) |
Aggregate activity completion state. More... | |
static | get_aggregation_methods () |
Return array of aggregation methods. More... | |
static | internal_get_grade_state ($item, $grade) |
Calculates the completion state that would result from a graded item (where grade-based completion is turned on) based on the actual grade and settings. More... | |
static | is_enabled_for_site () |
Determines whether completion is enabled across entire site. More... | |
Public Attributes | |
int | $course_id |
completion_info::__construct | ( | $course | ) |
Constructs with course details.
When instantiating a new completion info object you must provide a course object with at least id, and enablecompletion properties. Property cacherev is needed if you check completion of the current user since it is used for cache validation.
stdClass | $course | Moodle course object. |
|
static |
Aggregate activity completion state.
int | $type | Aggregation type (COMPLETION_* constant) |
bool | $old | Old state |
bool | $new | New state |
bool |
completion_info::count_course_user_data | ( | $user_id = null | ) |
Determines how much course completion data exists for a course.
This is used when deciding whether completion information should be 'locked' in the completion settings form and activity completion settings.
int | $user_id | Optionally only get course completion data for a single user |
int | The number of users who have completion data stored for this course, 0 if none |
completion_info::count_user_data | ( | $cm | ) |
Determines how much completion data exists for an activity.
This is used when deciding whether completion information should be 'locked' in the module editing form.
cm_info | $cm | Activity |
int | The number of users who have completion data stored for this activity, 0 if none |
completion_info::delete_all_completion_data | ( | ) |
Deletes all activity and course completion data for an entire course (the below delete_all_state function does this for a single activity).
Used by course reset page.
completion_info::delete_all_state | ( | $cm | ) |
Deletes completion state related to an activity for all users.
Intended for use only when the activity itself is deleted.
stdClass | cm_info | $cm | Activity |
completion_info::delete_course_completion_data | ( | ) |
Deletes all course completion completion data.
Intended to be used when unlocking completion criteria settings.
completion_info::display_help_icon | ( | ) |
Returns the 'Your progress' help icon, if completion tracking is enabled.
string | HTML code for help icon, or blank if not needed |
completion_info::get_activities | ( | ) |
Obtains a list of activities for which completion is enabled on the course.
The list is ordered by the section order of those activities.
cm_info[] | Array from $cmid => $cm of all activities with completion enabled, empty array if none |
completion_info::get_aggregation_method | ( | $criteriatype = null | ) |
Get aggregation method.
int | $criteriatype | If none supplied, get overall aggregation method (optional) |
int | One of COMPLETION_AGGREGATION_ALL or COMPLETION_AGGREGATION_ANY |
|
static |
Return array of aggregation methods.
array |
completion_info::get_completion | ( | $user_id, | |
$criteriatype | |||
) |
Get a course completion for a user.
int | $user_id | User id |
int | $criteriatype | Specific criteria type to return |
bool|completion_criteria_completion | returns false on fail |
completion_info::get_completions | ( | $user_id, | |
$criteriatype = null |
|||
) |
Get all course criteria's completion objects for a user.
int | $user_id | User id |
int | $criteriatype | Specific criteria type to return (optional) |
array |
completion_info::get_criteria | ( | $criteriatype = null | ) |
Get course completion criteria.
int | $criteriatype | Specific criteria type to return (optional) |
completion_info::get_data | ( | $cm, | |
$wholecourse = false , |
|||
$userid = 0 , |
|||
$modinfo = null |
|||
) |
Obtains completion data for a particular activity and user (from the completion cache if available, or by SQL query)
stcClass | cm_info | $cm | Activity; only required field is ->id |
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 |
int | $userid | User ID or 0 (default) for current user |
array | $modinfo | Supply the value here - this is used for unit testing and so that it can be called recursively from within get_fast_modinfo. (Needs only list of all CMs with IDs.) Otherwise the method calls get_fast_modinfo itself. |
object | Completion data (record from course_modules_completion) |
completion_info::get_incomplete_criteria | ( | ) |
completion_info::get_num_tracked_users | ( | $where = '' , |
|
$whereparams = array() , |
|||
$groupid = 0 |
|||
) |
Returns the number of users whose progress is tracked in this course.
Optionally supply a search's where clause, or a group id.
string | $where | Where clause sql (use 'u.whatever' for user table fields) |
array | $whereparams | Where clause params |
int | $groupid | Group id |
int | Number of tracked users |
completion_info::get_progress_all | ( | $where = '' , |
|
$where_params = array() , |
|||
$groupid = 0 , |
|||
$sort = '' , |
|||
$pagesize = '' , |
|||
$start = '' , |
|||
context | $extracontext = null |
||
) |
Obtains progress information across a course for all users on that course, or for all users in a specific group.
Intended for use when displaying progress.
This includes only users who, in course context, have one of the roles for which progress is tracked (the gradebookroles admin option) and are enrolled in course.
Users are included (in the first array) even if they do not have completion progress for any course-module.
bool | $sortfirstname | If true, sort by first name, otherwise sort by last name |
string | $where | Where clause sql (optional) |
array | $where_params | Where clause params (optional) |
int | $groupid | Group ID or 0 (default)/false for all groups |
int | $pagesize | Number of users to actually return (optional) |
int | $start | User to start at if paging (optional) |
context | $extracontext | If set, includes extra user information fields as appropriate to display for current user in this context |
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 |
completion_info::get_tracked_users | ( | $where = '' , |
|
$whereparams = array() , |
|||
$groupid = 0 , |
|||
$sort = '' , |
|||
$limitfrom = '' , |
|||
$limitnum = '' , |
|||
context | $extracontext = null |
||
) |
Return array of users whose progress is tracked in this course.
Optionally supply a search's where clause, group id, sorting, paging.
string | $where | Where clause sql, referring to 'u.' fields (optional) |
array | $whereparams | Where clause params (optional) |
int | $groupid | Group ID to restrict to (optional) |
string | $sort | Order by clause (optional) |
int | $limitfrom | Result start (optional) |
int | $limitnum | Result max size (optional) |
context | $extracontext | If set, includes extra user information fields as appropriate to display for current user in this context |
array | Array of user objects with standard user fields |
completion_info::get_user_completion | ( | $user_id, | |
$criteria | |||
) |
Get completion object for a user and a criteria.
int | $user_id | User id |
completion_criteria | $criteria | Criteria object |
completion_criteria_completion |
completion_info::has_activities | ( | ) |
Return whether or not the course has activities with completion enabled.
boolean | true when there is at least one activity with completion enabled. |
completion_info::has_criteria | ( | ) |
Check if course has completion criteria set.
bool | Returns true if there are criteria |
completion_info::inform_grade_changed | ( | $cm, | |
$item, | |||
$grade, | |||
$deleted | |||
) |
Called by grade code to inform the completion system when a grade has been changed.
If the changed grade is used to determine completion for the course-module, then the completion status will be updated.
stdClass | cm_info | $cm | Course-module for item that owns grade |
grade_item | $item | Grade item |
stdClass | $grade | |
bool | $deleted |
|
static |
Calculates the completion state that would result from a graded item (where grade-based completion is turned on) based on the actual grade and settings.
Internal function. Not private, so we can unit-test it.
grade_item | $item | an instance of grade_item |
grade_grade | $grade | an instance of grade_grade |
int | Completion state e.g. COMPLETION_INCOMPLETE |
completion_info::internal_get_state | ( | $cm, | |
$userid, | |||
$current | |||
) |
Calculates the completion state for an activity and user.
Internal function. Not private, so we can unit-test it.
stdClass | cm_info | $cm | Activity |
int | $userid | ID of user |
stdClass | $current | Previous completion information from database |
mixed |
completion_info::internal_set_data | ( | $cm, | |
$data | |||
) |
Updates completion data for a particular coursemodule and user (user is determined from $data).
(Internal function. Not private, so we can unit-test it.)
stdClass | cm_info | $cm | Activity |
stdClass | $data | Data about completion for that user |
type completion_info::internal_systemerror | ( | $error | ) |
This is to be used only for system errors (things that shouldn't happen) and not user-level errors.
$CFG
string | $error | Error string (will not be displayed to user unless debugging is enabled) |
moodle_exception | Exception with the error string as debug info |
completion_info::is_course_complete | ( | $user_id | ) |
Has the supplied user completed this course.
int | $user_id | User's id |
boolean |
completion_info::is_course_locked | ( | ) |
Check if this course's completion criteria should be locked.
boolean |
completion_info::is_enabled | ( | $cm = null | ) |
Checks whether completion is enabled in a particular course and possibly activity.
stdClass | cm_info | $cm | Course-module object. If not specified, returns the course completion enable state. |
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. |
|
static |
Determines whether completion is enabled across entire site.
bool | COMPLETION_ENABLED (true) if completion is enabled for the site, COMPLETION_DISABLED (false) if it's complete |
completion_info::is_tracked_user | ( | $userid | ) |
Checks to see if the userid supplied has a tracked role in this course.
int | $userid | User id |
bool |
completion_info::print_help_icon | ( | ) |
Displays the 'Your progress' help icon, if completion tracking is enabled.
Just prints the result of display_help_icon().
completion_info::reset_all_state | ( | $cm | ) |
Recalculates completion state related to an activity for all users.
Intended for use if completion conditions change. (This should be avoided as it may cause some things to become incomplete when they were previously complete, with the effect - for example - of hiding a later activity that was previously available.)
Resetting state of manual tickbox has same result as deleting state for it.
stcClass | cm_info | $cm | Activity |
completion_info::set_module_viewed | ( | $cm, | |
$userid = 0 |
|||
) |
Marks a module as viewed.
Should be called whenever a module is 'viewed' (it is up to the module how to determine that). Has no effect if viewing is not set as a completion condition.
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.
stdClass | cm_info | $cm | Activity |
int | $userid | User ID or 0 (default) for current user |
void |
completion_info::update_state | ( | $cm, | |
$possibleresult = COMPLETION_UNKNOWN , |
|||
$userid = 0 , |
|||
$override = false |
|||
) |
Updates (if necessary) the completion state of activity $cm for the given user.
For manual completion, this function is called when completion is toggled with $possibleresult set to the target state.
For automatic completion, this function should be called every time a module does something which might influence a user's completion state. For example, 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.
stdClass | cm_info | $cm | Course-module |
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 has just occurred (e.g. delete post) can only result in making the activity not complete when it was previously complete, use COMPLETION_INCOMPLETE. Otherwise use COMPLETION_UNKNOWN. Setting this value to something other than COMPLETION_UNKNOWN significantly improves performance because it will abandon processing early if the user's completion state already matches the expected result. For manual events, COMPLETION_COMPLETE or COMPLETION_INCOMPLETE must be used; these directly set the specified state. |
int | $userid | User ID to be updated. Default 0 = current user |
bool | $override | Whether manually overriding the existing completion state. |
void |
moodle_exception | if trying to override without permission. |
completion_info::user_can_override_completion | ( | $user | ) |
Check whether the supplied user can override the activity completion statuses within the current course.
stdClass | $user | The user object. |
bool | True if the user can override, false otherwise. |