Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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\bank;
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  
  29  /**
  30   * A question bank column which gathers together all the actions into a menu.
  31   *
  32   * This question bank column, if added to the question bank, will
  33   * replace all of the other columns which implement the
  34   * {@link menuable_action} interface and replace them with a single
  35   * column containing an Edit menu.
  36   *
  37   * @copyright 2019 The Open University
  38   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class edit_menu_column extends column_base {
  41      /**
  42       * @var menuable_action[]
  43       */
  44      protected $actions;
  45  
  46      /**
  47       * Set up the list of actions that should be shown in the menu.
  48       *
  49       * This takes a list of column object (the list from a question
  50       * bank view). It extracts all the ones that should go in the menu
  51       * and stores them for later use. Then it returns the remaining columns.
  52       *
  53       * @param column_base[] $allcolumns a set of columns.
  54       * @return column_base[] the non-action columns from the set.
  55       */
  56      public function claim_menuable_columns($allcolumns) {
  57          $remainingcolumns = [];
  58          foreach ($allcolumns as $key => $column) {
  59              if ($column instanceof menuable_action) {
  60                  $this->actions[$key] = $column;
  61              } else {
  62                  $remainingcolumns[$key] = $column;
  63              }
  64          }
  65          return $remainingcolumns;
  66      }
  67  
  68      protected function get_title() {
  69          return get_string('actions');
  70      }
  71  
  72      public function get_name() {
  73          return 'editmenu';
  74      }
  75  
  76      protected function display_content($question, $rowclasses) {
  77          global $OUTPUT;
  78  
  79          $menu = new \action_menu();
  80          $menu->set_menu_trigger(get_string('edit'));
  81          $menu->set_alignment(\action_menu::TL, \action_menu::BL);
  82          foreach ($this->actions as $actioncolumn) {
  83              $action = $actioncolumn->get_action_menu_link($question);
  84              if ($action) {
  85                  $menu->add($action);
  86              }
  87          }
  88  
  89          $qtypeactions = \question_bank::get_qtype($question->qtype, false)
  90                  ->get_extra_question_bank_actions($question);
  91          foreach ($qtypeactions as $action) {
  92              $menu->add($action);
  93          }
  94  
  95          echo $OUTPUT->render($menu);
  96      }
  97  
  98      public function get_required_fields() {
  99          return ['q.qtype'];
 100      }
 101  }