From fd0a43be1b05c22b9af946577b6d72a1ce050eba Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 18 Jul 2017 11:55:31 +0800 Subject: [PATCH] MDL-59369 enrol: Introduce data-action attribute for enrol action links --- enrol/cohort/lib.php | 4 +++- enrol/database/lib.php | 4 +++- enrol/flatfile/lib.php | 7 +++++-- enrol/lti/lib.php | 7 ++++--- enrol/manual/lib.php | 7 +++++-- enrol/meta/lib.php | 4 +++- enrol/paypal/lib.php | 7 +++++-- enrol/self/lib.php | 7 +++++-- lib/enrollib.php | 6 ++++++ lib/upgrade.txt | 7 +++++++ 10 files changed, 46 insertions(+), 14 deletions(-) diff --git a/enrol/cohort/lib.php b/enrol/cohort/lib.php index 179671e122c4..7c1eef26803a 100644 --- a/enrol/cohort/lib.php +++ b/enrol/cohort/lib.php @@ -236,7 +236,9 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u $params['ue'] = $ue->id; if ($this->allow_unenrol_user($instance, $ue) && has_capability('enrol/cohort: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)); + $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL); + $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, + $actionparams); } return $actions; } diff --git a/enrol/database/lib.php b/enrol/database/lib.php index b21578e5fc2e..890942a47bfe 100644 --- a/enrol/database/lib.php +++ b/enrol/database/lib.php @@ -97,7 +97,9 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u $params['ue'] = $ue->id; if ($this->allow_unenrol_user($instance, $ue) && has_capability('enrol/database: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)); + $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL); + $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, + $actionparams); } return $actions; } diff --git a/enrol/flatfile/lib.php b/enrol/flatfile/lib.php index 4bff2a9939a5..498584819bba 100644 --- a/enrol/flatfile/lib.php +++ b/enrol/flatfile/lib.php @@ -132,11 +132,14 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u $params['ue'] = $ue->id; if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/flatfile: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)); + $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL); + $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, + $actionparams); } if ($this->allow_manage($instance) && has_capability("enrol/flatfile:manage", $context)) { $url = new moodle_url('/enrol/editenrolment.php', $params); - $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id)); + $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT); + $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, $actionparams); } return $actions; } diff --git a/enrol/lti/lib.php b/enrol/lti/lib.php index 1377b1978152..0edfbfbdcac2 100644 --- a/enrol/lti/lib.php +++ b/enrol/lti/lib.php @@ -392,13 +392,14 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u $params['ue'] = $ue->id; if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/lti:unenrol", $context)) { $url = new moodle_url('/enrol/unenroluser.php', $params); + $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL); $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, - array('class' => 'unenrollink', 'rel' => $ue->id)); + $actionparams); } if ($this->allow_manage($instance) && has_capability("enrol/lti:manage", $context)) { $url = new moodle_url('/enrol/editenrolment.php', $params); - $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, - array('class' => 'editenrollink', 'rel' => $ue->id)); + $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT); + $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, $actionparams); } return $actions; } diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index 1eef9b01cbb1..c71c24670504 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -376,11 +376,14 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u $params['ue'] = $ue->id; if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/manual: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)); + $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL); + $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, + $actionparams); } if ($this->allow_manage($instance) && has_capability("enrol/manual:manage", $context)) { $url = new moodle_url('/enrol/editenrolment.php', $params); - $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id)); + $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT); + $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, $actionparams); } return $actions; } diff --git a/enrol/meta/lib.php b/enrol/meta/lib.php index 1415f57010d5..0b6bfd0171e4 100644 --- a/enrol/meta/lib.php +++ b/enrol/meta/lib.php @@ -110,7 +110,9 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u $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)); + $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL); + $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, + $actionparams); } return $actions; } diff --git a/enrol/paypal/lib.php b/enrol/paypal/lib.php index 87ecfe56ee8d..7ec6722175bf 100644 --- a/enrol/paypal/lib.php +++ b/enrol/paypal/lib.php @@ -291,11 +291,14 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u $params['ue'] = $ue->id; if ($this->allow_unenrol($instance) && has_capability("enrol/paypal: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)); + $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL); + $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, + $actionparams); } if ($this->allow_manage($instance) && has_capability("enrol/paypal:manage", $context)) { $url = new moodle_url('/enrol/editenrolment.php', $params); - $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id)); + $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT); + $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, $actionparams); } return $actions; } diff --git a/enrol/self/lib.php b/enrol/self/lib.php index 90be25aac530..3519f76fe116 100644 --- a/enrol/self/lib.php +++ b/enrol/self/lib.php @@ -536,11 +536,14 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u $params['ue'] = $ue->id; if ($this->allow_unenrol($instance) && has_capability("enrol/self: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)); + $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL); + $actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, + $actionparams); } if ($this->allow_manage($instance) && has_capability("enrol/self:manage", $context)) { $url = new moodle_url('/enrol/editenrolment.php', $params); - $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id)); + $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT); + $actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, $actionparams); } return $actions; } diff --git a/lib/enrollib.php b/lib/enrollib.php index 7995e77e6c2c..93f67dc28901 100644 --- a/lib/enrollib.php +++ b/lib/enrollib.php @@ -87,6 +87,12 @@ */ define('ENROL_SEND_EMAIL_FROM_NOREPLY', 3); +/** Edit enrolment action. */ +define('ENROL_ACTION_EDIT', 'editenrolment'); + +/** Unenrol action. */ +define('ENROL_ACTION_UNENROL', 'unenrol'); + /** * Returns instances of enrol plugins * @param bool $enabled return enabled only diff --git a/lib/upgrade.txt b/lib/upgrade.txt index ef21b435245e..ea0eace1434f 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -25,6 +25,13 @@ information provided here is intended especially for developers. every form. The method should accept a single parameter with the submitted value. It should return a string with the eventual validation error, or an empty value if the validation passes. * New user_picture attribute $includefullname to determine whether to include the user's full name with the user's picture. +* Enrol plugins which provide enrolment actions can now declare the following "data-action" attributes in their implementation of + enrol_plugin::get_user_enrolment_actions() whenever applicable: + * "editenrolment" - For editing a user'e enrolment details. Defined by constant ENROL_ACTION_EDIT. + * "unenrol" - For unenrolling a student. Defined by constant ENROL_ACTION_UNENROL. + These attributes enable enrol actions to be rendered via modals. If not added, clicking on the enrolment action buttons will still + redirect the user to the appropriate enrolment action page. Though optional, it is recommended to add these attributes for a + better user experience when performing enrol actions. === 3.3.1 ===