2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Category enrolment plugin.
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
25 defined('MOODLE_INTERNAL') || die();
29 * category enrolment plugin implementation.
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 class enrol_category_plugin extends enrol_plugin {
36 * Is it possible to delete enrol instance via standard UI?
38 * @param stdClass $instance
41 public function instance_deleteable($instance) {
44 if (!enrol_is_enabled('category')) {
47 // Allow delete only when no synced users here.
48 return !$DB->record_exists('user_enrolments', array('enrolid'=>$instance->id));
52 * Returns link to page which may be used to add new instance of enrolment plugin in course.
53 * @param int $courseid
54 * @return moodle_url page url
56 public function get_newinstance_link($courseid) {
57 // Instances are added automatically as necessary.
62 * Called for all enabled enrol plugins that returned true from is_cron_required().
65 public function cron() {
68 if (!enrol_is_enabled('category')) {
72 require_once("$CFG->dirroot/enrol/category/locallib.php");
73 enrol_category_sync_full();
77 * Called after updating/inserting course.
79 * @param bool $inserted true if course just inserted
80 * @param stdClass $course
81 * @param stdClass $data form data
84 public function course_updated($inserted, $course, $data) {
87 if (!enrol_is_enabled('category')) {
91 // Sync category enrols.
92 require_once("$CFG->dirroot/enrol/category/locallib.php");
93 enrol_category_sync_course($course);