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.

Implements the XML-RPC methods this plugin publishes to MNet peers This file must be named enrol.php because current MNet framework has the filename hardcoded in XML-RPC path and we want to be compatible with Moodle 1.x MNet clients. There is a proposal in MDL-21993 to allow map XMP-RPC calls to whatever file, function, class or methods. Once this is fixed, this file will be probably renamed to mnetlib.php (which could be a common name of a plugin library containing functions/methods callable via MNet framework.

Copyright: 2010 David Mudrak <david@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 357 lines (15 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 1 file
 enrol/mnet/lib.php

Defines 1 class

enrol_mnet_mnetservice_enrol:: (5 methods):
  available_courses()
  user_enrolments()
  enrol_user()
  unenrol_user()
  course_enrolments()


Class: enrol_mnet_mnetservice_enrol  - X-Ref

MNet server-side methods that are part of mnetservice_enrol

The weird name of the class tries to follow a pattern
{plugintype}_{pluginnname}_mnetservice_{servicename}

Class methods are compatible with API 1 of the service used by Moodle 1.x
and 2.0 peers. The API version might become a part of class name but it is
not neccessary due to how xml-rcp methods are/will be mapped to php methods.
available_courses()   X-Ref
Returns list of courses that we offer to the caller for remote enrolment of their users

Since Moodle 2.0, courses are made available for MNet peers by creating an instance
of enrol_mnet plugin for the course. Hidden courses are not returned. If there are two
instances - one specific for the host and one for 'All hosts', the setting of the specific
one is used. The id of the peer is kept in customint1, no other custom fields are used.

return: array

user_enrolments()   X-Ref
This method has never been implemented in Moodle MNet API

return: array empty array

enrol_user(array $userdata, $courseid)   X-Ref
Enrol remote user to our course

If we do not have local record for the remote user in our database,
it gets created here.

param: array $userdata user details {@see mnet_fields_to_import()}
param: int $courseid our local course id
return: bool true if the enrolment has been successful, throws exception otherwise

unenrol_user($username, $courseid)   X-Ref
Unenrol remote user from our course

Only users enrolled via enrol_mnet plugin can be unenrolled remotely. If the
remote user is enrolled into the local course via some other enrol plugin
(enrol_manual for example), the remote host can't touch such enrolment. Please
do not report this behaviour as bug, it is a feature ;-)

param: string $username of the remote user
param: int $courseid of our local course
return: bool true if the unenrolment has been successful, throws exception otherwise

course_enrolments($courseid, $roles=null)   X-Ref
Returns a list of users from the client server who are enrolled in our course

Suitable instance of enrol_mnet must be created in the course. This method will not
return any information about the enrolments in courses that are not available for
remote enrolment, even if their users are enrolled into them via other plugin
(note the difference from {@link self::user_enrolments()}).

This method will return enrolment information for users from hosts regardless
the enrolment plugin. It does not matter if the user was enrolled remotely by
their admin or locally. Once the course is available for remote enrolments, we
will tell them everything about their users.

In Moodle 1.x the returned array used to be indexed by username. The side effect
of MDL-19219 fix is that we do not need to use such index and therefore we can
return all enrolment records. MNet clients 1.x will only use the last record for
the student, if she is enrolled via multiple plugins.

param: int $courseid ID of our course
param: string|array $roles comma separated list of role shortnames (or array of them)
return: array