From d5bd0b0169cf3d6034d9428cdb1558324e965381 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Sat, 17 Jul 2010 22:29:28 +0000 Subject: [PATCH] MDL-22787 MNet: implementation of enrol_mnet server-side service methods --- enrol/mnet/db/mnet.php | 52 ++++++++++++++++++ enrol/mnet/enrol.php | 117 +++++++++++++++++++++++++++++++++++++++++ enrol/mnet/version.php | 2 +- lib/upgradelib.php | 2 + 4 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 enrol/mnet/db/mnet.php create mode 100644 enrol/mnet/enrol.php diff --git a/enrol/mnet/db/mnet.php b/enrol/mnet/db/mnet.php new file mode 100644 index 00000000000..10deee7a3be --- /dev/null +++ b/enrol/mnet/db/mnet.php @@ -0,0 +1,52 @@ +. + +/** + * This file contains the mnet services for the mnet enrolment plugin + * + * If we rewrite MNet as proposed in MDL-21993 this file would contain + * just a declaration of xml-rpc methods that this plugin publishes. + * + * @since 2.0 + * @package enrol + * @subpackage mnet + * @copyright 2010 Penny Leach + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$publishes = array( + 'mnet_enrol' => array( + 'apiversion' => 1, + 'classname' => 'enrol_mnet_mnetservice_enrol', + 'filename' => 'enrol.php', + 'methods' => array( + 'available_courses', + 'user_enrolments', + 'enrol_user', + 'unenrol_user', + 'course_enrolments' + ), + ), +); +$subscribes = array( + 'mnet_enrol' => array( + 'available_courses' => 'enrol/mnet/enrol.php/available_courses', + 'user_enrolments' => 'enrol/mnet/enrol.php/user_enrolments', + 'enrol_user' => 'enrol/mnet/enrol.php/enrol_user', + 'unenrol_user' => 'enrol/mnet/enrol.php/unenrol_user', + 'course_enrolments' => 'enrol/mnet/enrol.php/course_enrolments', + ), +); diff --git a/enrol/mnet/enrol.php b/enrol/mnet/enrol.php new file mode 100644 index 00000000000..83fceb18691 --- /dev/null +++ b/enrol/mnet/enrol.php @@ -0,0 +1,117 @@ +. + +/** + * 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. + * + * @package enrol + * @subpackage mnet + * @copyright 2010 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); +defined('MNET_SERVER') || die(); + +/** + * 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. + */ +class enrol_mnet_mnetservice_enrol { + + /** + * 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. + * + * @uses mnet_remote_client Callable via XML-RPC only + * @return array + */ + public function available_courses() { + global $DB; + + if (!$client = get_mnet_remote_client()) { + die('Callable via XML-RPC only'); + } + + $sql = "SELECT c.id AS remoteid, c.fullname, c.shortname, c.idnumber, c.summary, c.summaryformat, + c.sortorder, c.startdate, cat.id AS cat_id, cat.name AS cat_name, + cat.description AS cat_description, cat.descriptionformat AS cat_descriptionformat, + e.cost, e.currency, e.roleid AS defaultroleid, r.name + FROM {enrol} e + INNER JOIN {course} c ON c.id = e.courseid + INNER JOIN {course_categories} cat ON cat.id = c.category + INNER JOIN {role} r ON r.id = e.roleid + WHERE e.enrol = 'mnet' + AND (e.customint1 = 0 OR e.customint1 = ?) + AND c.visible = 1 + ORDER BY cat.sortorder, c.sortorder, c.shortname"; + + return $DB->get_records_sql($sql, array($client->id)); + } + + /** + * TODO: short description. + * + * @return TODO + */ + public function user_enrolments() { + return array(); + } + + /** + * TODO: short description. + * + * @return TODO + */ + public function enrol_user() { + return false; + } + + /** + * TODO: short description. + * + * @return TODO + */ + public function unenrol_user() { + return false; + } + + /** + * TODO: short description. + * + * @return TODO + */ + public function course_enrolments() { + return array(); + } +} diff --git a/enrol/mnet/version.php b/enrol/mnet/version.php index dfbb7b2a221..1800682a9fd 100644 --- a/enrol/mnet/version.php +++ b/enrol/mnet/version.php @@ -24,4 +24,4 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$plugin->version = 2010071500; +$plugin->version = 2010071603; diff --git a/lib/upgradelib.php b/lib/upgradelib.php index bc9c37c8512..ff294a0a769 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -1429,6 +1429,8 @@ function upgrade_plugin_mnet_functions($component) { $dataobject->id = $DB->insert_record('mnet_rpc', $dataobject, true); } + // TODO this API versioning must be reworked, here the recently processed method + // sets the service API which may not be correct foreach ($publishmethodservices[$dataobject->functionname] as $service) { if ($serviceobj = $DB->get_record('mnet_service', array('name'=>$service['servicename']))) { $serviceobj->apiversion = $service['apiversion'];