From 932773ff7b0cb4f1cb92cb9aceb8216dae270bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Trouv=C3=A9?= Date: Fri, 4 Aug 2017 13:48:09 +0200 Subject: [PATCH] fix #70: Prevent to unenrol a user with a pending application --- lib.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib.php b/lib.php index b822859..1359dac 100644 --- a/lib.php +++ b/lib.php @@ -41,7 +41,20 @@ class enrol_apply_plugin extends enrol_plugin { // Users with unenrol cap may unenrol other users manually. return true; } - + /** + * Prevent to unenrol an user with a pending application + * + * @param stdClass $instance course enrol instance + * @param stdClass $ue record from user_enrolments table, specifies user + * @return bool + */ + public function allow_unenrol_user(stdClass $instance, stdClass $ue) { + global $DB; + if ($DB->record_exists('enrol_apply_applicationinfo', ['userenrolmentid' => $ue->id])) { + return false; + } + return parent::allow_unenrol_user($instance, $ue); + } /** * Returns link to page which may be used to add new instance of enrolment plugin in course. * Multiple instances supported.