From 91b99e8018a2eaea12a730bafe14bddc391426dd Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 12 Jul 2010 17:46:48 +0000 Subject: [PATCH] MDL-23232 added support for enrol_plugin->all_enrol() which indicates plugin allows users to add new enrolments manually --- enrol/locallib.php | 4 ++-- enrol/manual/db/access.php | 10 +++++++++- enrol/manual/lang/en/enrol_manual.php | 3 ++- enrol/manual/lib.php | 7 ++++++- enrol/manual/manage.php | 2 ++ enrol/manual/version.php | 2 +- lib/enrollib.php | 18 +++++++++++++++--- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/enrol/locallib.php b/enrol/locallib.php index 7aeb9b60de9..0ad1c690760 100644 --- a/enrol/locallib.php +++ b/enrol/locallib.php @@ -629,7 +629,7 @@ class course_enrolment_manager { public function enrol_cohort_users($cohortid, $roleid) { global $DB; require_capability('moodle/course:enrolconfig', $this->get_context()); - require_capability('enrol/manual:manage', $this->get_context()); + require_capability('enrol/manual:enrol', $this->get_context()); $instances = $this->get_enrolment_instances(); $instance = false; foreach ($instances as $i) { @@ -643,7 +643,7 @@ class course_enrolment_manager { } $plugin = enrol_get_plugin('manual'); - $sql = "SELECT com.userid + $sql = "SELECT com.userid FROM {cohort_members} com LEFT JOIN ( SELECT * diff --git a/enrol/manual/db/access.php b/enrol/manual/db/access.php index 5c0194bf7e1..25a43734c23 100644 --- a/enrol/manual/db/access.php +++ b/enrol/manual/db/access.php @@ -34,7 +34,7 @@ $capabilities = array( ) ), - 'enrol/manual:manage' => array( + 'enrol/manual:enrol' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, 'legacy' => array( @@ -43,6 +43,14 @@ $capabilities = array( ) ), + 'enrol/manual:manage' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'manager' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + ) + ), 'enrol/manual:unenrol' => array( 'captype' => 'write', diff --git a/enrol/manual/lang/en/enrol_manual.php b/enrol/manual/lang/en/enrol_manual.php index 2ec7e3cdb38..78be2dd6cff 100644 --- a/enrol/manual/lang/en/enrol_manual.php +++ b/enrol/manual/lang/en/enrol_manual.php @@ -29,7 +29,8 @@ $string['defaultperiod_desc'] = 'Default length of the default enrolment period $string['enrolledincourserole'] = 'Enrolled in "{$a->course}" as "{$a->role}"'; $string['enrolusers'] = 'Enrol users'; $string['manual:config'] = 'Configure manual enrol instances'; -$string['manual:manage'] = 'Manage enrolled users'; +$string['manual:enrol'] = 'Enrol users'; +$string['manual:manage'] = 'Manage user enrolments'; $string['manual:unenrol'] = 'Unenrol users from the course'; $string['manual:unenrolself'] = 'Unenrol self from the course'; $string['pluginname'] = 'Manual enrolments'; diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index 57c7d57229e..9dbc89e5f96 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -32,6 +32,11 @@ class enrol_manual_plugin extends enrol_plugin { return false; } + public function allow_enrol(stdClass $instance) { + // users with enrol cap may unenrol other users manually manually + return true; + } + public function allow_unenrol(stdClass $instance) { // users with unenrol cap may unenrol other users manually manually return true; @@ -65,7 +70,7 @@ class enrol_manual_plugin extends enrol_plugin { $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST); - if (!has_capability('enrol/manual:manage', $context)) { + if (!has_capability('enrol/manual:manage', $context) or !has_capability('enrol/manual:enrol', $context) or !has_capability('enrol/manual:unenrol', $context)) { return NULL; } diff --git a/enrol/manual/manage.php b/enrol/manual/manage.php index 3a37aa866d6..c6f35fcd12a 100644 --- a/enrol/manual/manage.php +++ b/enrol/manual/manage.php @@ -35,7 +35,9 @@ $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_ $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); require_login($course); +require_capability('enrol/manual:enrol', $context); require_capability('enrol/manual:manage', $context); +require_capability('enrol/manual:unenrol', $context); $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST); if ($roleid < 0) { diff --git a/enrol/manual/version.php b/enrol/manual/version.php index fd209b7a96a..cb682a18ecb 100644 --- a/enrol/manual/version.php +++ b/enrol/manual/version.php @@ -23,4 +23,4 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$plugin->version = 2010061500; +$plugin->version = 2010071200; diff --git a/lib/enrollib.php b/lib/enrollib.php index 9f6ac8e184d..b681ec444c6 100644 --- a/lib/enrollib.php +++ b/lib/enrollib.php @@ -749,13 +749,25 @@ abstract class enrol_plugin { return true; } + /** + * Does this plugin allow manual enrolments? + * + * @param stdClass $instance course enrol instance + * All plugins allowing this must implement 'enrol/xxx:enrol' capability + * + * @return bool - true means user with 'enrol/xxx:enrol' may enrol others freely, trues means nobody may add more enrolments manually + */ + public function allow_enrol(stdClass $instance) { + return false; + } + /** * Does this plugin allow manual unenrolments? * * @param stdClass $instance course enrol instance - * ALl plugins allowing this must implement 'enrol/xxx:unenrol' capability + * All plugins allowing this must implement 'enrol/xxx:unenrol' capability * - * @return bool - true means anybody may unenrol others freely, trues means nobody may touch user_enrolments + * @return bool - true means user with 'enrol/xxx:unenrol' may unenrol others freely, trues means nobody may touch user_enrolments */ public function allow_unenrol(stdClass $instance) { return false; @@ -764,7 +776,7 @@ abstract class enrol_plugin { /** * Does this plugin allow manual changes in user_enrolments table? * - * ALl plugins allowing this must implement 'enrol/xxx:manage' capability + * All plugins allowing this must implement 'enrol/xxx:manage' capability * * @param stdClass $instance course enrol instance * @return bool - true means it is possible to change enrol period and status in user_enrolments table