Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

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

Cohort 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: 681 lines (25 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: enrol_cohort_plugin  - X-Ref

Cohort enrolment plugin implementation.

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

param: stdClass $instance
return: bool

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

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

can_add_instance($courseid)   X-Ref
Given a courseid this function returns true if the user is able to enrol or configure cohorts.
AND there are cohorts that the user can view.

param: int $courseid
return: bool

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

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

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

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

course_updated($inserted, $course, $data)   X-Ref
Called after updating/inserting course.

param: bool $inserted true if course just inserted
param: stdClass $course
param: stdClass $data form data
return: void

update_status($instance, $newstatus)   X-Ref
Update instance status

param: stdClass $instance
param: int $newstatus ENROL_INSTANCE_ENABLED, ENROL_INSTANCE_DISABLED
return: void

allow_unenrol_user(stdClass $instance, stdClass $ue)   X-Ref
Does this plugin allow manual unenrolment of a specific user?
Yes, but only if user suspended...

param: stdClass $instance course enrol instance
param: stdClass $ue record from user_enrolments table
return: bool - true means user with 'enrol/xxx:unenrol' may unenrol this user, false means nobody may touch this user enrolment

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_group_member($instance, $groupid, $userid)   X-Ref
Restore user group membership.

param: stdClass $instance
param: int $groupid
param: int $userid

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

param: stdClass $instance
return: bool

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

return: array

get_cohort_options($instance, $context)   X-Ref
Return an array of valid options for the cohorts.

param: stdClass $instance
param: context $context
return: array

get_role_options($instance, $coursecontext)   X-Ref
Return an array of valid options for the roles.

param: stdClass $instance
param: context $coursecontext
return: array

get_group_options($coursecontext)   X-Ref
Return an array of valid options for the groups.

param: context $coursecontext
return: array

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_form($instance, MoodleQuickForm $mform, $coursecontext)   X-Ref
Add elements to the edit instance form.

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

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

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
return: array of "element_name" => "error_description" if there are errors,
return: void

validate_enrol_plugin_data(array $enrolmentdata, ?int $courseid = null)   X-Ref
Check if data is valid for a given enrolment plugin

param: array $enrolmentdata enrolment data to validate.
param: int|null $courseid Course ID.
return: array Errors

fill_enrol_custom_fields(array $enrolmentdata, int $courseid)   X-Ref
Fill custom fields data for a given enrolment plugin.

param: array $enrolmentdata enrolment data.
param: int $courseid Course ID.
return: array Updated enrolment data with custom fields info.

validate_plugin_data_context(array $enrolmentdata, ?int $courseid = null)   X-Ref
Check if plugin custom data is allowed in relevant context.

param: array $enrolmentdata enrolment data to validate.
param: int|null $courseid Course ID.
return: lang_string|null Error

add_custom_instance(stdClass $course, ?array $fields = null)   X-Ref
Add new instance of enrol plugin with custom settings,
called when adding new instance manually or when adding new course.
Used for example on course upload.

Not all plugins support this.

param: stdClass $course Course object
param: array|null $fields instance fields
return: int|null id of new instance or null if not supported

is_csv_upload_supported()   X-Ref
Check if enrolment plugin is supported in csv course upload.

return: bool

enrol_cohort_allow_group_member_remove($itemid, $groupid, $userid)   X-Ref
Prevent removal of enrol roles.

param: int $itemid
param: int $groupid
param: int $userid
return: bool

enrol_cohort_create_new_group($courseid, $cohortid)   X-Ref
Create a new group with the cohorts name.

param: int $courseid
param: int $cohortid
return: int $groupid Group ID for this cohort.