Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is 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  namespace qbank_columnsortorder\external;
  18  
  19  use context_system;
  20  use core_external\external_api;
  21  use core_external\external_function_parameters;
  22  use core_external\external_multiple_structure;
  23  use core_external\external_value;
  24  use qbank_columnsortorder\column_manager;
  25  
  26  /**
  27   * External function for saving the list of hidden columns.
  28   *
  29   * @package   qbank_columnsortorder
  30   * @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
  31   * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
  32   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class set_hidden_columns extends external_api {
  35      /**
  36       * Returns description of method parameters.
  37       *
  38       * @return external_function_parameters
  39       */
  40      public static function execute_parameters(): external_function_parameters {
  41          return new external_function_parameters([
  42              'columns' => new external_multiple_structure(
  43                  new external_value(PARAM_TEXT, 'Plugin name for the hidden column', VALUE_REQUIRED),
  44                  'List of hidden columns',
  45                  VALUE_DEFAULT,
  46                  null,
  47                  NULL_ALLOWED,
  48              ),
  49              'global' => new external_value(
  50                  PARAM_BOOL,
  51                  'Set global config setting, rather than user preference',
  52                  VALUE_DEFAULT,
  53                  false
  54              ),
  55          ]);
  56      }
  57  
  58      /**
  59       * Returns description of method result value.
  60       *
  61       */
  62      public static function execute_returns(): void {
  63      }
  64  
  65      /**
  66       * Set hidden columns
  67       * Save against user preference if specified
  68       *
  69       * @param ?array $columns List of hidden columns. Null value clears the setting.
  70       * @param bool $global Set global config setting, rather than user preference
  71       */
  72      public static function execute(?array $columns, bool $global = false): void {
  73          [
  74              'columns' => $columns,
  75              'global' => $global,
  76          ] = self::validate_parameters(
  77              self::execute_parameters(),
  78              [
  79                  'columns' => $columns,
  80                  'global' => $global,
  81              ]
  82          );
  83  
  84          $context = context_system::instance();
  85          self::validate_context($context);
  86          if ($global) {
  87              require_capability('moodle/site:config', $context);
  88          }
  89  
  90          column_manager::set_hidden_columns($columns, $global);
  91      }
  92  }