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 * Global search report
20 * @package report_search
21 * @copyright Prateek Sachan {@link http://prateeksachan.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__ . '/../../config.php');
26 require_once($CFG->libdir . '/adminlib.php');
28 admin_externalpage_setup('reportsearch');
30 $pagetitle = get_string('pluginname', 'report_search');
31 $PAGE->set_title($pagetitle);
32 $PAGE->set_heading($pagetitle);
34 echo $OUTPUT->header();
35 echo $OUTPUT->heading($pagetitle);
37 if (\core_search\manager::is_global_search_enabled() === false) {
38 $renderer = $PAGE->get_renderer('core_search');
39 echo $renderer->render_search_disabled();
40 echo $OUTPUT->footer();
44 $renderer = $PAGE->get_renderer('report_search');
45 $search = \core_search\manager::instance();
47 // All enabled components.
48 $searchareas = $search->get_search_areas_list(true);
50 $mform = new \report_search\output\form(null, array('searchareas' => $searchareas));
51 if ($data = $mform->get_data()) {
53 if (!empty($data->delete)) {
54 if (!empty($data->all)) {
55 $search->delete_index();
58 // We check that the component exist and is enabled.
59 foreach ($searchareas as $areaid => $searcharea) {
60 if (!empty($data->{$areaid})) {
62 $search->delete_index($areaid);
67 if (!empty($data->all) || $anydelete) {
68 echo $OUTPUT->notification(get_string('deleted', 'report_search'), 'notifysuccess');
71 $cache = \cache::make('core', 'search_results');
76 if (!empty($data->reindex)) {
77 // Force full reindex. Quite heavy operation.
79 $search->optimize_index();
80 echo $OUTPUT->notification(get_string('indexed', 'report_search'), 'notifysuccess');
84 // After processing the form as config might change depending on the action.
85 $areasconfig = $search->get_areas_config($searchareas);
87 // Ensure that all search areas that we are going to display have config.
88 $missingareas = array_diff_key($searchareas, $areasconfig);
89 foreach ($missingareas as $searcharea) {
90 $search->reset_config($searcharea->get_area_id());
93 echo $renderer->render_report($mform, $searchareas, $areasconfig);
94 echo $OUTPUT->footer();