| 1 | 
           efrain | 
           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 | 
           use \core\plugininfo\qbank;
  | 
        
        
            | 
            | 
           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 | 
            * {@see menu_action_column_base} interface and replace them with a single
  | 
        
        
            | 
            | 
           35 | 
            * column containing an Edit menu.
  | 
        
        
            | 
            | 
           36 | 
            *
  | 
        
        
            | 
            | 
           37 | 
            * @copyright 2019 The Open University
  | 
        
        
            | 
            | 
           38 | 
            * @author    2021 Safat Shahin <safatshahin@catalyst-au.net>
  | 
        
        
            | 
            | 
           39 | 
            * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           40 | 
            */
  | 
        
        
            | 
            | 
           41 | 
           class edit_menu_column extends column_base {
  | 
        
        
            | 
            | 
           42 | 
               public function get_title() {
  | 
        
        
            | 
            | 
           43 | 
                   return get_string('actions');
  | 
        
        
            | 
            | 
           44 | 
               }
  | 
        
        
            | 
            | 
           45 | 
              | 
        
        
            | 
            | 
           46 | 
               public function get_name(): string {
  | 
        
        
            | 
            | 
           47 | 
                   return 'editmenu';
  | 
        
        
            | 
            | 
           48 | 
               }
  | 
        
        
            | 
            | 
           49 | 
              | 
        
        
            | 
            | 
           50 | 
               protected function display_content($question, $rowclasses): void {
  | 
        
        
            | 
            | 
           51 | 
                   global $OUTPUT;
  | 
        
        
            | 
            | 
           52 | 
                   $actions = $this->qbank->get_question_actions();
  | 
        
        
            | 
            | 
           53 | 
              | 
        
        
            | 
            | 
           54 | 
                   $menu = new \action_menu();
  | 
        
        
            | 
            | 
           55 | 
                   $menu->set_menu_trigger(get_string('edit'));
  | 
        
        
           | 1441 | 
           ariadna | 
           56 | 
                   $menu->set_boundary('window');
  | 
        
        
           | 1 | 
           efrain | 
           57 | 
                   foreach ($actions as $action) {
  | 
        
        
            | 
            | 
           58 | 
                       $action = $action->get_action_menu_link($question);
  | 
        
        
            | 
            | 
           59 | 
                       if ($action) {
  | 
        
        
            | 
            | 
           60 | 
                           $menu->add($action);
  | 
        
        
            | 
            | 
           61 | 
                       }
  | 
        
        
            | 
            | 
           62 | 
                   }
  | 
        
        
            | 
            | 
           63 | 
              | 
        
        
            | 
            | 
           64 | 
                   $qtypeactions = \question_bank::get_qtype($question->qtype, false)
  | 
        
        
            | 
            | 
           65 | 
                           ->get_extra_question_bank_actions($question);
  | 
        
        
            | 
            | 
           66 | 
                   foreach ($qtypeactions as $action) {
  | 
        
        
            | 
            | 
           67 | 
                       $menu->add($action);
  | 
        
        
            | 
            | 
           68 | 
                   }
  | 
        
        
            | 
            | 
           69 | 
              | 
        
        
            | 
            | 
           70 | 
                   echo $OUTPUT->render($menu);
  | 
        
        
            | 
            | 
           71 | 
               }
  | 
        
        
            | 
            | 
           72 | 
              | 
        
        
            | 
            | 
           73 | 
               public function get_required_fields(): array {
  | 
        
        
            | 
            | 
           74 | 
                   return ['q.qtype'];
  | 
        
        
            | 
            | 
           75 | 
               }
  | 
        
        
            | 
            | 
           76 | 
              | 
        
        
            | 
            | 
           77 | 
               /**
  | 
        
        
            | 
            | 
           78 | 
                * Get menuable actions.
  | 
        
        
            | 
            | 
           79 | 
                *
  | 
        
        
            | 
            | 
           80 | 
                * @return menu_action_column_base Menuable actions.
  | 
        
        
            | 
            | 
           81 | 
                */
  | 
        
        
            | 
            | 
           82 | 
               public function get_actions(): array {
  | 
        
        
            | 
            | 
           83 | 
                   return $this->actions;
  | 
        
        
            | 
            | 
           84 | 
               }
  | 
        
        
            | 
            | 
           85 | 
              | 
        
        
            | 
            | 
           86 | 
               public function get_extra_classes(): array {
  | 
        
        
           | 1441 | 
           ariadna | 
           87 | 
                   return ['pe-3'];
  | 
        
        
           | 1 | 
           efrain | 
           88 | 
               }
  | 
        
        
            | 
            | 
           89 | 
              | 
        
        
            | 
            | 
           90 | 
           }
  |