MDL-79059 mod_data: Fix presets accessibility issues
[moodle.git] / enrol / category / lib.php
blobf63e005cd6a78848a204807e1a92071a01a74b55
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.
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/>.
17 /**
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();
28 /**
29 * category enrolment plugin implementation.
30 * @author Petr Skoda
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 class enrol_category_plugin extends enrol_plugin {
35 /**
36 * Is it possible to delete enrol instance via standard UI?
38 * @param stdClass $instance
39 * @return bool
41 public function can_delete_instance($instance) {
42 global $DB;
44 $context = context_course::instance($instance->courseid);
45 if (!has_capability('enrol/category:config', $context)) {
46 return false;
49 if (!enrol_is_enabled('category')) {
50 return true;
52 // Allow delete only when no synced users here.
53 return !$DB->record_exists('user_enrolments', array('enrolid'=>$instance->id));
56 /**
57 * Is it possible to hide/show enrol instance via standard UI?
59 * @param stdClass $instance
60 * @return bool
62 public function can_hide_show_instance($instance) {
63 $context = context_course::instance($instance->courseid);
64 return has_capability('enrol/category:config', $context);
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
72 public function get_newinstance_link($courseid) {
73 // Instances are added automatically as necessary.
74 return null;
77 /**
78 * Called after updating/inserting course.
80 * @param bool $inserted true if course just inserted
81 * @param stdClass $course
82 * @param stdClass $data form data
83 * @return void
85 public function course_updated($inserted, $course, $data) {
86 global $CFG;
88 if (!enrol_is_enabled('category')) {
89 return;
92 // Sync category enrols.
93 require_once("$CFG->dirroot/enrol/category/locallib.php");
94 enrol_category_sync_course($course);
97 /**
98 * Automatic enrol sync executed during restore.
99 * Useful for automatic sync by course->idnumber or course category.
100 * @param stdClass $course course record
102 public function restore_sync_course($course) {
103 global $CFG;
104 require_once("$CFG->dirroot/enrol/category/locallib.php");
105 enrol_category_sync_course($course);