2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Search area category.
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
25 namespace core_search
;
27 defined('MOODLE_INTERNAL') ||
die();
30 * Search area category.
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
45 * Category visible name.
48 protected $visiblename;
58 * @var \core_search\base[]
60 protected $areas = [];
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.
70 public function __construct(string $name, string $visiblename, int $order = 0, array $areas = []) {
72 $this->visiblename
= $visiblename;
73 $this->order
= $order;
74 $this->set_areas($areas);
82 public function get_name() {
91 public function get_visiblename() {
92 return $this->visiblename
;
96 * Get order to display.
100 public function get_order() {
105 * Return a keyed by area id list of areas for this category.
107 * @return \core_search\base[]
109 public function get_areas() {
114 * Set list of search areas for this category,
116 * @param \core_search\base[] $areas
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;