Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.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   * Search area category.
  19   *
  20   * @package     core_search
  21   * @copyright   Dmitrii Metelkin <dmitriim@catalyst-au.net>
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_search;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Search area category.
  31   *
  32   * @package     core_search
  33   * @copyright   Dmitrii Metelkin <dmitriim@catalyst-au.net>
  34   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class area_category {
  37  
  38      /**
  39       * Category name.
  40       * @var string
  41       */
  42      protected $name;
  43  
  44      /**
  45       * Category visible name.
  46       * @var string
  47       */
  48      protected $visiblename;
  49  
  50      /**
  51       * Category order.
  52       * @var int
  53       */
  54      protected $order = 0;
  55  
  56      /**
  57       * Category areas.
  58       * @var \core_search\base[]
  59       */
  60      protected $areas = [];
  61  
  62      /**
  63       * Constructor.
  64       *
  65       * @param string $name Unique name of the category.
  66       * @param string $visiblename Visible name of the category.
  67       * @param int $order Category position in the list (smaller numbers will be displayed first).
  68       * @param \core_search\base[] $areas A list of search areas associated with this category.
  69       */
  70      public function __construct(string $name, string $visiblename, int $order = 0, array  $areas = []) {
  71          $this->name = $name;
  72          $this->visiblename = $visiblename;
  73          $this->order = $order;
  74          $this->set_areas($areas);
  75      }
  76  
  77      /**
  78       * Get name.
  79       *
  80       * @return string
  81       */
  82      public function get_name() {
  83          return $this->name;
  84      }
  85  
  86      /**
  87       * Get visible name.
  88       *
  89       * @return string
  90       */
  91      public function get_visiblename() {
  92          return $this->visiblename;
  93      }
  94  
  95      /**
  96       * Get order to display.
  97       *
  98       * @return int
  99       */
 100      public function get_order() {
 101          return $this->order;
 102      }
 103  
 104      /**
 105       * Return a keyed by area id list of areas for this category.
 106       *
 107       * @return \core_search\base[]
 108       */
 109      public function get_areas() {
 110          return $this->areas;
 111      }
 112  
 113      /**
 114       * Set list of search areas for this category,
 115       *
 116       * @param \core_search\base[] $areas
 117       */
 118      public function set_areas(array $areas) {
 119          foreach ($areas as $area) {
 120              if ($area instanceof base && !key_exists($area->get_area_id(), $this->areas)) {
 121                  $this->areas[$area->get_area_id()] = $area;
 122              }
 123          }
 124      }
 125  
 126  }