[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/enrol/mnet/ -> lib.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * MNet enrolment plugin
  19   *
  20   * @package    enrol_mnet
  21   * @copyright  2010 David Mudrak <[email protected]>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * MNet enrolment plugin implementation for Moodle 2.x enrolment framework
  29   */
  30  class enrol_mnet_plugin extends enrol_plugin {
  31  
  32      /**
  33       * Returns localised name of enrol instance
  34       *
  35       * @param object|null $instance enrol_mnet instance
  36       * @return string
  37       */
  38      public function get_instance_name($instance) {
  39          global $DB;
  40  
  41          if (empty($instance)) {
  42              $enrol = $this->get_name();
  43              return get_string('pluginname', 'enrol_'.$enrol);
  44  
  45          } else if (empty($instance->name)) {
  46              $enrol = $this->get_name();
  47              if ($role = $DB->get_record('role', array('id'=>$instance->roleid))) {
  48                  $role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING));
  49              } else {
  50                  $role = get_string('error');
  51              }
  52              if (empty($instance->customint1)) {
  53                  $host = get_string('remotesubscribersall', 'enrol_mnet');
  54              } else {
  55                  $host = $DB->get_field('mnet_host', 'name', array('id'=>$instance->customint1));
  56              }
  57              return get_string('pluginname', 'enrol_'.$enrol) . ' (' . format_string($host) . ' - ' . $role .')';
  58  
  59          } else {
  60              return format_string($instance->name);
  61          }
  62      }
  63  
  64      /**
  65       * Returns link to page which may be used to add new instance of enrolment plugin into the course
  66       *
  67       * The link is returned only if there are some MNet peers that we publish enrolment service to.
  68       *
  69       * @param int $courseid id of the course to add the instance to
  70       * @return moodle_url|null page url or null if instance can not be created
  71       */
  72      public function get_newinstance_link($courseid) {
  73          global $CFG, $DB;
  74          require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
  75  
  76          $service = mnetservice_enrol::get_instance();
  77          if (!$service->is_available()) {
  78              return null;
  79          }
  80          $coursecontext = context_course::instance($courseid);
  81          if (!has_capability('moodle/course:enrolconfig', $coursecontext)) {
  82              return null;
  83          }
  84          $subscribers = $service->get_remote_subscribers();
  85          if (empty($subscribers)) {
  86              return null;
  87          }
  88  
  89          return new moodle_url('/enrol/mnet/addinstance.php', array('id'=>$courseid));
  90      }
  91  
  92      /**
  93       * Is it possible to delete enrol instance via standard UI?
  94       *
  95       * @param stdClass $instance
  96       * @return bool
  97       */
  98      public function can_delete_instance($instance) {
  99          $context = context_course::instance($instance->courseid);
 100          return has_capability('enrol/mnet:config', $context);
 101      }
 102  
 103      /**
 104       * Is it possible to hide/show enrol instance via standard UI?
 105       *
 106       * @param stdClass $instance
 107       * @return bool
 108       */
 109      public function can_hide_show_instance($instance) {
 110          $context = context_course::instance($instance->courseid);
 111          return has_capability('enrol/mnet:config', $context);
 112      }
 113  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1