Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/enrol/self/ -> lib.php (source)

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

Self enrolment plugin.

Copyright: 2010 Petr Skoda {@link http://skodak.org}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1080 lines (43 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: enrol_self_plugin  - X-Ref

Self enrolment plugin implementation.

get_info_icons(array $instances)   X-Ref
Returns optional enrolment information icons.

This is used in course list for quick overview of enrolment options.

We are not using single instance parameter because sometimes
we might want to prevent icon repetition when multiple instances
of one type exist. One instance may also produce several icons.

return: array of pix_icon
param: array $instances all enrol instances of this type in one course

get_instance_name($instance)   X-Ref
Returns localised name of enrol instance

return: string
param: stdClass $instance (null is accepted too)

roles_protected()   X-Ref
No description

allow_unenrol(stdClass $instance)   X-Ref
No description

allow_manage(stdClass $instance)   X-Ref
No description

show_enrolme_link(stdClass $instance)   X-Ref
No description

can_add_instance($courseid)   X-Ref
Return true if we can add a new instance to this course.

return: boolean
param: int $courseid

enrol_self(stdClass $instance, $data = null)   X-Ref
Self enrol user to course

return: bool|array true if enroled else eddor code and messege
param: stdClass $instance enrolment instance
param: stdClass $data data needed for enrolment.

enrol_page_hook(stdClass $instance)   X-Ref
Creates course enrol form, checks if form submitted
and enrols user if necessary. It can also redirect.

return: string html text, usually a form in a text box
param: stdClass $instance

can_self_enrol(stdClass $instance, $checkuserenrolment = true)   X-Ref
Checks if user can self enrol.

return: bool|string true if successful, else error message or false.
param: stdClass $instance enrolment instance
param: bool $checkuserenrolment if true will check if user enrolment is inactive.

is_self_enrol_available(stdClass $instance)   X-Ref
Does this plugin support some way to self enrol?
This function doesn't check user capabilities. Use can_self_enrol to check capabilities.

return: bool - true means "Enrol me in this course" link could be available
param: stdClass $instance enrolment instance

get_enrol_info(stdClass $instance)   X-Ref
Return information for enrolment instance containing list of parameters required
for enrolment, name of enrolment plugin etc.

return: stdClass instance info.
param: stdClass $instance enrolment instance

add_default_instance($course)   X-Ref
Add new instance of enrol plugin with default settings.

return: int id of new instance
param: stdClass $course

get_instance_defaults()   X-Ref
Returns defaults for new instances.

return: array

email_welcome_message($instance, $user)   X-Ref
Send welcome email to specified user.

return: void
param: stdClass $instance
param: stdClass $user user record

sync(progress_trace $trace, $courseid = null)   X-Ref
Sync all meta course links.

return: int 0 means ok, 1 means error, 2 means plugin disabled
param: progress_trace $trace
param: int $courseid one course, empty mean all

get_enroller($instanceid)   X-Ref
Returns the user who is responsible for self enrolments in given instance.

Usually it is the first editing teacher - the person with "highest authority"
as defined by sort_by_roleassignment_authority() having 'enrol/self:manage'
capability.

return: stdClass user record
param: int $instanceid enrolment instance id

restore_instance(restore_enrolments_structure_step $step, stdClass $data, $course, $oldid)   X-Ref
Restore instance and map settings.

param: restore_enrolments_structure_step $step
param: stdClass $data
param: stdClass $course
param: int $oldid

restore_user_enrolment(restore_enrolments_structure_step $step, $data, $instance, $userid, $oldinstancestatus)   X-Ref
Restore user enrolment.

param: restore_enrolments_structure_step $step
param: stdClass $data
param: stdClass $instance
param: int $oldinstancestatus
param: int $userid

restore_role_assignment($instance, $roleid, $userid, $contextid)   X-Ref
Restore role assignment.

param: stdClass $instance
param: int $roleid
param: int $userid
param: int $contextid

can_delete_instance($instance)   X-Ref
Is it possible to delete enrol instance via standard UI?

return: bool
param: stdClass $instance

can_hide_show_instance($instance)   X-Ref
Is it possible to hide/show enrol instance via standard UI?

return: bool
param: stdClass $instance

get_status_options()   X-Ref
Return an array of valid options for the status.

return: array

get_newenrols_options()   X-Ref
Return an array of valid options for the newenrols property.

return: array

get_groupkey_options()   X-Ref
Return an array of valid options for the groupkey property.

return: array

get_expirynotify_options()   X-Ref
Return an array of valid options for the expirynotify property.

return: array

get_longtimenosee_options()   X-Ref
Return an array of valid options for the longtimenosee property.

return: array

get_bulk_operations(course_enrolment_manager $manager)   X-Ref
The self enrollment plugin has several bulk operations that can be performed.

return: array
param: course_enrolment_manager $manager

edit_instance_form($instance, MoodleQuickForm $mform, $context)   X-Ref
Add elements to the edit instance form.

return: bool
param: stdClass $instance
param: MoodleQuickForm $mform
param: context $context

use_standard_editing_ui()   X-Ref
We are a good plugin and don't invent our own UI/validation code path.

return: boolean

edit_instance_validation($data, $files, $instance, $context)   X-Ref
Perform custom validation of the data used to edit the instance.

return: array of "element_name"=>"error_description" if there are errors,
return: void
param: array $data array of ("fieldname"=>value) of submitted data
param: array $files array of uploaded files "element_name"=>tmp_file_path
param: object $instance The instance loaded from the DB
param: context $context The context of the instance we are editing

add_instance($course, array $fields = null)   X-Ref
Add new instance of enrol plugin.

return: int id of new instance, null if can not be created
param: object $course
param: array $fields instance fields

update_instance($instance, $data)   X-Ref
Update instance of enrol plugin.

return: boolean
param: stdClass $instance
param: stdClass $data modified instance fields

extend_assignable_roles($context, $defaultrole)   X-Ref
Gets a list of roles that this user can assign for the course as the default for self-enrolment.

return: array index is the role id, value is the role name
param: context $context the context.
param: integer $defaultrole the id of the role that is set as the default for self-enrolment

get_welcome_email_contact($sendoption, $context)   X-Ref
Get the "from" contact which the email will be sent from.

return: mixed|stdClass the contact user object.
param: int $sendoption send email from constant ENROL_SEND_EMAIL_FROM_*
param: $context context where the user will be fetched

enrol_self_get_fontawesome_icon_map()   X-Ref
Get icon mapping for font-awesome.