mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'MDL-60916-master_replace_course_search_wth_global_search' of https://github.com/gmrsagar/moodle
This commit is contained in:
commit
59008247db
@ -372,13 +372,14 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$inputsize = 30;
|
||||
}
|
||||
|
||||
$data = (object) [
|
||||
'searchurl' => (new moodle_url('/course/search.php'))->out(false),
|
||||
'id' => $formid,
|
||||
'inputid' => $inputid,
|
||||
'inputsize' => $inputsize,
|
||||
'value' => $value
|
||||
];
|
||||
$data = new stdClass();
|
||||
$data->searchurl = \core_search\manager::get_course_search_url()->out(false);
|
||||
$data->id = $formid;
|
||||
$data->inputid = $inputid;
|
||||
$data->inputsize = $inputsize;
|
||||
$data->value = $value;
|
||||
$data->areaids = 'core_course-course';
|
||||
|
||||
if ($format != 'navbar') {
|
||||
$helpicon = new \help_icon('coursesearch', 'core');
|
||||
$data->helpicon = $helpicon->export_for_template($this);
|
||||
|
@ -24,6 +24,7 @@
|
||||
require_once("../config.php");
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
|
||||
$q = optional_param('q', '', PARAM_RAW); // Global search words.
|
||||
$search = optional_param('search', '', PARAM_RAW); // search words
|
||||
$page = optional_param('page', 0, PARAM_INT); // which page to show
|
||||
$perpage = optional_param('perpage', '', PARAM_RAW); // how many per page, may be integer or 'all'
|
||||
@ -31,6 +32,11 @@ $blocklist = optional_param('blocklist', 0, PARAM_INT);
|
||||
$modulelist= optional_param('modulelist', '', PARAM_PLUGIN);
|
||||
$tagid = optional_param('tagid', '', PARAM_INT); // searches for courses tagged with this tag id
|
||||
|
||||
// Use global search.
|
||||
if ($q) {
|
||||
$search = $q;
|
||||
}
|
||||
|
||||
// List of minimum capabilities which user need to have for editing/moving course
|
||||
$capabilities = array('moodle/course:create', 'moodle/category:manage');
|
||||
|
||||
|
@ -17,22 +17,27 @@
|
||||
{{!
|
||||
@template core_course/course_search_form
|
||||
|
||||
This template renders the search form.
|
||||
This template renders the form for course search.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"searchurl": "https://domain.example/course/search.php",
|
||||
"searchurl": "https://moodlesite/course/search.php",
|
||||
"id": "coursesearch",
|
||||
"inputid": "coursesearchbox",
|
||||
"inputsize": "30",
|
||||
"value": "Find in course",
|
||||
"helpicon": "<a class='btn'><i class='icon fa fa-question-circle'></i></a>"
|
||||
"inputsize": 30,
|
||||
"value": "certificate",
|
||||
"name" : "q",
|
||||
"helpicon": [{
|
||||
"heading": "Search courses",
|
||||
"text": "You can search for multiple words at once and can refine your search as follows:"
|
||||
}]
|
||||
}
|
||||
}}
|
||||
<form action="{{searchurl}}" id="{{id}}" method="get" class="form-inline">
|
||||
<fieldset class="coursesearchbox invisiblefieldset">
|
||||
<label for="{{inputid}}">{{#str}}searchcourses{{/str}}</label>
|
||||
<input id="{{inputid}}" name="search" type="text" size="{{inputsize}}" value="{{value}}" class="form-control">
|
||||
<input id="{{inputid}}" name="q" type="text" size="{{inputsize}}" value="{{value}}" class="form-control">
|
||||
<input name="areaids" type="hidden" value="{{areaids}}">
|
||||
<button class="btn btn-secondary" type="submit">{{#str}}go{{/str}}</button>
|
||||
{{#helpicon}}
|
||||
{{>core/help_icon}}
|
||||
|
@ -253,6 +253,21 @@ class manager {
|
||||
return !empty($CFG->enableglobalsearch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the search URL for course search
|
||||
*
|
||||
* @return moodle_url
|
||||
*/
|
||||
public static function get_course_search_url() {
|
||||
if (self::is_global_search_enabled()) {
|
||||
$searchurl = '/search/index.php';
|
||||
} else {
|
||||
$searchurl = '/course/search.php';
|
||||
}
|
||||
|
||||
return new \moodle_url($searchurl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether indexing is enabled or not (you can enable indexing even when search is not
|
||||
* enabled at the moment, so as to have it ready for students).
|
||||
|
@ -78,6 +78,20 @@ class search_manager_testcase extends advanced_testcase {
|
||||
$this->assertFalse(\core_search\manager::is_global_search_enabled());
|
||||
}
|
||||
|
||||
public function test_course_search_url() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// URL is course/search.php by default.
|
||||
$this->assertEquals(new moodle_url("/course/search.php"), \core_search\manager::get_course_search_url());
|
||||
|
||||
set_config('enableglobalsearch', true);
|
||||
$this->assertEquals(new moodle_url("/search/index.php"), \core_search\manager::get_course_search_url());
|
||||
|
||||
set_config('enableglobalsearch', false);
|
||||
$this->assertEquals(new moodle_url("/course/search.php"), \core_search\manager::get_course_search_url());
|
||||
}
|
||||
|
||||
public function test_search_areas() {
|
||||
global $CFG;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user