Merge branch 'MDL-78408-402' of https://github.com/snake/moodle into MOODLE_402_STABLE
[moodle.git] / search / classes / area_category.php
blob975ed61908b27b7329294defd99c1b77247049da
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.
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/>.
17 /**
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();
29 /**
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
36 class area_category {
38 /**
39 * Category name.
40 * @var string
42 protected $name;
44 /**
45 * Category visible name.
46 * @var string
48 protected $visiblename;
50 /**
51 * Category order.
52 * @var int
54 protected $order = 0;
56 /**
57 * Category areas.
58 * @var \core_search\base[]
60 protected $areas = [];
62 /**
63 * Constructor.
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 = []) {
71 $this->name = $name;
72 $this->visiblename = $visiblename;
73 $this->order = $order;
74 $this->set_areas($areas);
77 /**
78 * Get name.
80 * @return string
82 public function get_name() {
83 return $this->name;
86 /**
87 * Get visible name.
89 * @return string
91 public function get_visiblename() {
92 return $this->visiblename;
95 /**
96 * Get order to display.
98 * @return int
100 public function get_order() {
101 return $this->order;
105 * Return a keyed by area id list of areas for this category.
107 * @return \core_search\base[]
109 public function get_areas() {
110 return $this->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;