MDL-32126 - data - backport of advanced search re-write
This commit is contained in:
+16
-13
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user