Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
course_enrolment_manager Class Reference

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)
 #-
 
 add_user_to_group ($user, $groupid)
 Adds a user to a group.
 
 assign_role_to_user ($roleid, $userid)
 Assigns a role to a user.
 
 edit_enrolment ($userenrolment, $data)
 Edits an enrolment.
 
 get_all_groups ()
 Gets all of the groups for this course.
 
 get_all_roles ()
 Gets all of the roles this course can contain.
 
 get_assignable_roles ($otherusers=false)
 Gets all of the assignable roles for this course.
 
 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.
 
 get_context ()
 Returns the course context.
 
 get_course ()
 Returns the course this object is managing enrolments for.
 
 get_enrolment_filter ()
 Returns the current enrolment filter that is being applied by this class.
 
 get_enrolment_instance_names ($onlyenabled=false)
 Returns the names for all of the enrolment instances for this course.
 
 get_enrolment_instances ($onlyenabled=false)
 Returns all of the enrolment instances for this course.
 
 get_enrolment_plugins ($onlyenabled=true)
 Gets all of the enrolment plugins that are available for this course.
 
 get_filtered_enrolment_plugin ()
 Returns the enrolment plugin that the course manager was being filtered to.
 
 get_group ($groupid)
 Gets the requested group.
 
 get_manual_enrol_buttons ()
 
 get_moodlepage ()
 Returns the current moodle page.
 
moodle_database get_other_users ($sort, $direction='ASC', $page=0, $perpage=25)
 Gets and array of other users.
 
 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.
 
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.
 
moodle_database get_total_other_users ()
 Returns the total number of enrolled users in the course.
 
moodle_database get_total_users ()
 Returns the total number of enrolled users in the course.
 
 get_url_params ()
 Retursn an array of params that would go into the URL to return to this exact page.
 
 get_user_enrolment_components ($userenrolment)
 Given a user enrolment record this method returns the plugin and enrolment instance that relate to it.
 
moodle_database get_user_enrolments ($userid)
 Gets the enrolments this user has in the course - including all suspended plugins and instances.
 
 get_user_groups ($userid)
 Gets the groups this user belongs to.
 
 get_user_roles ($userid)
 Gets the roles assigned to this user that are applicable for this course.
 
moodle_database get_users ($sort, $direction='ASC', $page=0, $perpage=25)
 Gets all of the users enrolled in this course.
 
moodle_database get_users_enrolments (array $userids)
 Returns and array of users + enrolment details.
 
 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.
 
 get_viewable_roles ()
 Gets all of the roles this course can contain.
 
 has_instance ($enrolpluginname)
 
moodle_database remove_user_from_group ($user, $groupid)
 Removes a user from a group.
 
moodle_database search_other_users ($search='', $searchanywhere=false, $page=0, $perpage=25, $returnexactcount=false)
 Searches other users and returns paginated results.
 
 search_users (string $search='', bool $searchanywhere=false, int $page=0, int $perpage=25, bool $returnexactcount=false, ?int $contextid=null)
 Searches through the enrolled users in this course.
 
moodle_database unassign_role_from_user ($userid, $roleid)
 Removes an assigned role from a user.
 
moodle_database unenrol_user ($ue)
 Unenrols a user from the course given the users ue entry.
 

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().
 
 get_basic_search_conditions ($search, $searchanywhere)
 Helper method used by get_potential_users() and search_other_users().
 
 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).
 
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.
 

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.
 

Detailed Description

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.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

course_enrolment_manager::__construct ( moodle_page $moodlepage,
$course,
$instancefilter = null,
$rolefilter = 0,
$searchfilter = '',
$groupfilter = 0,
$statusfilter = -1 )

#-

Constructs the course enrolment manager

Parameters
moodle_page$moodlepage
stdClass$course
string$instancefilter
int$rolefilterIf non-zero, filters to users with specified role
string$searchfilterIf non-blank, filters to users with search text
int$groupfilterif non-zero, filter users with specified group
int$statusfilterif not -1, filter users with active/inactive enrollment.

