Permalink
Browse files

Merge branch 'MDL-60953-master' of https://github.com/timhunt/moodle

  • Loading branch information...
dmonllao committed Apr 16, 2018
2 parents d2c8008 + 3c49b0e commit 9dbb24fa7a262631a8d96e44496b011869e6047f
Showing with 75 additions and 3 deletions.
  1. +35 −2 search/classes/output/form/search.php
  2. +5 −1 search/index.php
  3. +35 −0 search/tests/behat/search_query.feature
@@ -36,7 +36,7 @@ class search extends \moodleform {
* @return void
*/
function definition() {
global $CFG;
global $USER;
$mform =& $this->_form;
$mform->disable_form_change_checker();
@@ -95,9 +95,42 @@ function definition() {
$mform->addElement('course', 'courseids', get_string('courses', 'core'), $options);
$mform->setType('courseids', PARAM_INT);
// Course options should be hidden if we choose to search within a specific location.
if (!empty($this->_customdata['searchwithin'])) {
// Course options should be hidden if we choose to search within a specific location.
$mform->hideIf('courseids', 'searchwithin', 'ne', '');
// Get groups on course (we don't show group selector if there aren't any).
$courseid = $this->_customdata['withincourseid'];
$allgroups = groups_get_all_groups($courseid);
if ($allgroups && $search->get_engine()->supports_groups()) {
$groupnames = [];
foreach ($allgroups as $group) {
$groupnames[$group->id] = $group->name;
}
// Create group autocomplete option.
$options = array(
'multiple' => true,
'noselectionstring' => get_string('allgroups'),
);
$mform->addElement('autocomplete', 'groupids', get_string('groups'), $groupnames, $options);
// Is the second 'search within' option a cm?
if (!empty($this->_customdata['withincmid'])) {
// Find out if the cm supports groups.
$modinfo = get_fast_modinfo($courseid);
$cm = $modinfo->get_cm($this->_customdata['withincmid']);
if ($cm->effectivegroupmode != NOGROUPS) {
// If it does, group ids are available when you have course or module selected.
$mform->hideIf('groupids', 'searchwithin', 'eq', '');
} else {
// Group ids are only available if you have course selected.
$mform->hideIf('groupids', 'searchwithin', 'ne', 'course');
}
} else {
$mform->hideIf('groupids', 'searchwithin', 'eq', '');
}
}
}
$mform->addElement('date_time_selector', 'timestart', get_string('fromtime', 'search'), array('optional' => true));
@@ -66,10 +66,14 @@
$searchwithin = [];
$searchwithin[''] = get_string('everywhere', 'search');
$searchwithin['course'] = $coursecontext->get_context_name();
if ($context->contextlevel !== CONTEXT_COURSE) {
if ($context->contextlevel != CONTEXT_COURSE) {
$searchwithin['context'] = $context->get_context_name();
if ($context->contextlevel == CONTEXT_MODULE) {
$customdata['withincmid'] = $context->instanceid;
}
}
$customdata['searchwithin'] = $searchwithin;
$customdata['withincourseid'] = $coursecontext->instanceid;
}
// Get available ordering options from search engine.
@@ -91,3 +91,38 @@ Feature: Use global search interface
And I should not see "Courses" in the "region-main" "region"
And I select "Forum: ForumName1" from the "Search within" singleselect
And I should not see "Courses" in the "region-main" "region"
@javascript
Scenario: Check that groups option in search form appears when intended
Given the following "groups" exist:
| name | course | idnumber |
| A Group | F1 | G1 |
| B Group | F1 | G2 |
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| forum | ForumSG | ForumDesc1 | F1 | FORUM2 | 1 |
When I am on "Amphibians" course homepage
And I follow "ForumSG"
And global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
And I search for "frogs" using the header global search box
And I expand all fieldsets
Then I should not see "Groups" in the "region-main" "region"
And I select "Course: Amphibians" from the "Search within" singleselect
And I should see "Groups" in the "region-main" "region"
And I set the field "Groups" to "A Group"
And I select "Forum: ForumSG" from the "Search within" singleselect
And I should see "Groups" in the "region-main" "region"
And I am on "Amphibians" course homepage
And I follow "ForumName1"
And global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
And I search for "frogs" using the header global search box
And I expand all fieldsets
Then I should not see "Groups" in the "region-main" "region"
And I select "Course: Amphibians" from the "Search within" singleselect
And I should see "Groups" in the "region-main" "region"
And I select "Forum: ForumName1" from the "Search within" singleselect
And I should not see "Groups" in the "region-main" "region"

0 comments on commit 9dbb24f

Please sign in to comment.