mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-59811 enrol: Move get_user_enrolment_actions logic to parent class
* These duplicated implementations can be simplified where the logic can be moved to enrol_plugin::get_user_enrolment_actions() method itself.
This commit is contained in:
parent
18000c6d60
commit
4047fccba7
@ -221,28 +221,6 @@ class enrol_cohort_plugin extends enrol_plugin {
|
||||
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/cohort: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')),
|
||||
get_string('unenrol', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore instance and map settings.
|
||||
*
|
||||
|
@ -82,28 +82,6 @@ class enrol_database_plugin extends enrol_plugin {
|
||||
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/database: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')),
|
||||
get_string('unenrol', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces synchronisation of user enrolments with external database,
|
||||
* does not create new courses.
|
||||
|
@ -117,34 +117,6 @@ class enrol_flatfile_plugin extends enrol_plugin {
|
||||
return has_capability('enrol/flatfile:manage', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_manage($instance) && has_capability("enrol/flatfile:manage", $context)) {
|
||||
$url = new moodle_url('/enrol/editenrolment.php', $params);
|
||||
$actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
|
||||
$actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
|
||||
get_string('editenrolment', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/flatfile: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')),
|
||||
get_string('unenrol', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enrol user into course via enrol instance.
|
||||
*
|
||||
|
@ -38,7 +38,7 @@ class course_enrolment_manager {
|
||||
|
||||
/**
|
||||
* The course context
|
||||
* @var stdClass
|
||||
* @var context
|
||||
*/
|
||||
protected $context;
|
||||
/**
|
||||
@ -933,7 +933,7 @@ class course_enrolment_manager {
|
||||
/**
|
||||
* Returns the course context
|
||||
*
|
||||
* @return stdClass
|
||||
* @return context
|
||||
*/
|
||||
public function get_context() {
|
||||
return $this->context;
|
||||
|
@ -377,34 +377,6 @@ class enrol_lti_plugin extends enrol_plugin {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_manage($instance) && has_capability("enrol/lti:manage", $context)) {
|
||||
$url = new moodle_url('/enrol/editenrolment.php', $params);
|
||||
$actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
|
||||
$actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
|
||||
get_string('editenrolment', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
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')),
|
||||
get_string('unenrol', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore instance and map settings.
|
||||
*
|
||||
|
@ -361,34 +361,6 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
return $this->lasternoller;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_manage($instance) && has_capability("enrol/manual:manage", $context)) {
|
||||
$url = new moodle_url('/enrol/editenrolment.php', $params);
|
||||
$actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
|
||||
$actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
|
||||
get_string('editenrolment', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/manual: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')),
|
||||
get_string('unenrol', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* The manual plugin has several bulk operations that can be performed.
|
||||
* @param course_enrolment_manager $manager
|
||||
|
@ -95,28 +95,6 @@ class enrol_meta_plugin extends enrol_plugin {
|
||||
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);
|
||||
$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')),
|
||||
get_string('unenrol', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after updating/inserting course.
|
||||
*
|
||||
|
@ -276,34 +276,6 @@ class enrol_paypal_plugin extends enrol_plugin {
|
||||
$this->enrol_user($instance, $userid, null, $data->timestart, $data->timeend, $data->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_manage($instance) && has_capability("enrol/paypal:manage", $context)) {
|
||||
$url = new moodle_url('/enrol/editenrolment.php', $params);
|
||||
$actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
|
||||
$actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
|
||||
get_string('editenrolment', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
if ($this->allow_unenrol($instance) && has_capability("enrol/paypal: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')),
|
||||
get_string('unenrol', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
public function cron() {
|
||||
$trace = new text_progress_trace();
|
||||
$this->process_expirations($trace);
|
||||
|
@ -521,34 +521,6 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
return $this->lasternoller;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_manage($instance) && has_capability("enrol/self:manage", $context)) {
|
||||
$url = new moodle_url('/enrol/editenrolment.php', $params);
|
||||
$actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
|
||||
$actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
|
||||
get_string('editenrolment', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
if ($this->allow_unenrol($instance) && has_capability("enrol/self: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')),
|
||||
get_string('unenrol', 'enrol'), $url, $actionparams);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore instance and map settings.
|
||||
*
|
||||
|
@ -2588,7 +2588,38 @@ abstract class enrol_plugin {
|
||||
* @return array An array of user_enrolment_actions
|
||||
*/
|
||||
public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) {
|
||||
return array();
|
||||
$actions = [];
|
||||
$context = $manager->get_context();
|
||||
$instance = $ue->enrolmentinstance;
|
||||
$params = $manager->get_moodlepage()->url->params();
|
||||
$params['ue'] = $ue->id;
|
||||
|
||||
// Edit enrolment action.
|
||||
if ($this->allow_manage($instance) && has_capability("enrol/{$instance->enrol}:manage", $context)) {
|
||||
$title = get_string('editenrolment', 'enrol');
|
||||
$icon = new pix_icon('t/edit', $title);
|
||||
$url = new moodle_url('/enrol/editenrolment.php', $params);
|
||||
$actionparams = [
|
||||
'class' => 'editenrollink',
|
||||
'rel' => $ue->id,
|
||||
'data-action' => ENROL_ACTION_EDIT
|
||||
];
|
||||
$actions[] = new user_enrolment_action($icon, $title, $url, $actionparams);
|
||||
}
|
||||
|
||||
// Unenrol action.
|
||||
if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/{$instance->enrol}:unenrol", $context)) {
|
||||
$title = get_string('unenrol', 'enrol');
|
||||
$icon = new pix_icon('t/delete', $title);
|
||||
$url = new moodle_url('/enrol/unenroluser.php', $params);
|
||||
$actionparams = [
|
||||
'class' => 'unenrollink',
|
||||
'rel' => $ue->id,
|
||||
'data-action' => ENROL_ACTION_UNENROL
|
||||
];
|
||||
$actions[] = new user_enrolment_action($icon, $title, $url, $actionparams);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,6 +32,13 @@ information provided here is intended especially for developers.
|
||||
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.
|
||||
* The enrol_plugin::get_user_enrolment_actions() implementations for core enrol plugins have been removed and moved to
|
||||
the parent method itself. New enrol plugins don't have to implement get_user_enrolment_actions(), but just need to
|
||||
make sure that they override:
|
||||
- enrol_plugin::allow_manage(), and/or
|
||||
- enrol_plugin::allow_unenrol_user() or enrol_plugin::allow_unenrol()
|
||||
Existing enrol plugins that override enrol_plugin::get_user_enrolment_actions() don't have to do anything, but can
|
||||
also opt to remove their own implementation of the method if they basically have the same logic as the parent method.
|
||||
* New optional parameter $enrolid for the following functions:
|
||||
- get_enrolled_join()
|
||||
- get_enrolled_sql()
|
||||
|
Loading…
x
Reference in New Issue
Block a user