MDL-53167 search: Add ability to limit courses searched

This commit is contained in:
Eric Merrill
2016-04-07 14:41:59 -04:00
parent b611ade3ab
commit 427e3cbcd6
17 changed files with 145 additions and 30 deletions
+18 -11
View File
@@ -135,6 +135,9 @@ class engine extends \core_search\engine {
// 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->courseids)) {
$query->addFilterQuery('{!cache=false}courseid:(' . implode(' OR ', $data->courseids) . ')');
}
if (!empty($data->timestart) or !empty($data->timeend)) {
if (empty($data->timestart)) {
@@ -159,19 +162,23 @@ class engine extends \core_search\engine {
// If the user can access all contexts $usercontexts value is just true, we don't need to filter
// in that case.
if ($usercontexts && is_array($usercontexts)) {
if (!empty($data->areaid)) {
$query->addFilterQuery('contextid:(' . implode(' OR ', $usercontexts[$data->areaid]) . ')');
} else {
// Join all area contexts into a single array and implode.
$allcontexts = array();
foreach ($usercontexts as $areacontexts) {
foreach ($areacontexts as $contextid) {
// Ensure they are unique.
$allcontexts[$contextid] = $contextid;
}
// Join all area contexts into a single array and implode.
$allcontexts = array();
foreach ($usercontexts as $areaid => $areacontexts) {
if (!empty($data->areaid) && ($areaid !== $data->areaid)) {
// Skip unused areas.
continue;
}
foreach ($areacontexts as $contextid) {
// Ensure they are unique.
$allcontexts[$contextid] = $contextid;
}
$query->addFilterQuery('contextid:(' . implode(' OR ', $allcontexts) . ')');
}
if (empty($allcontexts)) {
// This means there are no valid contexts for them, so they get no results.
return array();
}
$query->addFilterQuery('contextid:(' . implode(' OR ', $allcontexts) . ')');
}
try {