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_deletequestion;
  18  
  19  use core\output\datafilter;
  20  use core_question\local\bank\condition;
  21  
  22  use core_question\local\bank\question_version_status;
  23  
  24  /**
  25   * This class controls whether hidden / deleted questions are hidden in the list.
  26   *
  27   * @package    qbank_deletequestion
  28   * @copyright  2013 Ray Morris
  29   * @author     2021 Safat Shahin <safatshahin@catalyst-au.net>
  30   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  class hidden_condition extends condition {
  33  
  34      public static function get_condition_key() {
  35          return 'hidden';
  36      }
  37  
  38      /**
  39       * Build query from filter value
  40       *
  41       * @param array $filter filter properties
  42       * @return array where sql and params
  43       */
  44      public static function build_query_from_filter(array $filter): array {
  45          $showhidden = (bool)$filter['values'][0];
  46          $where = "";
  47          $params = [];
  48          if (!$showhidden) {
  49              $where = "qv.status <> :hidden_condition";
  50              $params = ['hidden_condition' => question_version_status::QUESTION_STATUS_HIDDEN];
  51          }
  52          return [$where, $params];
  53      }
  54  
  55      public function get_title() {
  56          return get_string('showhidden', 'core_question');
  57      }
  58  
  59      public function get_join_list(): array {
  60          return [
  61              datafilter::JOINTYPE_ANY,
  62          ];
  63      }
  64  
  65      public function get_filter_class() {
  66          return 'qbank_deletequestion/datafilter/filtertypes/hidden';
  67      }
  68  
  69      public function is_required(): bool {
  70          return true;
  71      }
  72  }