Skip to content

Commit

Permalink
MDL-22787 MDL-21993 New mnetservice plugin type
Browse files Browse the repository at this point in the history
This commit introduces new plugin type called mnetservice. Once the MNet
framework is redesigned, this plugin will define the service itself, the
strings for it and the the client tools for administrator. The server
side is implemented mainly in enrol_mnet plugin which publishes xml-rpc
methods.

AMOS BEGIN
 MOV [remoteenrolhosts_desc,core_mnet],[clientname_help,mnetservice_enrol]
AMOS END
  • Loading branch information
mudrd8mz committed Jul 17, 2010
1 parent 82195aa commit fe73e93
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 66 deletions.
4 changes: 2 additions & 2 deletions admin/settings/mnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
$ADMIN->add('mnet', new admin_externalpage('ssoaccesscontrol', get_string('ssoaccesscontrol', 'mnet'),
"$CFG->wwwroot/$CFG->admin/mnet/access_control.php",
'moodle/site:config'));
$ADMIN->add('mnet', new admin_externalpage('mnetenrol', get_string('mnetenrol', 'mnet'),
"$CFG->wwwroot/$CFG->admin/mnet/enr_hosts.php",
$ADMIN->add('mnet', new admin_externalpage('mnetenrol', get_string('clientname', 'mnetservice_enrol'),
"$CFG->wwwroot/mnet/service/enrol/index.php",
'moodle/site:config'));
$ADMIN->add('mnet', new admin_externalpage('trustedhosts', get_string('trustedhosts', 'mnet'),
"$CFG->wwwroot/$CFG->admin/mnet/trustedhosts.php",
Expand Down
9 changes: 5 additions & 4 deletions enrol/mnet/addinstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
*/

require(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once("$CFG->dirroot/enrol/mnet/addinstance_form.php");
require_once($CFG->dirroot.'/enrol/mnet/addinstance_form.php');
require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');

$id = required_param('id', PARAM_INT); // course id

$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);

require_login($course);
require_capability('moodle/course:enrolconfig', $context); // todo shall the own capability be used?
require_capability('moodle/course:enrolconfig', $context);

$PAGE->set_url('/enrol/mnet/addinstance.php', array('id'=>$course->id));
$PAGE->set_pagelayout('standard');
Expand All @@ -49,8 +50,8 @@
if (!$enrol->get_candidate_link($course->id)) {
redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
}

$mform = new enrol_mnet_addinstance_form(null, array('course'=>$course, 'enrol'=>$enrol));
$service = mnetservice_enrol::get_instance();
$mform = new enrol_mnet_addinstance_form(null, array('course'=>$course, 'enrol'=>$enrol, 'service'=>$service));

if ($mform->is_cancelled()) {
redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
Expand Down
3 changes: 2 additions & 1 deletion enrol/mnet/addinstance_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ function definition() {
$mform = $this->_form;
$course = $this->_customdata['course'];
$enrol = $this->_customdata['enrol'];
$service = $this->_customdata['service'];
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);

$subscribers = $enrol->get_remote_subscribers();
$subscribers = $service->get_remote_subscribers();
$hosts = array(0 => get_string('remotesubscribersall', 'enrol_mnet'));
foreach ($subscribers as $hostid => $subscriber) {
$hosts[$hostid] = $subscriber->appname.': '.$subscriber->hostname.' ('.$subscriber->hosturl.')';
Expand Down
2 changes: 1 addition & 1 deletion enrol/mnet/lang/en/enrol_mnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$string['instancename'] = 'Enrolment method name';
$string['instancename_help'] = 'You can optionally rename this instance of the MNet enrolment method. If you leave this field empty, the default instance name will be used, containing the name of the remote host and the assigned role for their users.';
$string['mnet_enrol_description'] = 'Publish this service to allow administrators at {$a} to enrol their students in courses you have created on your server.<br/><ul><li><em>Dependency</em>: You must also <strong>publish</strong> the SSO (Service Provider) service to {$a}.</li><li><em>Dependency</em>: You must also <strong>subscribe</strong> to the SSO (Identity Provider) service on {$a}.</li></ul><br/>Subscribe to this service to be able to enrol your students in courses on {$a}.<br/><ul><li><em>Dependency</em>: You must also <strong>subscribe</strong> to the SSO (Service Provider) service on {$a}.</li><li><em>Dependency</em>: You must also <strong>publish</strong> the SSO (Identity Provider) service to {$a}.</li></ul><br/>';
$string['mnet_enrol_name'] = 'Moodle Networked Enrolment';
$string['mnet_enrol_name'] = 'Remote enrolment service';
$string['pluginname'] = 'MNet remote enrolments';
$string['pluginname_desc'] = 'Allows remote MNet host to enrol their users into our courses.';
$string['remotesubscriber'] = 'Remote host';
Expand Down
60 changes: 5 additions & 55 deletions enrol/mnet/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
*/
class enrol_mnet_plugin extends enrol_plugin {

/** @var caches the result of {@link get_remote_subscribers()} */
protected $cachesubscribers = null;

////////////////////////////////////////////////////////////////////////////
// Enrolment plugin API - methods required by Moodle core
////////////////////////////////////////////////////////////////////////////

/**
* Returns localised name of enrol instance
*
Expand Down Expand Up @@ -79,65 +72,22 @@ public function get_instance_name($instance) {
* @return moodle_url|null page url or null if instance can not be created
*/
public function get_candidate_link($courseid) {
global $DB;
global $CFG, $DB;
require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');

if (!$this->mnet_available()) {
$service = mnetservice_enrol::get_instance();
if (!$service->is_available()) {
return null;
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
if (!has_capability('moodle/course:enrolconfig', $coursecontext)) {
return null;
}
$subscribers = $this->get_remote_subscribers();
$subscribers = $service->get_remote_subscribers();
if (empty($subscribers)) {
return null;
}

return new moodle_url('/enrol/mnet/addinstance.php', array('id'=>$courseid));
}

////////////////////////////////////////////////////////////////////////////
// Internal methods used by the plugin itself only
////////////////////////////////////////////////////////////////////////////

/**
* 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.
*
* @return array
*/
public function get_remote_subscribers() {
global $DB;

if (is_null($this->cachesubscribers)) {
$sql = "SELECT DISTINCT h.id, h.name AS hostname, h.wwwroot AS hosturl,
a.display_name AS appname
FROM {mnet_host} h
JOIN {mnet_host2service} hs ON h.id = hs.hostid
JOIN {mnet_service} s ON hs.serviceid = s.id
JOIN {mnet_application} a ON h.applicationid = a.id
WHERE s.name = 'mnet_enrol'
AND hs.publish = 1";
$this->cachesubscribers = $DB->get_records_sql($sql);
}

return $this->cachesubscribers;
}

/**
* Is MNet networking enabled at this server?
*
* @return bool
*/
protected function mnet_available() {
global $CFG;

if (empty($CFG->mnet_dispatcher_mode) || $CFG->mnet_dispatcher_mode !== 'strict') {
return false;
}
return true;
}

}
3 changes: 0 additions & 3 deletions lang/en/mnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@
$string['registerhostsoff'] = 'Register all hosts is currently <b>off</b>';
$string['registerhostson'] = 'Register all hosts is currently <b>on</b>';
$string['remotecourses'] = 'Remote Courses';
$string['remoteenrolhosts_desc'] = 'Enrol and unenrol users from your Moodle installation
on Moodle Hosts that allow you to do so via the Moodle
Network enrolment plugin.';
$string['remotehost'] = 'Remote Hub';
$string['remotehosts'] = 'Remote hosts';
$string['remotemoodles'] = 'Remote Moodles';
Expand Down
1 change: 1 addition & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6905,6 +6905,7 @@ function get_plugin_types($fullpaths=true) {
'gradeexport' => 'grade/export',
'gradeimport' => 'grade/import',
'gradereport' => 'grade/report',
'mnetservice' => 'mnet/service',
'webservice' => 'webservice',
'repository' => 'repository',
'portfolio' => 'portfolio',
Expand Down
68 changes: 68 additions & 0 deletions mnet/service/enrol/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Displays the list of remote peers we can enrol our users to
*
* @package mnetservice
* @subpackage enrol
* @copyright 2010 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');

admin_externalpage_setup('mnetenrol');
$service = mnetservice_enrol::get_instance();

echo $OUTPUT->header();
echo $OUTPUT->heading_with_help(get_string('clientname', 'mnetservice_enrol'), 'clientname', 'mnetservice_enrol');

if (!$service->is_available()) {
echo $OUTPUT->box(get_string('mnetdisabled','mnet'), 'noticebox');
echo $OUTPUT->footer();
die();
}

// remote hosts that may publish remote enrolment service and we are subscribed to it
$hosts = $service->get_remote_publishers();

if (empty($hosts)) {
echo $OUTPUT->box(get_string('nopublishers', 'mnetservice_enrol'), 'noticebox');
echo $OUTPUT->footer();
die();
}

$table = new html_table();
$table->attributes['class'] = 'generaltable remotehosts';
$table->head = array(
get_string('hostappname', 'mnetservice_enrol'),
get_string('hostname', 'mnetservice_enrol'),
get_string('hosturl', 'mnetservice_enrol'),
get_string('action')
);
foreach ($hosts as $host) {
$hostlink = html_writer::link(new moodle_url($host->hosturl), s($host->hosturl));
$editlink = html_writer::link(new moodle_url('/mnet/service/enrol/host.php', array('id'=>$host->id)),
get_string('editenrolments', 'mnetservice_enrol'));
$table->data[] = array(s($host->appname), s($host->hostname), $hostlink, $editlink);
}
echo html_writer::table($table);

echo $OUTPUT->footer();
34 changes: 34 additions & 0 deletions mnet/service/enrol/lang/en/mnetservice_enrol.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package mnetservice
* @subpackage enrolment
* @copyright 2010 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$string['clientname'] = 'Remote enrolments client';
$string['clientname_help'] = 'This tool allows you to enrol and unenrol your local users on remote hosts that allow you to do so via the \'MNet remote enrolments\' plugin.';
$string['editenrolments'] = 'Edit enrolments';
$string['hostappname'] = 'Application';
$string['hostname'] = 'Host name';
$string['hosturl'] = 'Remote host URL';
$string['nopublishers'] = 'No remote peers available.';
$string['pluginname'] = 'Remote enrolment service';
Loading

0 comments on commit fe73e93

Please sign in to comment.