MDL-32126 - data - backport of advanced search re-write

This commit is contained in:
Adrian Greeve
2012-05-14 08:33:18 +08:00
parent efac2d2ad4
commit d4d88ffd73
2 changed files with 185 additions and 13 deletions
+16 -13
View File
@@ -561,6 +561,7 @@ if ($showactivity) {
$params['myid2'] = $USER->id;
}
$i = 0;
if (!empty($advanced)) { //If advanced box is checked.
foreach($search_array as $key => $val) { //what does $search_array hold?
if ($key == DATA_FIRSTNAME or $key == DATA_LASTNAME) {
@@ -587,30 +588,32 @@ if ($showactivity) {
/// To actually fetch the records
$fromsql = "FROM $tables $advtables $where $advwhere $groupselect $approveselect $searchselect $advsearchselect";
$sqlselect = "SELECT $what $fromsql $sortorder";
$sqlcount = "SELECT $count $fromsql"; // Total number of records when searching
$sqlmax = "SELECT $count FROM $tables $where $groupselect $approveselect"; // number of all recoirds user may see
$allparams = array_merge($params, $advparams);
/// Work out the paging numbers and counts
$recordids = data_get_all_recordids($data->id);
$newrecordids = data_get_advance_search_ids($recordids, $search_array, $data->id);
$totalcount = count($newrecordids);
$selectdata = $groupselect . $approveselect;
$totalcount = $DB->count_records_sql($sqlcount, $allparams);
if (!empty($advanced)) {
$advancedsearchsql = data_get_advanced_search_sql($sort, $data, $newrecordids, $selectdata, $sortorder);
$sqlselect = $advancedsearchsql['sql'];
$allparams = array_merge($allparams, $advancedsearchsql['params']);
} else {
$sqlselect = "SELECT $what $fromsql $sortorder";
}
/// Work out the paging numbers and counts
if (empty($searchselect) && empty($advsearchselect)) {
$maxcount = $totalcount;
} else {
$maxcount = $DB->count_records_sql($sqlmax, $params);
$maxcount = count($recordids);
}
if ($record) { // We need to just show one, so where is it in context?
$nowperpage = 1;
$mode = 'single';
$page = 0;
// TODO: Improve this because we are executing $sqlselect twice (here and some lines below)!
if ($allrecordids = $DB->get_fieldset_sql($sqlselect, $allparams)) {
$page = (int)array_search($record->id, $allrecordids);
unset($allrecordids);
}
$page = (int)array_search($record->id, $recordids);
} else if ($mode == 'single') { // We rely on ambient $page settings
$nowperpage = 1;