MDL-69454 core_search: consistent mod searches

This commit is contained in:
Bas Brands 2020-08-31 14:20:10 +02:00
parent 411cf64738
commit 4c71e1d0d0
6 changed files with 103 additions and 58 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@template core/checkbox
Chooser search template.
Example context (json):
{
"name": "fullsearch",
"id": "fullsearch",
"checked": true,
"value": "1",
"label": "Reset options"
}
}}
<div class="custom-control custom-checkbox">
<input type="checkbox" name={{{ name }}} class="custom-control-input" value={{{ value }}} id="{{{ id }}}" {{#checked}} checked="checked" {{/checked}}>
<label class="custom-control-label" for="{{{ id }}}">{{{ label }}}</label>
</div>

View file

@ -62,5 +62,8 @@
</button> </button>
</div> </div>
</div> </div>
{{#otherfields}}
<div class="ml-2">{{{ otherfields }}}</div>
{{/otherfields}}
</form> </form>
</div> </div>

View file

@ -63,11 +63,16 @@ class quick_search_form implements renderable, templatable {
} }
public function export_for_template(renderer_base $output) { public function export_for_template(renderer_base $output) {
$hiddenfields = [
(object) ['name' => 'id', 'value' => $this->courseid],
];
$data = [ $data = [
'actionurl' => $this->actionurl->out(false), 'action' => $this->actionurl->out(false),
'courseid' => $this->courseid, 'hiddenfields' => $hiddenfields,
'query' => $this->query, 'query' => $this->query,
'helpicon' => $this->helpicon->export_for_template($output), 'helpicon' => $this->helpicon->export_for_template($output),
'inputname' => 'search',
'searchstring' => get_string('searchforums', 'mod_forum')
]; ];
return $data; return $data;
} }

View file

@ -21,27 +21,14 @@
Example context (json): Example context (json):
{ {
"actionurl": "https://domain.example/mod/forum/search.php", "action": "https://domain.example/mod/forum/search.php",
"courseid": "2",
"helpicon": "<a class='btn'><i class='icon fa fa-question-circle'></i></a>", "helpicon": "<a class='btn'><i class='icon fa fa-question-circle'></i></a>",
"query": "find this post" "query": "find this post",
"inputname": "search"
} }
}} }}
<div class="forumsearch"> {{#helpicon}}
<form action="{{actionurl}}" class="form-inline"> {{>core/help_icon}}
<input type="hidden" name="id" value="{{courseid}}"> {{/helpicon}}
<div class="input-group"> {{< core/search_input }}
<div class="input-group-prepend"> {{/ core/search_input }}
{{#helpicon}}
{{>core/help_icon}}
{{/helpicon}}
</div>
<label class="sr-only" for="search">{{#str}}search, forum{{/str}}</label>
<input id="search" name="search" type="text" class="form-control" value="{{query}}">
<div class="input-group-append">
<button class="btn btn-secondary" id="searchforums" type="submit">{{#str}}searchforums, mod_forum{{/str}}</button>
</div>
</div>
</form>
</div>

View file

@ -380,27 +380,35 @@ if ($glossary->intro && $showcommonelements) {
/// Search box /// Search box
if ($showcommonelements ) { if ($showcommonelements ) {
echo '<form method="post" class="form form-inline mb-1" action="' . $CFG->wwwroot . '/mod/glossary/view.php">'; $fullsearchchecked = false;
if ($mode == 'search') {
echo '<input type="text" name="hook" size="20" value="'.s($hook).'" alt="'.$strsearch.'" class="form-control"/> ';
} else {
echo '<input type="text" name="hook" size="20" value="" alt="'.$strsearch.'" class="form-control"/> ';
}
echo '<input type="submit" value="'.$strsearch.'" name="searchbutton" class="btn btn-secondary mr-1"/> ';
if ($fullsearch || $mode != 'search') { if ($fullsearch || $mode != 'search') {
$fullsearchchecked = 'checked="checked"'; $fullsearchchecked = true;
} else {
$fullsearchchecked = '';
} }
echo '<span class="checkbox"><label for="fullsearch">';
echo ' <input type="checkbox" name="fullsearch" id="fullsearch" value="1" '.$fullsearchchecked.'/> ';
echo '<input type="hidden" name="mode" value="search" />';
echo '<input type="hidden" name="id" value="'.$cm->id.'" />';
echo $strsearchindefinition.'</label></span>';
echo '</form>'; $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 /// Show the add entry button if allowed

View file

@ -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) { function wiki_search_form($cm, $search = '', $subwiki = null) {
global $CFG, $OUTPUT; global $OUTPUT;
$output = '<div class="wikisearch">'; $hiddenfields = [
$output .= '<form method="post" action="' . $CFG->wwwroot . '/mod/wiki/search.php" style="display:inline">'; (object) ['type' => 'hidden', 'name' => 'courseid', 'value' => $cm->course],
$output .= '<fieldset class="invisiblefieldset">'; (object) ['type' => 'hidden', 'name' => 'cmid', 'value' => $cm->id],
$output .= '<legend class="accesshide">'. get_string('searchwikis', 'wiki') .'</legend>'; (object) ['type' => 'hidden', 'name' => 'searchwikicontent', 'value' => 1],
$output .= '<label class="accesshide" for="searchwiki">' . get_string("searchterms", "wiki") . '</label>'; ];
$output .= '<input id="searchwiki" name="searchstring" type="text" size="18" value="' . s($search, true) . '" alt="search" />';
$output .= '<input name="courseid" type="hidden" value="' . $cm->course . '" />';
$output .= '<input name="cmid" type="hidden" value="' . $cm->id . '" />';
if (!empty($subwiki->id)) { if (!empty($subwiki->id)) {
$output .= '<input name="subwikiid" type="hidden" value="' . $subwiki->id . '" />'; $hiddenfields[] = (object) ['type' => 'hidden', 'name' => 'subwikiid', 'value' => $subwiki->id];
} }
$output .= '<input name="searchwikicontent" type="hidden" value="1" />'; $data = [
$output .= '<input value="' . get_string('searchwikis', 'wiki') . '" class="btn btn-secondary" type="submit" />'; 'action' => new moodle_url('/mod/wiki/search.php'),
$output .= '</fieldset>'; 'hiddenfields' => $hiddenfields,
$output .= '</form>'; 'inputname' => 'searchstring',
$output .= '</div>'; 'query' => s($search, true),
'searchstring' => get_string('searchwikis', 'wiki'),
return $output; 'extraclasses' => 'mt-2'
];
return $OUTPUT->render_from_template('core/search_input', $data);
} }
function wiki_extend_navigation(navigation_node $navref, $course, $module, $cm) { function wiki_extend_navigation(navigation_node $navref, $course, $module, $cm) {
global $CFG, $PAGE, $USER; global $CFG, $PAGE, $USER;