| 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 | namespace qbank_columnsortorder\local\bank;
 | 
        
           |  |  | 18 |   | 
        
           |  |  | 19 | use core_question\local\bank\column_action_base;
 | 
        
           |  |  | 20 | use core_question\local\bank\column_base;
 | 
        
           |  |  | 21 |   | 
        
           |  |  | 22 | /**
 | 
        
           |  |  | 23 |  * Remove a column
 | 
        
           |  |  | 24 |  *
 | 
        
           |  |  | 25 |  * This action will display a link that will set the current column as hidden, then redirect back the current page.
 | 
        
           |  |  | 26 |  *
 | 
        
           |  |  | 27 |  * @package   qbank_columnsortorder
 | 
        
           |  |  | 28 |  * @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
 | 
        
           |  |  | 29 |  * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
 | 
        
           |  |  | 30 |  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 31 |  */
 | 
        
           |  |  | 32 | class column_action_remove extends column_action_base {
 | 
        
           |  |  | 33 |     /** @var bool True if we are changing global config, false for user preferences. */
 | 
        
           |  |  | 34 |     protected bool $global;
 | 
        
           |  |  | 35 |   | 
        
           |  |  | 36 |     /** @var string Label for the Remove action. */
 | 
        
           |  |  | 37 |     protected string $remove;
 | 
        
           |  |  | 38 |   | 
        
           |  |  | 39 |     protected function init(): void {
 | 
        
           |  |  | 40 |         $this->global = false;
 | 
        
           |  |  | 41 |         $this->remove = get_string('remove');
 | 
        
           |  |  | 42 |     }
 | 
        
           |  |  | 43 |   | 
        
           |  |  | 44 |     /**
 | 
        
           |  |  | 45 |      * Set the $global property to indicate whether we are changing global config.
 | 
        
           |  |  | 46 |      *
 | 
        
           |  |  | 47 |      * This action is used on both the user and admin screens, so requires this additional method.
 | 
        
           |  |  | 48 |      *
 | 
        
           |  |  | 49 |      * @param bool $global
 | 
        
           |  |  | 50 |      * @return void
 | 
        
           |  |  | 51 |      */
 | 
        
           |  |  | 52 |     public function set_global(bool $global): void {
 | 
        
           |  |  | 53 |         $this->global = $global;
 | 
        
           |  |  | 54 |     }
 | 
        
           |  |  | 55 |   | 
        
           |  |  | 56 |     public function get_action_menu_link(column_base $column): ?\action_menu_link {
 | 
        
           |  |  | 57 |         $actionurl = new \moodle_url('/question/bank/columnsortorder/actions.php', [
 | 
        
           |  |  | 58 |             'column' => $column->get_column_id(),
 | 
        
           |  |  | 59 |             'action' => 'remove',
 | 
        
           |  |  | 60 |             'sesskey' => sesskey(),
 | 
        
           |  |  | 61 |             'returnurl' => new \moodle_url($this->qbank->returnurl),
 | 
        
           |  |  | 62 |         ]);
 | 
        
           |  |  | 63 |         if ($this->global) {
 | 
        
           |  |  | 64 |             $actionurl->param('global', $this->global);
 | 
        
           |  |  | 65 |         }
 | 
        
           |  |  | 66 |         return new \action_menu_link_secondary(
 | 
        
           |  |  | 67 |             $actionurl,
 | 
        
           |  |  | 68 |             new \pix_icon('t/delete', ''),
 | 
        
           |  |  | 69 |             $this->remove,
 | 
        
           |  |  | 70 |             [
 | 
        
           |  |  | 71 |                 'class' => 'action-link',
 | 
        
           |  |  | 72 |                 'title' => get_string('removecolumn', 'qbank_columnsortorder', $column->get_title()),
 | 
        
           |  |  | 73 |                 'data-action' => 'remove',
 | 
        
           |  |  | 74 |                 'data-column' => $column->get_column_id(),
 | 
        
           |  |  | 75 |             ]
 | 
        
           |  |  | 76 |         );
 | 
        
           |  |  | 77 |     }
 | 
        
           |  |  | 78 | }
 |