Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
mnetservice_enrol Class Reference

Singleton providing various functionality usable by plugin(s) implementing this MNet service. More...

Public Member Functions

 format_error_message ($errormsg)
 Prepares error messages returned by our XML-RPC requests to be send as debug info to print_error(). More...
 
 get_remote_courses ($mnethostid, $usecache=true)
 Fetches the information about the courses available on remote host for our students. More...
 
 get_remote_publishers ()
 Returns a list of remote servers that offer their courses for our users. More...
 
 get_remote_subscribers ()
 Returns a list of remote servers that can enrol their users into our courses. More...
 
 is_available ()
 Is this service enabled? More...
 
 req_course_enrolments ($mnethostid, $remotecourseid)
 Updates local cache about enrolments of our users in remote courses. More...
 
 req_enrol_user (stdclass $user, stdclass $remotecourse)
 Send request to enrol our user to the remote course. More...
 
 req_unenrol_user (stdclass $user, stdclass $remotecourse)
 Send request to unenrol our user from the remote course. More...
 

Static Public Member Functions

static get_instance ()
 

Protected Member Functions

 __construct ()
 This is singleton, use mnetservice_enrol::get_instance().
 

Protected Attributes

caches $cachepublishers = null
 the result of self::get_remote_publishers()
 
caches $cachesubscribers = null
 the result of self::get_remote_subscribers()
 

Static Protected Attributes

static mnetservice_enrol $singleton
 holds the singleton instance.
 

Detailed Description

Singleton providing various functionality usable by plugin(s) implementing this MNet service.

Member Function Documentation

◆ format_error_message()

mnetservice_enrol::format_error_message (   $errormsg)

Prepares error messages returned by our XML-RPC requests to be send as debug info to print_error().

MNet client-side methods in this class return request error as serialized array.

Parameters
string$errorserialized array
Return values
string

◆ get_instance()

static mnetservice_enrol::get_instance ( )
static
Return values
mnetservice_enrolsingleton instance

◆ get_remote_courses()

mnetservice_enrol::get_remote_courses (   $mnethostid,
  $usecache = true 
)

Fetches the information about the courses available on remote host for our students.

The information about remote courses available for us is cached in {mnetservice_enrol_courses}. This method either returns the cached information (typically when displaying the list to students) or fetch fresh data via new XML-RPC request (which updates the local cache, too). The lifetime of the cache is 1 day, so even if $usecache is set to true, the cache will be re-populated if we did not fetch from any server (not only the currently requested one) for some time.

Parameters
id$mnethostidMNet remote host id
bool$usecacheuse cached data or invoke new XML-RPC? @uses mnet_xmlrpc_client Invokes XML-RPC request if the cache is not used
Return values
array|stringreturned list or serialized array of mnet error messages

◆ get_remote_publishers()

mnetservice_enrol::get_remote_publishers ( )

Returns a list of remote servers that offer their courses for our users.

We must subscribe MNet service 'mnet_enrol' for the peers to allow our users to enrol into their courses.

Todo:

once the MNet core is refactored this may be part of a parent class

the name of the service should be changed to the name of this plugin

Return values
array

◆ get_remote_subscribers()

mnetservice_enrol::get_remote_subscribers ( )

Returns a list of remote servers that can enrol their users into our courses.

We must publish MNet service 'mnet_enrol' for the peers to allow them to enrol their users into our courses.

Todo:

once the MNet core is refactored this may be part of a parent class

the name of the service should be changed to the name of this plugin

Return values
array

◆ is_available()

mnetservice_enrol::is_available ( )

Is this service enabled?

Currently, this checks if whole MNet is available. In the future, additional checks can be done. Probably the field 'offer' should be checked but it does not seem to be used so far.

Todo:
move this to some parent class once we have such
Return values
bool

◆ req_course_enrolments()

mnetservice_enrol::req_course_enrolments (   $mnethostid,
  $remotecourseid 
)

Updates local cache about enrolments of our users in remote courses.

The remote course must allow enrolments via our Remote enrolment service client. Because of legacy design of data structure returned by XML-RPC code, only one user enrolment per course is returned by 1.9 MNet servers. This may be an issue if the user is enrolled multiple times by various enrolment plugins. MNet 2.0 servers do not use user name as array keys - they do not need to due to side effect of MDL-19219.

Parameters
id$mnethostidMNet remote host id
int$remotecourseidID of the course at the remote host
bool$usecacheuse cached data or invoke new XML-RPC? @uses mnet_xmlrpc_client Invokes XML-RPC request
Return values
bool|stringtrue if success or serialized array of mnet error messages

◆ req_enrol_user()

mnetservice_enrol::req_enrol_user ( stdclass  $user,
stdclass  $remotecourse 
)

Send request to enrol our user to the remote course.

Updates our remote enrolments cache if the enrolment was successful.

@uses mnet_xmlrpc_client Invokes XML-RPC request

Parameters
object$userour user
object$remotecourserecord from mnetservice_enrol_courses table
Return values
true|stringtrue if success, error message from the remote host otherwise

◆ req_unenrol_user()

mnetservice_enrol::req_unenrol_user ( stdclass  $user,
stdclass  $remotecourse 
)

Send request to unenrol our user from the remote course.

Updates our remote enrolments cache if the unenrolment was successful.

@uses mnet_xmlrpc_client Invokes XML-RPC request

Parameters
object$userour user
object$remotecourserecord from mnetservice_enrol_courses table
Return values
true|stringtrue if success, error message from the remote host otherwise

The documentation for this class was generated from the following file: