Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * A question bank column which gathers together all the actions into a menu.
  19   *
  20   * @package   core_question
  21   * @copyright 2019 The Open University
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_question\local\bank;
  26  
  27  /**
  28   * A question bank column which gathers together all the actions into a menu.
  29   *
  30   * This question bank column, if added to the question bank, will
  31   * replace all of the other columns which implement the
  32   * {@see menuable_action} interface and replace them with a single
  33   * column containing an Edit menu.
  34   *
  35   * @copyright 2019 The Open University
  36   * @author    2021 Safat Shahin <safatshahin@catalyst-au.net>
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class edit_menu_column extends column_base {
  40      /**
  41       * @var menuable_action[]
  42       */
  43      protected $actions;
  44  
  45      /**
  46       * Set up the list of actions that should be shown in the menu.
  47       *
  48       * This takes a list of column object (the list from a question
  49       * bank view). It extracts all the ones that should go in the menu
  50       * and stores them for later use. Then it returns the remaining columns.
  51       *
  52       * @param column_base[] $allcolumns a set of columns.
  53       * @return column_base[] the non-action columns from the set.
  54       */
  55      public function claim_menuable_columns($allcolumns): array {
  56          $remainingcolumns = [];
  57          foreach ($allcolumns as $key => $column) {
  58              if ($column instanceof menuable_action) {
  59                  $this->actions[$key] = $column;
  60              } else {
  61                  $remainingcolumns[$key] = $column;
  62              }
  63          }
  64          return $remainingcolumns;
  65      }
  66  
  67      public function get_title() {
  68          return get_string('actions');
  69      }
  70  
  71      public function get_name(): string {
  72          return 'editmenu';
  73      }
  74  
  75      protected function display_content($question, $rowclasses): void {
  76          global $OUTPUT;
  77  
  78          $menu = new \action_menu();
  79          $menu->set_menu_trigger(get_string('edit'));
  80          foreach ($this->actions as $actioncolumn) {
  81              $action = $actioncolumn->get_action_menu_link($question);
  82              if ($action) {
  83                  $menu->add($action);
  84              }
  85          }
  86  
  87          $qtypeactions = \question_bank::get_qtype($question->qtype, false)
  88                  ->get_extra_question_bank_actions($question);
  89          foreach ($qtypeactions as $action) {
  90              $menu->add($action);
  91          }
  92  
  93          echo $OUTPUT->render($menu);
  94      }
  95  
  96      public function get_required_fields():array {
  97          return ['q.qtype'];
  98      }
  99  
 100      /**
 101       * Get menuable actions.
 102       *
 103       * @return menuable_action Menuable actions.
 104       */
 105      public function get_actions(): array {
 106          return $this->actions;
 107      }
 108  
 109      public function get_extra_classes(): array {
 110          return ['pr-3'];
 111      }
 112  
 113  }