From 4a635890003ed8a4ea7e0ce2341df923dcfd433a Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 27 Feb 2012 11:21:06 +0100 Subject: [PATCH] MDL-31361 allow unenrolling of suspended users in enrol/database --- enrol/database/db/access.php | 13 ++++++++ enrol/database/lang/en/enrol_database.php | 1 + enrol/database/lib.php | 37 +++++++++++++++++++++++ enrol/database/version.php | 4 +-- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/enrol/database/db/access.php b/enrol/database/db/access.php index 5173b6bd30b..b3305d0201c 100644 --- a/enrol/database/db/access.php +++ b/enrol/database/db/access.php @@ -26,3 +26,16 @@ defined('MOODLE_INTERNAL') || die(); +$capabilities = array( + /* This is used only when sync suspends users instead of full unenrolment */ + 'enrol/database:unenrol' => array( + + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'manager' => CAP_ALLOW, + ) + ), +); + + diff --git a/enrol/database/lang/en/enrol_database.php b/enrol/database/lang/en/enrol_database.php index 0787b008ac4..18f642058ee 100644 --- a/enrol/database/lang/en/enrol_database.php +++ b/enrol/database/lang/en/enrol_database.php @@ -23,6 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['database:unenrol'] = 'Unenrol suspended users'; $string['dbencoding'] = 'Database encoding'; $string['dbhost'] = 'Database host'; $string['dbhost_desc'] = 'Type database server IP address or host name'; diff --git a/enrol/database/lib.php b/enrol/database/lib.php index 08b86f9beae..eca99b138b8 100644 --- a/enrol/database/lib.php +++ b/enrol/database/lib.php @@ -51,6 +51,43 @@ class enrol_database_plugin extends enrol_plugin { return false; } + /** + * Does this plugin allow manual unenrolment of a specific user? + * Yes, but only if user suspended... + * + * @param stdClass $instance course enrol instance + * @param stdClass $ue record from user_enrolments table + * + * @return bool - true means user with 'enrol/xxx:unenrol' may unenrol this user, false means nobody may touch this user enrolment + */ + public function allow_unenrol_user(stdClass $instance, stdClass $ue) { + if ($ue->status == ENROL_USER_SUSPENDED) { + return true; + } + + return false; + } + + /** + * Gets an array of the user enrolment actions + * + * @param course_enrolment_manager $manager + * @param stdClass $ue A user enrolment object + * @return array An array of user_enrolment_actions + */ + public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) { + $actions = array(); + $context = $manager->get_context(); + $instance = $ue->enrolmentinstance; + $params = $manager->get_moodlepage()->url->params(); + $params['ue'] = $ue->id; + if ($this->allow_unenrol_user($instance, $ue) && has_capability('enrol/meta:unenrol', $context)) { + $url = new moodle_url('/enrol/unenroluser.php', $params); + $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id)); + } + return $actions; + } + /** * Forces synchronisation of user enrolments with external database, * does not create new courses. diff --git a/enrol/database/version.php b/enrol/database/version.php index fe7178e467d..c1a28206e95 100644 --- a/enrol/database/version.php +++ b/enrol/database/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2011112900; // The current plugin version (Date: YYYYMMDDXX) -$plugin->requires = 2011112900; // Requires this Moodle version +$plugin->version = 2012022700; // The current plugin version (Date: YYYYMMDDXX) +$plugin->requires = 2012022300; // Requires this Moodle version $plugin->component = 'enrol_database'; // Full name of the plugin (used for diagnostics) //TODO: should we add cron sync? \ No newline at end of file