Example #1
0
 /**
  * @return mnetservice_enrol singleton instance
  */
 public static function get_instance()
 {
     if (is_null(self::$singleton)) {
         self::$singleton = new self();
     }
     return self::$singleton;
 }
Example #2
0
 /**
  * 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_newinstance_link($courseid)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/mnet/service/enrol/locallib.php';
     $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 = $service->get_remote_subscribers();
     if (empty($subscribers)) {
         return null;
     }
     return new moodle_url('/enrol/mnet/addinstance.php', array('id' => $courseid));
 }
Example #3
0
 * hosts (session key required in such case).
 *
 * @package    mnetservice
 * @subpackage enrol
 * @copyright  2010 David Mudrak <*****@*****.**>
 * @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';
$hostid = required_param('id', PARAM_INT);
// remote host id
$usecache = optional_param('usecache', true, PARAM_BOOL);
// use cached list of courses
admin_externalpage_setup('mnetenrol', '', array('id' => $hostid, 'usecache' => 1), new moodle_url('/mnet/service/enrol/host.php'));
$service = mnetservice_enrol::get_instance();
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[$hostid])) {
    print_error('wearenotsubscribedtothishost', 'mnetservice_enrol');
}
$host = $hosts[$hostid];
if (!$usecache) {
    // our local database will be changed
    require_sesskey();
}
Example #4
0
 /**
  * Return an array of valid options for the hosts property.
  *
  * @return array
  */
 protected function get_valid_hosts_options()
 {
     global $CFG;
     require_once $CFG->dirroot . '/mnet/service/enrol/locallib.php';
     $service = mnetservice_enrol::get_instance();
     $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 . ')';
     }
     return $hosts;
 }