Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/meta/lib.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00026 defined('MOODLE_INTERNAL') || die();
00027 
00033 class enrol_meta_plugin extends enrol_plugin {
00034 
00041     public function get_instance_name($instance) {
00042         global $DB;
00043 
00044         if (empty($instance)) {
00045             $enrol = $this->get_name();
00046             return get_string('pluginname', 'enrol_'.$enrol);
00047         } else if (empty($instance->name)) {
00048             $enrol = $this->get_name();
00049             return get_string('pluginname', 'enrol_'.$enrol) . ' (' . format_string($DB->get_field('course', 'fullname', array('id'=>$instance->customint1))) . ')';
00050         } else {
00051             return format_string($instance->name);
00052         }
00053     }
00054 
00060     public function get_newinstance_link($courseid) {
00061         $context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST);
00062         if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/meta:config', $context)) {
00063             return NULL;
00064         }
00065         // multiple instances supported - multiple parent courses linked
00066         return new moodle_url('/enrol/meta/addinstance.php', array('id'=>$courseid));
00067     }
00068 
00078     public function allow_unenrol_user(stdClass $instance, stdClass $ue) {
00079         if ($ue->status == ENROL_USER_SUSPENDED) {
00080             return true;
00081         }
00082 
00083         return false;
00084     }
00085 
00093     public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) {
00094         $actions = array();
00095         $context = $manager->get_context();
00096         $instance = $ue->enrolmentinstance;
00097         $params = $manager->get_moodlepage()->url->params();
00098         $params['ue'] = $ue->id;
00099         if ($this->allow_unenrol_user($instance, $ue) && has_capability('enrol/meta:unenrol', $context)) {
00100             $url = new moodle_url('/enrol/unenroluser.php', $params);
00101             $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
00102         }
00103         return $actions;
00104     }
00105 
00114     public function course_updated($inserted, $course, $data) {
00115         global $CFG;
00116 
00117         if (!$inserted) {
00118             // sync cohort enrols
00119             require_once("$CFG->dirroot/enrol/meta/locallib.php");
00120             enrol_meta_sync($course->id);
00121         } else {
00122             // cohorts are never inserted automatically
00123         }
00124     }
00125 
00133     public function update_status($instance, $newstatus) {
00134         global $CFG;
00135 
00136         parent::update_status($instance, $newstatus);
00137 
00138         require_once("$CFG->dirroot/enrol/meta/locallib.php");
00139         enrol_meta_sync($instance->courseid);
00140     }
00141 
00146     public function cron() {
00147         global $CFG;
00148 
00149         require_once("$CFG->dirroot/enrol/meta/locallib.php");
00150         enrol_meta_sync();
00151     }
00152 }
00153 
 All Data Structures Namespaces Files Functions Variables Enumerations