Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
This class provides a targeted tied together means of interfacing the enrolment tasks together with a course. More...
Public Member Functions | |
__construct (moodle_page $moodlepage, $course, $instancefilter=null, $rolefilter=0, $searchfilter='', $groupfilter=0, $statusfilter=-1) | |
#- More... | |
add_user_to_group ($user, $groupid) | |
Adds a user to a group. More... | |
assign_role_to_user ($roleid, $userid) | |
Assigns a role to a user. More... | |
edit_enrolment ($userenrolment, $data) | |
Edits an enrolment. More... | |
get_all_groups () | |
Gets all of the groups for this course. More... | |
get_all_roles () | |
Gets all of the roles this course can contain. More... | |
get_assignable_roles ($otherusers=false) | |
Gets all of the assignable roles for this course. More... | |
get_assignable_roles_for_json ($otherusers=false) | |
Gets all of the assignable roles for this course, wrapped in an array to ensure role sort order is not lost during json deserialisation. More... | |
get_context () | |
Returns the course context. More... | |
get_course () | |
Returns the course this object is managing enrolments for. More... | |
get_enrolment_filter () | |
Returns the current enrolment filter that is being applied by this class. More... | |
get_enrolment_instance_names ($onlyenabled=false) | |
Returns the names for all of the enrolment instances for this course. More... | |
get_enrolment_instances ($onlyenabled=false) | |
Returns all of the enrolment instances for this course. More... | |
get_enrolment_plugins ($onlyenabled=true) | |
Gets all of the enrolment plugins that are available for this course. More... | |
get_filtered_enrolment_plugin () | |
Returns the enrolment plugin that the course manager was being filtered to. More... | |
get_group ($groupid) | |
Gets the requested group. More... | |
get_manual_enrol_buttons () | |
get_moodlepage () | |
Returns the current moodle page. More... | |
moodle_database | get_other_users ($sort, $direction='ASC', $page=0, $perpage=25) |
Gets and array of other users. More... | |
get_other_users_for_display (core_enrol_renderer $renderer, moodle_url $pageurl, $sort, $direction, $page, $perpage) | |
Gets an array of other users in this course ready for display. More... | |
moodle_database | get_potential_users ($enrolid, $search='', $searchanywhere=false, $page=0, $perpage=25, $addedenrollment=0, $returnexactcount=false) |
Gets an array of the users that can be enrolled in this course. More... | |
moodle_database | get_total_other_users () |
Returns the total number of enrolled users in the course. More... | |
moodle_database | get_total_users () |
Returns the total number of enrolled users in the course. More... | |
get_url_params () | |
Retursn an array of params that would go into the URL to return to this exact page. More... | |
get_user_enrolment_components ($userenrolment) | |
Given a user enrolment record this method returns the plugin and enrolment instance that relate to it. More... | |
moodle_database | get_user_enrolments ($userid) |
Gets the enrolments this user has in the course - including all suspended plugins and instances. More... | |
get_user_groups ($userid) | |
Gets the groups this user belongs to. More... | |
get_user_roles ($userid) | |
Gets the roles assigned to this user that are applicable for this course. More... | |
moodle_database | get_users ($sort, $direction='ASC', $page=0, $perpage=25) |
Gets all of the users enrolled in this course. More... | |
moodle_database | get_users_enrolments (array $userids) |
Returns and array of users + enrolment details. More... | |
get_users_for_display (course_enrolment_manager $manager, $sort, $direction, $page, $perpage) | |
Gets an array of users for display, this includes minimal user information as well as minimal information on the users roles, groups, and enrolments. More... | |
get_viewable_roles () | |
Gets all of the roles this course can contain. More... | |
has_instance ($enrolpluginname) | |
moodle_database | remove_user_from_group ($user, $groupid) |
Removes a user from a group. More... | |
moodle_database | search_other_users ($search='', $searchanywhere=false, $page=0, $perpage=25, $returnexactcount=false) |
Searches other users and returns paginated results. More... | |
search_users (string $search='', bool $searchanywhere=false, int $page=0, int $perpage=25, bool $returnexactcount=false) | |
Searches through the enrolled users in this course. More... | |
moodle_database | unassign_role_from_user ($userid, $roleid) |
Removes an assigned role from a user. More... | |
moodle_database | unenrol_user ($ue) |
Unenrols a user from the course given the users ue entry. More... | |
Protected Member Functions | |
execute_search_queries ($search, $fields, $countfields, $sql, array $params, $page, $perpage, $addedenrollment=0, $returnexactcount=false) | |
Helper method used by get_potential_users() and search_other_users(). More... | |
get_basic_search_conditions ($search, $searchanywhere) | |
Helper method used by get_potential_users() and search_other_users(). More... | |
get_filter_sql () | |
Obtains WHERE clause to filter results by defined search and role filter (instance filter is handled separately in JOIN clause, see get_instance_sql). More... | |
moodle_database | get_instance_sql () |
Gets an array containing some SQL to user for when selecting, params for that SQL, and the filter that was used in constructing the sql. More... | |
Protected Attributes | |
context | $context |
The course context. | |
stdClass | $course = null |
The course we are managing enrolments for. | |
int | $groupfilter = 0 |
Limits the focus of the manager to users in specified group. | |
string | $instancefilter = null |
Limits the focus of the manager to one enrolment plugin instance. | |
moodle_page | $moodlepage = null |
The current moodle_page object. | |
array | $otherusers = array() |
An array of users who have roles within this course but who have not been enrolled in the course. | |
int | $rolefilter = 0 |
Limits the focus of the manager to users with specified role. | |
string | $searchfilter = '' |
Limits the focus of the manager to users who match search string. | |
int | $statusfilter = -1 |
Limits the focus of the manager to users who match status active/inactive. | |
int | $totalotherusers = null |
The total number of users who hold a role within the course but who arn't enrolled. | |
int | $totalusers = null |
The total number of users enrolled in the course Populated by course_enrolment_manager::get_total_users. | |
array | $users = array() |
An array of users currently enrolled in the course Populated by course_enrolment_manager::get_users. | |
This class provides a targeted tied together means of interfacing the enrolment tasks together with a course.
It is provided as a convenience more than anything else.
course_enrolment_manager::__construct | ( | moodle_page | $moodlepage, |
$course, | |||
$instancefilter = null , |
|||
$rolefilter = 0 , |
|||
$searchfilter = '' , |
|||
$groupfilter = 0 , |
|||
$statusfilter = -1 |
|||
) |
#-
Constructs the course enrolment manager
moodle_page | $moodlepage | |
stdClass | $course | |
string | $instancefilter | |
int | $rolefilter | If non-zero, filters to users with specified role |
string | $searchfilter | If non-blank, filters to users with search text |
int | $groupfilter | if non-zero, filter users with specified group |
int | $statusfilter | if not -1, filter users with active/inactive enrollment. |
course_enrolment_manager::add_user_to_group | ( | $user, | |
$groupid | |||
) |
Adds a user to a group.
stdClass | $user | |
int | $groupid |
bool |
course_enrolment_manager::assign_role_to_user | ( | $roleid, | |
$userid | |||
) |
Assigns a role to a user.
int | $roleid | |
int | $userid |
int|false |
course_enrolment_manager::edit_enrolment | ( | $userenrolment, | |
$data | |||
) |
Edits an enrolment.
stdClass | $userenrolment | |
stdClass | $data |
bool |
|
protected |
Helper method used by get_potential_users() and search_other_users().
string | $search | the search string, if any. |
string | $fields | the first bit of the SQL when returning some users. |
string | $countfields | fhe first bit of the SQL when counting the users. |
string | $sql | the bulk of the SQL statement. |
array | $params | query parameters. |
int | $page | which page number of the results to show. |
int | $perpage | number of users per page. |
int | $addedenrollment | number of users added to enrollment. |
bool | $returnexactcount | Return the exact total users using count_record or not. |
array | with two or three elements: int totalusers Number users matching the search. (This element only exist if $returnexactcount was set to true) array users List of user objects returned by the query. boolean moreusers True if there are still more users, otherwise is False. |
dml_exception |
course_enrolment_manager::get_all_groups | ( | ) |
Gets all of the groups for this course.
array |
course_enrolment_manager::get_all_roles | ( | ) |
Gets all of the roles this course can contain.
array |
course_enrolment_manager::get_assignable_roles | ( | $otherusers = false | ) |
Gets all of the assignable roles for this course.
array |
course_enrolment_manager::get_assignable_roles_for_json | ( | $otherusers = false | ) |
Gets all of the assignable roles for this course, wrapped in an array to ensure role sort order is not lost during json deserialisation.
boolean | $otherusers | whether to include the assignable roles for other users |
array |
|
protected |
Helper method used by get_potential_users() and search_other_users().
string | $search | the search term, if any. |
bool | $searchanywhere | Can the search term be anywhere, or must it be at the start. |
array | with three elements: string list of fields to SELECT, string contents of SQL WHERE clause, array query params. Note that the SQL snippets use named parameters. |
course_enrolment_manager::get_context | ( | ) |
Returns the course context.
context |
course_enrolment_manager::get_course | ( | ) |
Returns the course this object is managing enrolments for.
stdClass |
course_enrolment_manager::get_enrolment_filter | ( | ) |
Returns the current enrolment filter that is being applied by this class.
string |
course_enrolment_manager::get_enrolment_instance_names | ( | $onlyenabled = false | ) |
Returns the names for all of the enrolment instances for this course.
bool | $onlyenabled | Whether to return data from enabled enrolment instance names only. |
array |
course_enrolment_manager::get_enrolment_instances | ( | $onlyenabled = false | ) |
Returns all of the enrolment instances for this course.
bool | $onlyenabled | Whether to return data from enabled enrolment instance names only. |
array |
course_enrolment_manager::get_enrolment_plugins | ( | $onlyenabled = true | ) |
Gets all of the enrolment plugins that are available for this course.
bool | $onlyenabled | return only enabled enrol plugins |
array |
|
protected |
Obtains WHERE clause to filter results by defined search and role filter (instance filter is handled separately in JOIN clause, see get_instance_sql).
array | Two-element array with SQL and params for WHERE clause |
course_enrolment_manager::get_filtered_enrolment_plugin | ( | ) |
Returns the enrolment plugin that the course manager was being filtered to.
If no filter was being applied then this function returns false.
enrol_plugin |
course_enrolment_manager::get_group | ( | $groupid | ) |
Gets the requested group.
int | $groupid |
stdClass|int |
|
protected |
Gets an array containing some SQL to user for when selecting, params for that SQL, and the filter that was used in constructing the sql.
$DB
string |
course_enrolment_manager::get_moodlepage | ( | ) |
Returns the current moodle page.
moodle_page |
moodle_database course_enrolment_manager::get_other_users | ( | $sort, | |
$direction = 'ASC' , |
|||
$page = 0 , |
|||
$perpage = 25 |
|||
) |
Gets and array of other users.
Other users are users who have been assigned roles or inherited roles within this course but who have not been enrolled in the course
$DB
string | $sort | |
string | $direction | |
int | $page | |
int | $perpage |
array |
course_enrolment_manager::get_other_users_for_display | ( | core_enrol_renderer | $renderer, |
moodle_url | $pageurl, | ||
$sort, | |||
$direction, | |||
$page, | |||
$perpage | |||
) |
Gets an array of other users in this course ready for display.
Other users are users who have been assigned or inherited roles within this course but have not been enrolled.
core_enrol_renderer | $renderer | |
moodle_url | $pageurl | |
string | $sort | |
string | $direction | ASC | DESC |
int | $page | Starting from 0 |
int | $perpage |
array |
moodle_database course_enrolment_manager::get_potential_users | ( | $enrolid, | |
$search = '' , |
|||
$searchanywhere = false , |
|||
$page = 0 , |
|||
$perpage = 25 , |
|||
$addedenrollment = 0 , |
|||
$returnexactcount = false |
|||
) |
Gets an array of the users that can be enrolled in this course.
$DB
int | $enrolid | |
string | $search | |
bool | $searchanywhere | |
int | $page | Defaults to 0 |
int | $perpage | Defaults to 25 |
int | $addedenrollment | Defaults to 0 |
bool | $returnexactcount | Return the exact total users using count_record or not. |
array | with two or three elements: int totalusers Number users matching the search. (This element only exist if $returnexactcount was set to true) array users List of user objects returned by the query. boolean moreusers True if there are still more users, otherwise is False. |
dml_exception |
moodle_database course_enrolment_manager::get_total_other_users | ( | ) |
Returns the total number of enrolled users in the course.
If a filter was specificed this will be the total number of users enrolled in this course by means of that instance.
$DB
int |
moodle_database course_enrolment_manager::get_total_users | ( | ) |
Returns the total number of enrolled users in the course.
If a filter was specificed this will be the total number of users enrolled in this course by means of that instance.
$DB
int |
course_enrolment_manager::get_url_params | ( | ) |
Retursn an array of params that would go into the URL to return to this exact page.
array |
course_enrolment_manager::get_user_enrolment_components | ( | $userenrolment | ) |
Given a user enrolment record this method returns the plugin and enrolment instance that relate to it.
stdClass | int | $userenrolment |
array | array($instance, $plugin) |
moodle_database course_enrolment_manager::get_user_enrolments | ( | $userid | ) |
Gets the enrolments this user has in the course - including all suspended plugins and instances.
$DB
int | $userid |
array |
course_enrolment_manager::get_user_groups | ( | $userid | ) |
Gets the groups this user belongs to.
int | $userid |
array |
course_enrolment_manager::get_user_roles | ( | $userid | ) |
Gets the roles assigned to this user that are applicable for this course.
int | $userid |
array |
moodle_database course_enrolment_manager::get_users | ( | $sort, | |
$direction = 'ASC' , |
|||
$page = 0 , |
|||
$perpage = 25 |
|||
) |
Gets all of the users enrolled in this course.
If a filter was specified this will be the users who were enrolled in this course by means of that instance. If role or search filters were specified then these will also be applied.
$DB
string | $sort | |
string | $direction | ASC or DESC |
int | $page | First page should be 0 |
int | $perpage | Defaults to 25 |
array |
moodle_database course_enrolment_manager::get_users_enrolments | ( | array | $userids | ) |
Returns and array of users + enrolment details.
Given an array of user id's this function returns and array of user enrolments for those users as well as enough user information to display the users name and picture for each enrolment.
$DB
array | $userids |
array |
course_enrolment_manager::get_users_for_display | ( | course_enrolment_manager | $manager, |
$sort, | |||
$direction, | |||
$page, | |||
$perpage | |||
) |
Gets an array of users for display, this includes minimal user information as well as minimal information on the users roles, groups, and enrolments.
core_enrol_renderer | $renderer | |
moodle_url | $pageurl | |
int | $sort | |
string | $direction | ASC or DESC |
int | $page | |
int | $perpage |
array |
course_enrolment_manager::get_viewable_roles | ( | ) |
Gets all of the roles this course can contain.
array |
moodle_database course_enrolment_manager::remove_user_from_group | ( | $user, | |
$groupid | |||
) |
Removes a user from a group.
$DB
StdClass | $user | |
int | $groupid |
bool |
moodle_database course_enrolment_manager::search_other_users | ( | $search = '' , |
|
$searchanywhere = false , |
|||
$page = 0 , |
|||
$perpage = 25 , |
|||
$returnexactcount = false |
|||
) |
Searches other users and returns paginated results.
$DB
string | $search | |
bool | $searchanywhere | |
int | $page | Starting at 0 |
int | $perpage | |
bool | $returnexactcount | Return the exact total users using count_record or not. |
array | with two or three elements: int totalusers Number users matching the search. (This element only exist if $returnexactcount was set to true) array users List of user objects returned by the query. boolean moreusers True if there are still more users, otherwise is False. |
dml_exception |
course_enrolment_manager::search_users | ( | string | $search = '' , |
bool | $searchanywhere = false , |
||
int | $page = 0 , |
||
int | $perpage = 25 , |
||
bool | $returnexactcount = false |
||
) |
Searches through the enrolled users in this course.
string | $search | The search term. |
bool | $searchanywhere | Can the search term be anywhere, or must it be at the start. |
int | $page | Starting at 0. |
int | $perpage | Number of users returned per page. |
bool | $returnexactcount | Return the exact total users using count_record or not. |
array | with two or three elements: int totalusers Number users matching the search. (This element only exist if $returnexactcount was set to true) array users List of user objects returned by the query. boolean moreusers True if there are still more users, otherwise is False. |
moodle_database course_enrolment_manager::unassign_role_from_user | ( | $userid, | |
$roleid | |||
) |
Removes an assigned role from a user.
$DB
int | $userid | |
int | $roleid |
bool |
moodle_database course_enrolment_manager::unenrol_user | ( | $ue | ) |
Unenrols a user from the course given the users ue entry.
$DB
stdClass | $ue |
bool |