Merge branch 'MDL-38511-bulk-actions' of https://github.com/brendanheywood/moodle
authorAdrian Greeve <abgreeve@gmail.com>
Tue, 28 Jan 2020 03:07:44 +0000 (11:07 +0800)
committerAdrian Greeve <abgreeve@gmail.com>
Tue, 28 Jan 2020 03:10:17 +0000 (11:10 +0800)
1  2 
admin/user/user_bulk_forms.php
lib/upgrade.txt

@@@ -3,32 -27,88 +27,88 @@@ defined('MOODLE_INTERNAL') || die()
  require_once($CFG->libdir.'/formslib.php');
  require_once($CFG->libdir.'/datalib.php');
  
+ /**
+  * Bulk user action form
+  *
+  * @copyright  Moodle
+  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+  */
  class user_bulk_action_form extends moodleform {
-     function definition() {
-         global $CFG;
  
-         $mform =& $this->_form;
+     /**
+      * Returns an array of action_link's of all bulk actions available for this user.
+      *
+      * @return array of action_link objects
+      */
 -    public function get_actions() : array {
++    public function get_actions(): array {
+         global $CFG;
  
          $syscontext = context_system::instance();
-         $actions = array(0=>get_string('choose').'...');
+         $actions = [];
          if (has_capability('moodle/user:update', $syscontext)) {
-             $actions[1] = get_string('confirm');
+             $actions['confirm'] = new action_link(
+                 new moodle_url('/admin/user/user_bulk_confirm.php'),
+                 get_string('confirm'));
          }
          if (has_capability('moodle/site:readallmessages', $syscontext) && !empty($CFG->messaging)) {
-             $actions[2] = get_string('messageselectadd');
+             $actions['message'] = new action_link(
+                 new moodle_url('/admin/user/user_bulk_message.php'),
+                 get_string('messageselectadd'));
          }
          if (has_capability('moodle/user:delete', $syscontext)) {
-             $actions[3] = get_string('delete');
+             $actions['delete'] = new action_link(
+                 new moodle_url('/admin/user/user_bulk_delete.php'),
+                 get_string('delete'));
          }
-         $actions[4] = get_string('displayonpage');
+         $actions['displayonpage'] = new action_link(
+                 new moodle_url('/admin/user/user_bulk_display.php'),
+                 get_string('displayonpage'));
          if (has_capability('moodle/user:update', $syscontext)) {
-             $actions[5] = get_string('download', 'admin');
+             $actions['download'] = new action_link(
+                 new moodle_url('/admin/user/user_bulk_download.php'),
+                 get_string('download', 'admin'));
          }
          if (has_capability('moodle/user:update', $syscontext)) {
-             $actions[7] = get_string('forcepasswordchange');
+             $actions['forcepasswordchange'] = new action_link(
+                 new moodle_url('/admin/user/user_bulk_forcepasswordchange.php'),
+                 get_string('forcepasswordchange'));
          }
          if (has_capability('moodle/cohort:assign', $syscontext)) {
-             $actions[8] = get_string('bulkadd', 'core_cohort');
+             $actions['addtocohort'] = new action_link(
+                 new moodle_url('/admin/user/user_bulk_cohortadd.php'),
+                 get_string('bulkadd', 'core_cohort'));
+         }
+         // Any plugin can append actions to this list by implementing a callback
+         // <component>_bulk_user_actions() which returns an array of action_link.
+         // Each new action's key should have a frankenstyle prefix to avoid clashes.
+         // See MDL-38511 for more details.
+         $moreactions = get_plugins_with_function('bulk_user_actions', 'lib.php');
+         foreach ($moreactions as $plugintype => $plugins) {
+             foreach ($plugins as $pluginfunction) {
+                 $actions += $pluginfunction();
+             }
+         }
+         return $actions;
+     }
+     /**
+      * Form definition
+      */
+     public function definition() {
+         global $CFG;
+         $mform =& $this->_form;
+         $actions = [0 => get_string('choose') . '...'];
+         $bulkactions = $this->get_actions();
+         foreach ($bulkactions as $key => $action) {
+             $actions[$key] = $action->text;
          }
          $objs = array();
          $objs[] =& $mform->createElement('select', 'action', null, $actions);
diff --cc lib/upgrade.txt
Simple merge