[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/enrol/category/ -> 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   * Category enrolment plugin.
  19   *
  20   * @package    enrol_category
  21   * @copyright  2010 Petr Skoda {@link http://skodak.org}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  
  28  /**
  29   * category enrolment plugin implementation.
  30   * @author  Petr Skoda
  31   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class enrol_category_plugin extends enrol_plugin {
  34  
  35     /**
  36       * Is it possible to delete enrol instance via standard UI?
  37       *
  38       * @param stdClass $instance
  39       * @return bool
  40       */
  41      public function can_delete_instance($instance) {
  42          global $DB;
  43  
  44          $context = context_course::instance($instance->courseid);
  45          if (!has_capability('enrol/category:config', $context)) {
  46              return false;
  47          }
  48  
  49          if (!enrol_is_enabled('category')) {
  50              return true;
  51          }
  52          // Allow delete only when no synced users here.
  53          return !$DB->record_exists('user_enrolments', array('enrolid'=>$instance->id));
  54      }
  55  
  56      /**
  57       * Is it possible to hide/show enrol instance via standard UI?
  58       *
  59       * @param stdClass $instance
  60       * @return bool
  61       */
  62      public function can_hide_show_instance($instance) {
  63          $context = context_course::instance($instance->courseid);
  64          return has_capability('enrol/category:config', $context);
  65      }
  66  
  67      /**
  68       * Returns link to page which may be used to add new instance of enrolment plugin in course.
  69       * @param int $courseid
  70       * @return moodle_url page url
  71       */
  72      public function get_newinstance_link($courseid) {
  73          // Instances are added automatically as necessary.
  74          return null;
  75      }
  76  
  77      /**
  78       * Called for all enabled enrol plugins that returned true from is_cron_required().
  79       * @return void
  80       */
  81      public function cron() {
  82          global $CFG;
  83  
  84          if (!enrol_is_enabled('category')) {
  85              return;
  86          }
  87  
  88          require_once("$CFG->dirroot/enrol/category/locallib.php");
  89          $trace = new null_progress_trace();
  90          enrol_category_sync_full($trace);
  91      }
  92  
  93      /**
  94       * Called after updating/inserting course.
  95       *
  96       * @param bool $inserted true if course just inserted
  97       * @param stdClass $course
  98       * @param stdClass $data form data
  99       * @return void
 100       */
 101      public function course_updated($inserted, $course, $data) {
 102          global $CFG;
 103  
 104          if (!enrol_is_enabled('category')) {
 105              return;
 106          }
 107  
 108          // Sync category enrols.
 109          require_once("$CFG->dirroot/enrol/category/locallib.php");
 110          enrol_category_sync_course($course);
 111      }
 112  
 113      /**
 114       * Automatic enrol sync executed during restore.
 115       * Useful for automatic sync by course->idnumber or course category.
 116       * @param stdClass $course course record
 117       */
 118      public function restore_sync_course($course) {
 119          global $CFG;
 120          require_once("$CFG->dirroot/enrol/category/locallib.php");
 121          enrol_category_sync_course($course);
 122      }
 123  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1