Member Function Documentation

◆ add_user_to_group()

course_enrolment_manager::add_user_to_group ( $user,
$groupid )

Adds a user to a group.

Parameters
stdClass$user
int$groupid
Return values
bool

◆ assign_role_to_user()

course_enrolment_manager::assign_role_to_user ( $roleid,
$userid )

Assigns a role to a user.

Parameters
int$roleid
int$userid
Return values
int|false

◆ edit_enrolment()

course_enrolment_manager::edit_enrolment ( $userenrolment,
$data )

Edits an enrolment.

Parameters
stdClass$userenrolment
stdClass$data
Return values
bool

◆ execute_search_queries()

course_enrolment_manager::execute_search_queries ( $search,
$fields,
$countfields,
$sql,
array $params,
$page,
$perpage,
$addedenrollment = 0,
$returnexactcount = false )
protected

Helper method used by get_potential_users() and search_other_users().

Parameters
string$searchthe search string, if any.
string$fieldsthe first bit of the SQL when returning some users.
string$countfieldsfhe first bit of the SQL when counting the users.
string$sqlthe bulk of the SQL statement.
array$paramsquery parameters.
int$pagewhich page number of the results to show.
int$perpagenumber of users per page.
int$addedenrollmentnumber of users added to enrollment.
bool$returnexactcountReturn the exact total users using count_record or not.
Return values
arraywith 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.
Exceptions
dml_exception

◆ get_all_groups()

course_enrolment_manager::get_all_groups ( )

Gets all of the groups for this course.

Return values
array

◆ get_all_roles()

course_enrolment_manager::get_all_roles ( )

Gets all of the roles this course can contain.

Return values
array

◆ get_assignable_roles()

course_enrolment_manager::get_assignable_roles ( $otherusers = false)

Gets all of the assignable roles for this course.

Return values
array

◆ get_assignable_roles_for_json()

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.

Parameters
boolean$otheruserswhether to include the assignable roles for other users
Return values
array

◆ get_basic_search_conditions()

course_enrolment_manager::get_basic_search_conditions ( $search,
$searchanywhere )
protected

Helper method used by get_potential_users() and search_other_users().

Parameters
string$searchthe search term, if any.
bool$searchanywhereCan the search term be anywhere, or must it be at the start.
Return values
arraywith three elements: string list of fields to SELECT, string possible database joins for user fields string contents of SQL WHERE clause, array query params. Note that the SQL snippets use named parameters.

◆ get_context()

course_enrolment_manager::get_context ( )

Returns the course context.

Return values
context

◆ get_course()

course_enrolment_manager::get_course ( )

Returns the course this object is managing enrolments for.

Return values
stdClass

◆ get_enrolment_filter()

course_enrolment_manager::get_enrolment_filter ( )

Returns the current enrolment filter that is being applied by this class.

Return values
string

◆ get_enrolment_instance_names()

course_enrolment_manager::get_enrolment_instance_names ( $onlyenabled = false)

Returns the names for all of the enrolment instances for this course.

Parameters
bool$onlyenabledWhether to return data from enabled enrolment instance names only.
Return values
array

◆ get_enrolment_instances()

course_enrolment_manager::get_enrolment_instances ( $onlyenabled = false)

Returns all of the enrolment instances for this course.

Parameters
bool$onlyenabledWhether to return data from enabled enrolment instance names only.
Return values
array

◆ get_enrolment_plugins()

course_enrolment_manager::get_enrolment_plugins ( $onlyenabled = true)

Gets all of the enrolment plugins that are available for this course.

Parameters
bool$onlyenabledreturn only enabled enrol plugins
Return values
array

◆ get_filter_sql()

course_enrolment_manager::get_filter_sql ( )
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).

Return values
arrayTwo-element array with SQL and params for WHERE clause

◆ get_filtered_enrolment_plugin()

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.

Return values
enrol_plugin

◆ get_group()

