Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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: 529 lines (19 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

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.