Merge branch 'MDL-53642-master' of git://github.com/merrill-oakland/moodle
This commit is contained in:
@@ -56,11 +56,15 @@ class search extends \moodleform {
|
||||
$search = \core_search\manager::instance();
|
||||
|
||||
$searchareas = \core_search\manager::get_search_areas_list(true);
|
||||
$areanames = array('' => get_string('allareas', 'search'));
|
||||
$areanames = array();
|
||||
foreach ($searchareas as $areaid => $searcharea) {
|
||||
$areanames[$areaid] = $searcharea->get_visible_name();
|
||||
}
|
||||
$mform->addElement('select', 'areaid', get_string('searcharea', 'search'), $areanames);
|
||||
$options = array(
|
||||
'multiple' => true,
|
||||
'noselectionstring' => get_string('allareas', 'search'),
|
||||
);
|
||||
$mform->addElement('autocomplete', 'areaids', get_string('searcharea', 'search'), $areanames, $options);
|
||||
|
||||
$options = array(
|
||||
'multiple' => true,
|
||||
|
||||
@@ -131,9 +131,9 @@ class engine extends \core_search\engine {
|
||||
if (!empty($data->title)) {
|
||||
$query->addFilterQuery('{!field cache=false f=title}' . $data->title);
|
||||
}
|
||||
if (!empty($data->areaid)) {
|
||||
// Even if it is only supposed to contain PARAM_ALPHANUMEXT, better to prevent.
|
||||
$query->addFilterQuery('{!field cache=false f=areaid}' . $data->areaid);
|
||||
if (!empty($data->areaids)) {
|
||||
// If areaids are specified, we want to get any that match.
|
||||
$query->addFilterQuery('{!cache=false}areaid:(' . implode(' OR ', $data->areaids) . ')');
|
||||
}
|
||||
if (!empty($data->courseids)) {
|
||||
$query->addFilterQuery('{!cache=false}courseid:(' . implode(' OR ', $data->courseids) . ')');
|
||||
@@ -165,7 +165,7 @@ class engine extends \core_search\engine {
|
||||
// Join all area contexts into a single array and implode.
|
||||
$allcontexts = array();
|
||||
foreach ($usercontexts as $areaid => $areacontexts) {
|
||||
if (!empty($data->areaid) && ($areaid !== $data->areaid)) {
|
||||
if (!empty($data->areaids) && !in_array($areaid, $data->areaids)) {
|
||||
// Skip unused areas.
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -199,6 +199,23 @@ class search_solr_engine_testcase extends advanced_testcase {
|
||||
$querydata->courseids = array(SITEID);
|
||||
$this->assertCount(3, $this->search->search($querydata));
|
||||
|
||||
// Now try some area-id combinations.
|
||||
unset($querydata->courseids);
|
||||
$forumpostareaid = \core_search\manager::generate_areaid('mod_forum', 'post');
|
||||
$mockareaid = \core_search\manager::generate_areaid('core_mocksearch', 'role_capabilities');
|
||||
|
||||
$querydata->areaids = array($forumpostareaid);
|
||||
$this->assertCount(0, $this->search->search($querydata));
|
||||
|
||||
$querydata->areaids = array($forumpostareaid, $mockareaid);
|
||||
$this->assertCount(3, $this->search->search($querydata));
|
||||
|
||||
$querydata->areaids = array($mockareaid);
|
||||
$this->assertCount(3, $this->search->search($querydata));
|
||||
|
||||
$querydata->areaids = array();
|
||||
$this->assertCount(3, $this->search->search($querydata));
|
||||
|
||||
// Check that index contents get updated.
|
||||
$DB->delete_records('role_capabilities', array('capability' => 'moodle/course:renameroles'));
|
||||
$this->search->index(true);
|
||||
|
||||
+9
-3
@@ -28,7 +28,7 @@ $page = optional_param('page', 0, PARAM_INT);
|
||||
$q = optional_param('q', '', PARAM_NOTAGS);
|
||||
$title = optional_param('title', '', PARAM_NOTAGS);
|
||||
$areaid = optional_param('areaid', false, PARAM_ALPHANUMEXT);
|
||||
// Moving courseids, timestart, and timeend further down as they might come as an array if they come from the form.
|
||||
// Moving areaids, courseids, timestart, and timeend further down as they might come as an array if they come from the form.
|
||||
|
||||
$context = context_system::instance();
|
||||
$pagetitle = get_string('globalsearch', 'search');
|
||||
@@ -66,7 +66,11 @@ if (!$data && $q) {
|
||||
$data = new stdClass();
|
||||
$data->q = $q;
|
||||
$data->title = $title;
|
||||
$data->areaid = $areaid;
|
||||
$areaids = optional_param('areaids', '', PARAM_RAW);
|
||||
if (!empty($areaids)) {
|
||||
$areaids = explode(',', $areaids);
|
||||
$data->areaids = clean_param_array($areaids, PARAM_ALPHANUMEXT);
|
||||
}
|
||||
$courseids = optional_param('courseids', '', PARAM_RAW);
|
||||
if (!empty($courseids)) {
|
||||
$courseids = explode(',', $courseids);
|
||||
@@ -82,7 +86,9 @@ $urlparams = array('page' => $page);
|
||||
if ($data) {
|
||||
$urlparams['q'] = $data->q;
|
||||
$urlparams['title'] = $data->title;
|
||||
$urlparams['areaid'] = $data->areaid;
|
||||
if (!empty($data->areaids)) {
|
||||
$urlparams['areaids'] = implode(',', $data->areaids);
|
||||
}
|
||||
if (!empty($data->courseids)) {
|
||||
$urlparams['courseids'] = implode(',', $data->courseids);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user