From e9435e8f6d64fa973b7b9ebf3c92ee95aa978ead Mon Sep 17 00:00:00 2001 From: Bas Brands Date: Mon, 31 Aug 2020 14:20:10 +0200 Subject: [PATCH] MDL-69454 core_search: consistent mod searches --- lib/templates/checkbox.mustache | 34 ++++++++++++++++++ lib/templates/search_input.mustache | 3 ++ mod/forum/classes/output/quick_search_form.php | 9 +++-- mod/forum/templates/quick_search_form.mustache | 29 +++++----------- mod/glossary/view.php | 48 +++++++++++++++----------- mod/wiki/lib.php | 46 ++++++++++++++---------- 6 files changed, 107 insertions(+), 62 deletions(-) create mode 100644 lib/templates/checkbox.mustache diff --git a/lib/templates/checkbox.mustache b/lib/templates/checkbox.mustache new file mode 100644 index 00000000000..518e662b2cf --- /dev/null +++ b/lib/templates/checkbox.mustache @@ -0,0 +1,34 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template core/checkbox + + Chooser search template. + + Example context (json): + { + "name": "fullsearch", + "id": "fullsearch", + "checked": true, + "value": "1", + "label": "Reset options" + } +}} +
+ + +
\ No newline at end of file diff --git a/lib/templates/search_input.mustache b/lib/templates/search_input.mustache index 48c20f7b65d..5d47c5ee72d 100644 --- a/lib/templates/search_input.mustache +++ b/lib/templates/search_input.mustache @@ -62,5 +62,8 @@ + {{#otherfields}} +
{{{ otherfields }}}
+ {{/otherfields}} \ No newline at end of file diff --git a/mod/forum/classes/output/quick_search_form.php b/mod/forum/classes/output/quick_search_form.php index dc024b51ae8..80f55d45b0f 100644 --- a/mod/forum/classes/output/quick_search_form.php +++ b/mod/forum/classes/output/quick_search_form.php @@ -63,11 +63,16 @@ class quick_search_form implements renderable, templatable { } public function export_for_template(renderer_base $output) { + $hiddenfields = [ + (object) ['name' => 'id', 'value' => $this->courseid], + ]; $data = [ - 'actionurl' => $this->actionurl->out(false), - 'courseid' => $this->courseid, + 'action' => $this->actionurl->out(false), + 'hiddenfields' => $hiddenfields, 'query' => $this->query, 'helpicon' => $this->helpicon->export_for_template($output), + 'inputname' => 'search', + 'searchstring' => get_string('searchforums', 'mod_forum') ]; return $data; } diff --git a/mod/forum/templates/quick_search_form.mustache b/mod/forum/templates/quick_search_form.mustache index e3d17c51aaa..21b22c6f32c 100644 --- a/mod/forum/templates/quick_search_form.mustache +++ b/mod/forum/templates/quick_search_form.mustache @@ -21,27 +21,14 @@ Example context (json): { - "actionurl": "https://domain.example/mod/forum/search.php", - "courseid": "2", + "action": "https://domain.example/mod/forum/search.php", "helpicon": "", - "query": "find this post" + "query": "find this post", + "inputname": "search" } }} -
-
- -
-
- {{#helpicon}} - {{>core/help_icon}} - {{/helpicon}} -
- - -
- -
-
- -
-
+{{#helpicon}} + {{>core/help_icon}} +{{/helpicon}} +{{< core/search_input }} +{{/ core/search_input }} diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 4c5c8fc8120..adadafe2c0a 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -380,27 +380,35 @@ if ($glossary->intro && $showcommonelements) { /// Search box if ($showcommonelements ) { - echo '
'; - - - if ($mode == 'search') { - echo ' '; - } else { - echo ' '; - } - echo ' '; + $fullsearchchecked = false; if ($fullsearch || $mode != 'search') { - $fullsearchchecked = 'checked="checked"'; - } else { - $fullsearchchecked = ''; - } - echo ''; - - echo '
'; + $fullsearchchecked = true; + } + + $check = [ + 'name' => 'fullsearch', + 'id' => 'fullsearch', + 'value' => '1', + 'checked' => $fullsearchchecked, + 'label' => $strsearchindefinition + ]; + + $checkbox = $OUTPUT->render_from_template('core/checkbox', $check); + + $hiddenfields = [ + (object) ['name' => 'id', 'value' => $cm->id], + (object) ['name' => 'mode', 'value' => 'search'], + ]; + $data = [ + 'action' => new moodle_url('/mod/glossary/view.php'), + 'hiddenfields' => $hiddenfields, + 'otherfields' => $checkbox, + 'inputname' => 'hook', + 'query' => ($mode == 'search') ? s($hook) : '', + 'searchstring' => get_string('search'), + 'extraclasses' => 'my-2' + ]; + echo $OUTPUT->render_from_template('core/search_input', $data); } /// Show the add entry button if allowed diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php index cb42b9f7826..809aaadcf6e 100644 --- a/mod/wiki/lib.php +++ b/mod/wiki/lib.php @@ -441,28 +441,36 @@ function wiki_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa } } +/** + * Search for wiki + * + * @param stdClass $cm course module object + * @param string $search searchword. + * @param stdClass $subwiki Optional Subwiki. + * @return Search wiki input form + */ function wiki_search_form($cm, $search = '', $subwiki = null) { - global $CFG, $OUTPUT; - - $output = '
'; - $output .= '
'; - $output .= '
'; - $output .= ''. get_string('searchwikis', 'wiki') .''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - if (!empty($subwiki->id)) { - $output .= ''; - } - $output .= ''; - $output .= ''; - $output .= '
'; - $output .= '
'; - $output .= '
'; + global $OUTPUT; - return $output; + $hiddenfields = [ + (object) ['type' => 'hidden', 'name' => 'courseid', 'value' => $cm->course], + (object) ['type' => 'hidden', 'name' => 'cmid', 'value' => $cm->id], + (object) ['type' => 'hidden', 'name' => 'searchwikicontent', 'value' => 1], + ]; + if (!empty($subwiki->id)) { + $hiddenfields[] = (object) ['type' => 'hidden', 'name' => 'subwikiid', 'value' => $subwiki->id]; + } + $data = [ + 'action' => new moodle_url('/mod/wiki/search.php'), + 'hiddenfields' => $hiddenfields, + 'inputname' => 'searchstring', + 'query' => s($search, true), + 'searchstring' => get_string('searchwikis', 'wiki'), + 'extraclasses' => 'mt-2' + ]; + return $OUTPUT->render_from_template('core/search_input', $data); } + function wiki_extend_navigation(navigation_node $navref, $course, $module, $cm) { global $CFG, $PAGE, $USER; -- 2.11.4.GIT