2010-07-17 22:16:48 +00:00
|
|
|
<?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/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MNet enrolment plugin
|
|
|
|
*
|
2013-04-27 13:41:32 +02:00
|
|
|
* @package enrol_mnet
|
2010-07-17 22:16:48 +00:00
|
|
|
* @copyright 2010 David Mudrak <david@moodle.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2010-07-31 20:30:29 +00:00
|
|
|
defined('MOODLE_INTERNAL') || die();
|
2010-07-17 22:16:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MNet enrolment plugin implementation for Moodle 2.x enrolment framework
|
|
|
|
*/
|
|
|
|
class enrol_mnet_plugin extends enrol_plugin {
|
|
|
|
|
2010-07-17 22:17:10 +00:00
|
|
|
/**
|
|
|
|
* 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))) {
|
2012-07-23 16:08:41 +08:00
|
|
|
$role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING));
|
2010-07-17 22:17:10 +00:00
|
|
|
} 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
|
|
|
|
*/
|
2010-07-31 20:02:56 +00:00
|
|
|
public function get_newinstance_link($courseid) {
|
2010-07-17 22:18:07 +00:00
|
|
|
global $CFG, $DB;
|
|
|
|
require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
|
2010-07-17 22:17:10 +00:00
|
|
|
|
2010-07-17 22:18:07 +00:00
|
|
|
$service = mnetservice_enrol::get_instance();
|
|
|
|
if (!$service->is_available()) {
|
2010-07-17 22:17:10 +00:00
|
|
|
return null;
|
|
|
|
}
|
2012-07-23 16:08:41 +08:00
|
|
|
$coursecontext = context_course::instance($courseid);
|
2010-07-17 22:17:10 +00:00
|
|
|
if (!has_capability('moodle/course:enrolconfig', $coursecontext)) {
|
|
|
|
return null;
|
|
|
|
}
|
2010-07-17 22:18:07 +00:00
|
|
|
$subscribers = $service->get_remote_subscribers();
|
2010-07-17 22:17:10 +00:00
|
|
|
if (empty($subscribers)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new moodle_url('/enrol/mnet/addinstance.php', array('id'=>$courseid));
|
|
|
|
}
|
2010-07-17 22:16:48 +00:00
|
|
|
}
|