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.
/enrol/ldap/ -> lib.php (source)

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]

LDAP enrolment plugin implementation.

Author: Iñaki Arenaza - based on code by Martin Dougiamas, Martin Langhoff and others
Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
Copyright: 2010 Iñaki Arenaza <iarenaza@eps.mondragon.edu>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1243 lines (62 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class


Class: enrol_ldap_plugin  - X-Ref

__construct()   X-Ref
Constructor for the plugin. In addition to calling the parent
constructor, we define and 'fix' some settings depending on the
real settings the admin defined.


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

sync_user_enrolments($user)   X-Ref
Forces synchronisation of user enrolments with LDAP server.
It creates courses if the plugin is configured to do so.

param: object $user user record
return: void

sync_enrolments(progress_trace $trace, $onecourse = null)   X-Ref
Forces synchronisation of all enrolments with LDAP server.
It creates courses if the plugin is configured to do so.

param: progress_trace $trace
param: int|null $onecourse limit sync to one course->id, null if all courses
return: void

ldap_connect(progress_trace $trace = null)   X-Ref
Connect to the LDAP server, using the plugin configured
settings. It's actually a wrapper around ldap_connect_moodle()

param: progress_trace $trace
return: bool success

ldap_close()   X-Ref
Disconnects from a LDAP server


find_ext_enrolments($memberuid, $role)   X-Ref
Return multidimensional array with details of user courses (at
least dn and idnumber).

param: string $memberuid user idnumber (without magic quotes).
param: object role is a record from the mdl_role table.
return: array

ldap_find_userdn($userid)   X-Ref
Search specified contexts for the specified userid and return the
user dn like: cn=username,ou=suborg,o=org. It's actually a wrapper
around ldap_find_userdn().

param: string $userid the userid to search for (in external LDAP encoding, no magic quotes).
return: mixed the user dn or false

ldap_find_user_groups($memberdn)   X-Ref
Find the groups a given distinguished name belongs to, both directly
and indirectly via nested groups membership.

param: string $memberdn distinguished name to search
return: array with member groups' distinguished names (can be emtpy)

ldap_find_user_groups_recursively($memberdn, &$membergroups)   X-Ref
Recursively process the groups the given member distinguished name
belongs to, adding them to the already processed groups array.

param: string $memberdn distinguished name to search
param: array reference &$membergroups array with already found

ldap_explode_group($group, $memberattribute)   X-Ref
Given a group name (either a RDN or a DN), get the list of users
belonging to that group. If the group has nested groups, expand all
the intermediate groups and return the full list of users that
directly or indirectly belong to the group.

param: string $group the group name to search
param: string $memberattibute the attribute that holds the members of the group
return: array the list of users belonging to the group. If $group

create_course($course_ext, progress_trace $trace)   X-Ref
Will create the moodle course from the template
course_ext is an array as obtained from ldap -- flattened somewhat

param: array $course_ext
param: progress_trace $trace
return: mixed false on error, id for the newly created course otherwise.

update_course($course, $externalcourse, progress_trace $trace)   X-Ref
Will update a moodle course with new values from LDAP
A field will be updated only if it is marked to be updated
on sync in plugin settings

param: object $course
param: array $externalcourse
param: progress_trace $trace
return: bool

restore_sync_course($course)   X-Ref
Automatic enrol sync executed during restore.
Useful for automatic sync by course->idnumber or course category.

param: stdClass $course course record

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