3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * MNet enrolment plugin
23 * @copyright 2010 David Mudrak <david@moodle.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die();
30 * MNet enrolment plugin implementation for Moodle 2.x enrolment framework
32 class enrol_mnet_plugin
extends enrol_plugin
{
35 * Returns localised name of enrol instance
37 * @param object|null $instance enrol_mnet instance
40 public function get_instance_name($instance) {
43 if (empty($instance)) {
44 $enrol = $this->get_name();
45 return get_string('pluginname', 'enrol_'.$enrol);
47 } else if (empty($instance->name
)) {
48 $enrol = $this->get_name();
49 if ($role = $DB->get_record('role', array('id'=>$instance->roleid
))) {
50 $role = role_get_name($role, context_course
::instance($instance->courseid
, IGNORE_MISSING
));
52 $role = get_string('error');
54 if (empty($instance->customint1
)) {
55 $host = get_string('remotesubscribersall', 'enrol_mnet');
57 $host = $DB->get_field('mnet_host', 'name', array('id'=>$instance->customint1
));
59 return get_string('pluginname', 'enrol_'.$enrol) . ' (' . format_string($host) . ' - ' . $role .')';
62 return format_string($instance->name
);
67 * Returns link to page which may be used to add new instance of enrolment plugin into the course
69 * The link is returned only if there are some MNet peers that we publish enrolment service to.
71 * @param int $courseid id of the course to add the instance to
72 * @return moodle_url|null page url or null if instance can not be created
74 public function get_newinstance_link($courseid) {
76 require_once($CFG->dirroot
.'/mnet/service/enrol/locallib.php');
78 $service = mnetservice_enrol
::get_instance();
79 if (!$service->is_available()) {
82 $coursecontext = context_course
::instance($courseid);
83 if (!has_capability('moodle/course:enrolconfig', $coursecontext)) {
86 $subscribers = $service->get_remote_subscribers();
87 if (empty($subscribers)) {
91 return new moodle_url('/enrol/mnet/addinstance.php', array('id'=>$courseid));