mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-22787 Instances of enrol_mnet can be added to the course
This commit is contained in:
parent
6f948538bb
commit
82195aaefe
68
enrol/mnet/addinstance.php
Normal file
68
enrol/mnet/addinstance.php
Normal file
@ -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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds new instance of enrol_mnet into the specified course
|
||||||
|
*
|
||||||
|
* @package enrol
|
||||||
|
* @subpackage mnet
|
||||||
|
* @copyright 2010 David Mudrak <david@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
require(dirname(dirname(dirname(__FILE__))).'/config.php');
|
||||||
|
require_once("$CFG->dirroot/enrol/mnet/addinstance_form.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?
|
||||||
|
|
||||||
|
$PAGE->set_url('/enrol/mnet/addinstance.php', array('id'=>$course->id));
|
||||||
|
$PAGE->set_pagelayout('standard');
|
||||||
|
|
||||||
|
// Try and make the manage instances node on the navigation active
|
||||||
|
$courseadmin = $PAGE->settingsnav->get('courseadmin');
|
||||||
|
if ($courseadmin && $courseadmin->get('users') && $courseadmin->get('users')->get('manageinstances')) {
|
||||||
|
$courseadmin->get('users')->get('manageinstances')->make_active();
|
||||||
|
}
|
||||||
|
|
||||||
|
$enrol = enrol_get_plugin('mnet');
|
||||||
|
// make sure we were allowed to get here form the Enrolment methods page
|
||||||
|
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));
|
||||||
|
|
||||||
|
if ($mform->is_cancelled()) {
|
||||||
|
redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
|
||||||
|
|
||||||
|
} else if ($data = $mform->get_data()) {
|
||||||
|
$enrol->add_instance($course, array('customint1'=>$data->hostid, 'roleid'=>$data->roleid, 'name'=>$data->name));
|
||||||
|
redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
$PAGE->set_heading($course->fullname);
|
||||||
|
$PAGE->set_title(get_string('pluginname', 'enrol_mnet'));
|
||||||
|
|
||||||
|
echo $OUTPUT->header();
|
||||||
|
$mform->display();
|
||||||
|
echo $OUTPUT->footer();
|
87
enrol/mnet/addinstance_form.php
Normal file
87
enrol/mnet/addinstance_form.php
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form to add an instance of enrol_mnet plugin
|
||||||
|
*
|
||||||
|
* @package enrol
|
||||||
|
* @subpackage mnet
|
||||||
|
* @copyright 2010 David Mudrak <david@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die;
|
||||||
|
|
||||||
|
require_once("$CFG->libdir/formslib.php");
|
||||||
|
|
||||||
|
class enrol_mnet_addinstance_form extends moodleform {
|
||||||
|
function definition() {
|
||||||
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
$mform = $this->_form;
|
||||||
|
$course = $this->_customdata['course'];
|
||||||
|
$enrol = $this->_customdata['enrol'];
|
||||||
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||||
|
|
||||||
|
$subscribers = $enrol->get_remote_subscribers();
|
||||||
|
$hosts = array(0 => get_string('remotesubscribersall', 'enrol_mnet'));
|
||||||
|
foreach ($subscribers as $hostid => $subscriber) {
|
||||||
|
$hosts[$hostid] = $subscriber->appname.': '.$subscriber->hostname.' ('.$subscriber->hosturl.')';
|
||||||
|
}
|
||||||
|
$roles = get_assignable_roles($coursecontext);
|
||||||
|
|
||||||
|
$mform->addElement('header','general', get_string('pluginname', 'enrol_mnet'));
|
||||||
|
|
||||||
|
$mform->addElement('select', 'hostid', get_string('remotesubscriber', 'enrol_mnet'), $hosts);
|
||||||
|
$mform->addHelpButton('hostid', 'remotesubscriber', 'enrol_mnet');
|
||||||
|
$mform->addRule('hostid', get_string('required'), 'required', null, 'client');
|
||||||
|
|
||||||
|
$mform->addElement('select', 'roleid', get_string('roleforremoteusers', 'enrol_mnet'), $roles);
|
||||||
|
$mform->addHelpButton('roleid', 'roleforremoteusers', 'enrol_mnet');
|
||||||
|
$mform->addRule('roleid', get_string('required'), 'required', null, 'client');
|
||||||
|
$mform->setDefault('roleid', $enrol->get_config('roleid'));
|
||||||
|
|
||||||
|
$mform->addElement('text', 'name', get_string('instancename', 'enrol_mnet'));
|
||||||
|
$mform->addHelpButton('name', 'instancename', 'enrol_mnet');
|
||||||
|
$mform->setType('name', PARAM_TEXT);
|
||||||
|
|
||||||
|
$mform->addElement('hidden', 'id', null);
|
||||||
|
$mform->setType('id', PARAM_INT);
|
||||||
|
|
||||||
|
$this->add_action_buttons();
|
||||||
|
|
||||||
|
$this->set_data(array('id'=>$course->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not allow multiple instances for single remote host
|
||||||
|
*
|
||||||
|
* @param array $data raw form data
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function validation($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
if ($DB->record_exists('enrol', array('enrol' => 'mnet', 'courseid' => $data['id'], 'customint1' => $data['hostid']))) {
|
||||||
|
$errors['hostid'] = get_string('error_multiplehost', 'enrol_mnet');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
}
|
@ -1,37 +0,0 @@
|
|||||||
<?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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Capabilities for MNet enrolment plugin
|
|
||||||
*
|
|
||||||
* @package enrol
|
|
||||||
* @subpackage mnet
|
|
||||||
* @copyright 2010 David Mudrak <david@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$capabilities = array(
|
|
||||||
// configure the mnet plugin settings in the course
|
|
||||||
// users with this capability open the course for the remote users
|
|
||||||
'enrol/mnet:config' => array(
|
|
||||||
'captype' => 'write',
|
|
||||||
'contextlevel' => CONTEXT_COURSE,
|
|
||||||
'legacy' => array(
|
|
||||||
'manager' => CAP_ALLOW,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
);
|
|
@ -24,7 +24,15 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$string['error_multiplehost'] = 'Some instance of MNet enrolment plugin already exists for this host. Only one instance per host and/or one instance for \'All hosts\' is allowed.';
|
||||||
|
$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_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'] = 'Moodle Networked Enrolment';
|
||||||
$string['pluginname'] = 'MNet remote enrolments';
|
$string['pluginname'] = 'MNet remote enrolments';
|
||||||
$string['pluginname_desc'] = 'Allows remote MNet host to enrol their users into our courses.';
|
$string['pluginname_desc'] = 'Allows remote MNet host to enrol their users into our courses.';
|
||||||
|
$string['remotesubscriber'] = 'Remote host';
|
||||||
|
$string['remotesubscriber_help'] = 'Select \'All hosts\' to open this course for all MNet peers we are offering the remote enrolment service to. Or choose a single host to make this course available for their users only.';
|
||||||
|
$string['remotesubscribersall'] = 'All hosts';
|
||||||
|
$string['roleforremoteusers'] = 'Role for their users';
|
||||||
|
$string['roleforremoteusers_help'] = 'What role will the remote users from the selected host get.';
|
||||||
|
@ -31,4 +31,113 @@ defined('MOODLE_INTERNAL') || die;
|
|||||||
*/
|
*/
|
||||||
class enrol_mnet_plugin extends enrol_plugin {
|
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
|
||||||
|
*
|
||||||
|
* @param object|null $instance enrol_mnet instance
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_instance_name($instance) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
if (empty($instance)) {
|
||||||
|
$enrol = $this->get_name();
|
||||||
|
return get_string('pluginname', 'enrol_'.$enrol);
|
||||||
|
|
||||||
|
} else if (empty($instance->name)) {
|
||||||
|
$enrol = $this->get_name();
|
||||||
|
if ($role = $DB->get_record('role', array('id'=>$instance->roleid))) {
|
||||||
|
$role = role_get_name($role, get_context_instance(CONTEXT_COURSE, $instance->courseid));
|
||||||
|
} else {
|
||||||
|
$role = get_string('error');
|
||||||
|
}
|
||||||
|
if (empty($instance->customint1)) {
|
||||||
|
$host = get_string('remotesubscribersall', 'enrol_mnet');
|
||||||
|
} else {
|
||||||
|
$host = $DB->get_field('mnet_host', 'name', array('id'=>$instance->customint1));
|
||||||
|
}
|
||||||
|
return get_string('pluginname', 'enrol_'.$enrol) . ' (' . format_string($host) . ' - ' . $role .')';
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return format_string($instance->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns link to page which may be used to add new instance of enrolment plugin into the course
|
||||||
|
*
|
||||||
|
* The link is returned only if there are some MNet peers that we publish enrolment service to.
|
||||||
|
*
|
||||||
|
* @param int $courseid id of the course to add the instance to
|
||||||
|
* @return moodle_url|null page url or null if instance can not be created
|
||||||
|
*/
|
||||||
|
public function get_candidate_link($courseid) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
if (!$this->mnet_available()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||||
|
if (!has_capability('moodle/course:enrolconfig', $coursecontext)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$subscribers = $this->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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,4 +24,4 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$plugin->version = 2010071400;
|
$plugin->version = 2010071401;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user