Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Flatfile enrolment plugin. This plugin lets the user specify a "flatfile" (CSV) containing enrolment information. On a regular cron cycle, the specified file is parsed and then deleted.

Copyright: 2010 Eugene Venter
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 696 lines (29 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: enrol_flatfile_plugin  - X-Ref

Flatfile enrolment plugin implementation.

Comma separated file assumed to have four or six fields per line:
operation, role, idnumber(user), idnumber(course) [, starttime [, endtime]]
where:
operation        = add | del
role             = student | teacher | teacheredit
idnumber(user)   = idnumber in the user table NB not id
idnumber(course) = idnumber in the course table NB not id
starttime        = start time (in seconds since epoch) - optional
endtime          = end time (in seconds since epoch) - optional

roles_protected()   X-Ref
Does this plugin assign protected roles are can they be manually removed?

return: bool - false means anybody may tweak roles, it does not use itemid and component when assigning roles

allow_unenrol(stdClass $instance)   X-Ref
Does this plugin allow manual unenrolment of all users?
All plugins allowing this must implement 'enrol/xxx:unenrol' capability

param: stdClass $instance course enrol instance
return: bool - true means user with 'enrol/xxx:unenrol' may unenrol others freely, false means nobody may touch user_enrolments

allow_unenrol_user(stdClass $instance, stdClass $ue)   X-Ref
Does this plugin allow manual unenrolment of a specific user?
All plugins allowing this must implement 'enrol/xxx:unenrol' capability

This is useful especially for synchronisation plugins that
do suspend instead of full unenrolment.

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

allow_manage(stdClass $instance)   X-Ref
Does this plugin allow manual changes in user_enrolments table?

All plugins allowing this must implement 'enrol/xxx:manage' capability

param: stdClass $instance course enrol instance
return: bool - true means it is possible to change enrol period and status in user_enrolments table

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

param: object $instance
return: bool

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

param: stdClass $instance
return: bool

enrol_user(stdClass $instance, $userid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null)   X-Ref
Enrol user into course via enrol instance.

param: stdClass $instance
param: int $userid
param: int $roleid optional role id
param: int $timestart 0 means unknown
param: int $timeend 0 means forever
param: int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
param: bool $recovergrades restore grade history
return: void

sync(progress_trace $trace)   X-Ref
Execute synchronisation.

param: progress_trace
return: int exit code, 0 means ok, 2 means plugin disabled

obfuscate_filepath($filepath)   X-Ref
Sorry, we do not want to show paths in cron output.

param: string $filepath
return: string

process_file(progress_trace $trace)   X-Ref
Process flatfile.

param: progress_trace $trace
return: bool true if any data processed, false if not

process_buffer(progress_trace $trace)   X-Ref
Process any future enrollments stored in the buffer.

param: progress_trace $trace
return: bool true if any data processed, false if not

process_records(progress_trace $trace, $action, $roleid, $user, $course, $timestart, $timeend, $buffer_if_future = true)   X-Ref
Process user enrolment line.

param: progress_trace $trace
param: string $action
param: int $roleid
param: stdClass $user
param: stdClass $course
param: int $timestart
param: int $timeend
param: bool $buffer_if_future

get_enroller($courseid)   X-Ref
Returns the user who is responsible for flatfile enrolments in given curse.

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

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

get_role_map(progress_trace $trace)   X-Ref
Returns a mapping of ims roles to role ids.

param: progress_trace $trace
return: array imsrolename=>roleid

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