Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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  /**
  18   * Course format filter.
  19   *
  20   * @package    tool_usertours
  21   * @copyright  2017 The Open University
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tool_usertours\local\filter;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use tool_usertours\tour;
  30  use context;
  31  
  32  /**
  33   * Course format filter.
  34   *
  35   * @copyright  2017 The Open University
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class courseformat extends base {
  39      /**
  40       * The name of the filter.
  41       *
  42       * @return  string
  43       */
  44      public static function get_filter_name() {
  45          return 'courseformat';
  46      }
  47  
  48      /**
  49       * Retrieve the list of available filter options.
  50       *
  51       * @return  array                   An array whose keys are the valid options
  52       *                                  And whose values are the values to display
  53       */
  54      public static function get_filter_options() {
  55          $options = [];
  56          $courseformats = get_sorted_course_formats(true);
  57          foreach ($courseformats as $courseformat) {
  58              $options[$courseformat] = get_string('pluginname', "format_$courseformat");
  59          }
  60          return $options;
  61      }
  62  
  63      /**
  64       * Check whether the filter matches the specified tour and/or context.
  65       *
  66       * @param   tour        $tour       The tour to check
  67       * @param   context     $context    The context to check
  68       * @return  boolean
  69       */
  70      public static function filter_matches(tour $tour, context $context) {
  71          global $COURSE;
  72          $values = $tour->get_filter_values('courseformat');
  73          if (empty($values)) {
  74              // There are no values configured, meaning all.
  75              return true;
  76          }
  77          if (empty($COURSE->format)) {
  78              return false;
  79          }
  80          return in_array($COURSE->format, $values);
  81      }
  82  }