course_enrolment_manager::get_group ( $groupid)

Gets the requested group.

Parameters
int$groupid
Return values
stdClass|int

◆ get_instance_sql()

moodle_database course_enrolment_manager::get_instance_sql ( )
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

Return values
array

◆ get_moodlepage()

course_enrolment_manager::get_moodlepage ( )

Returns the current moodle page.

Return values
moodle_page

◆ get_other_users()

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

Parameters
string$sort
string$direction
int$page
int$perpage
Return values
array

◆ get_other_users_for_display()

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.

Parameters
core_enrol_renderer$renderer
moodle_url$pageurl
string$sort
string$directionASC | DESC
int$pageStarting from 0
int$perpage
Return values
array

◆ get_potential_users()

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

Parameters
int$enrolid
string$search
bool$searchanywhere
int$pageDefaults to 0
int$perpageDefaults to 25
int$addedenrollmentDefaults to 0
bool$returnexactcountReturn the exact total users using count_record or not.
Return values
arraywith 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.
Exceptions
dml_exception

◆ get_total_other_users()

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

Return values
int

◆ get_total_users()

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

Return values
int

◆ get_url_params()

course_enrolment_manager::get_url_params ( )

Retursn an array of params that would go into the URL to return to this exact page.

Return values
array

◆ get_user_enrolment_components()

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.

Parameters
stdClass | int$userenrolment
Return values
arrayarray($instance, $plugin)

◆ get_user_enrolments()

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

Parameters
int$userid
Return values
array

◆ get_user_groups()

course_enrolment_manager::get_user_groups ( $userid)

Gets the groups this user belongs to.

Parameters
int$userid
Return values
array

◆ get_user_roles()

course_enrolment_manager::get_user_roles ( $userid)

Gets the roles assigned to this user that are applicable for this course.

Parameters
int$userid
Return values
array

◆ get_users()

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

Parameters
string$sort
string$directionASC or DESC
int$pageFirst page should be 0
int$perpageDefaults to 25
Return values
array

◆ get_users_enrolments()

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

Parameters
array$userids
Return values
array

◆ get_users_for_display()

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.

Parameters
core_enrol_renderer$renderer
moodle_url$pageurl
int$sort
string$directionASC or DESC
int$page
int$perpage
Return values
array

◆ get_viewable_roles()

course_enrolment_manager::get_viewable_roles ( )

Gets all of the roles this course can contain.

Return values
array

◆ remove_user_from_group()

moodle_database course_enrolment_manager::remove_user_from_group ( $user,
$groupid )

Removes a user from a group.

$DB

Parameters
StdClass$user
int$groupid
Return values
bool

◆ search_other_users()

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

Parameters
string$search
bool$searchanywhere
int$pageStarting at 0
int$perpage
bool$returnexactcountReturn the exact total users using count_record or not.
Return values
arraywith 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.
Exceptions
dml_exception

◆ search_users()

course_enrolment_manager::search_users ( string $search = '',
bool $searchanywhere = false,
int $page = 0,
int $perpage = 25,
bool $returnexactcount = false,
?int $contextid = null )

Searches through the enrolled users in this course.

Parameters
string$searchThe search term.
bool$searchanywhereCan the search term be anywhere, or must it be at the start.
int$pageStarting at 0.
int$perpageNumber of users returned per page.
bool$returnexactcountReturn the exact total users using count_record or not.
?int$contextidContext ID we are in - we might use search on activity level and its group mode can be different from course group mode.
Return values
arraywith 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.

◆ unassign_role_from_user()

moodle_database course_enrolment_manager::unassign_role_from_user ( $userid,
$roleid )

Removes an assigned role from a user.

$DB

Parameters
int$userid
int$roleid
Return values
bool

◆ unenrol_user()

moodle_database course_enrolment_manager::unenrol_user ( $ue)

Unenrols a user from the course given the users ue entry.

$DB

Parameters
stdClass$ue
Return values
bool

The documentation for this class was generated from the following file: