diff --git a/course/renderer.php b/course/renderer.php index 9d1439c7ad8..ba33b0647b8 100644 --- a/course/renderer.php +++ b/course/renderer.php @@ -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); diff --git a/course/search.php b/course/search.php index 9dcd11292a2..144767d452f 100644 --- a/course/search.php +++ b/course/search.php @@ -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'); diff --git a/course/templates/course_search_form.mustache b/course/templates/course_search_form.mustache index d709096c015..f8ec18620ca 100644 --- a/course/templates/course_search_form.mustache +++ b/course/templates/course_search_form.mustache @@ -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": "" + "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:" + }] } }}
- + + {{#helpicon}} {{>core/help_icon}} diff --git a/search/classes/manager.php b/search/classes/manager.php index a68c6e93d73..75f65f6e598 100644 --- a/search/classes/manager.php +++ b/search/classes/manager.php @@ -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). diff --git a/search/tests/manager_test.php b/search/tests/manager_test.php index 6b04ee9dfdd..f0a2b570f86 100644 --- a/search/tests/manager_test.php +++ b/search/tests/manager_test.php @@ -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;