Skip to content

Commit

Permalink
Rewrite student_search_table query
Browse files Browse the repository at this point in the history
Details on internal WR 427905
  • Loading branch information
marxjohnson committed Feb 9, 2024
1 parent b5a9181 commit 9d17228
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions classes/output/student_search_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,28 +513,41 @@ public function query_db($pagesize, $useinitialsbar = false) {
}

$sql = "SELECT u.*,
COALESCE(qo.timeopen, $quizobj->timestampopen) AS timeopen,
COALESCE(qo.timeclose, $quizobj->timestampclose) AS timeclose,
COALESCE(qo.timelimit, $quizobj->timestamplimit) AS timelimit,
COALESCE(qa.state, (CASE
WHEN us.userid > 0 THEN 'loggedin'
ELSE 'notloggedin'
END)) AS state,
qo.timeopen AS timeopen,
qo.timeclose AS timeclose,
qo.timelimit AS timelimit,
COALESCE(
qa.state,
(
CASE
WHEN us.userid > 0 THEN 'loggedin'
ELSE 'notloggedin'
END
)
) AS state,
qa.attemptid,
qa.timestart,
qa.timefinish,
$quizobj->assessid AS quiz,
$context->instanceid as quizinstance,
$quizobj->timestampopen AS quiztimeopen,
$quizobj->timestampclose AS quiztimeclose,
$quizobj->timestamplimit AS quiztimelimit,
'$quizobj->name' AS quizname
qa.timefinish
FROM {user} u
$finaljoin->joins
WHERE $finaljoin->wheres";

$records = $DB->get_records_sql($sql, $params);
$allrecords = array_merge($allrecords, $records);
$records = $DB->get_records_sql($sql, $params);
$quizdata = [
'quiz' => $quizobj->assessid,
'quizinstance' => $context->instanceid,
'quiztimeopen' => $quizobj->timestampopen,
'quiztimeclose' => $quizobj->timestampclose,
'quiztimelimit' => $quizobj->timestamplimit,
'quizname' => $quizobj->name,
];
foreach ($records as &$record) {
$record->timeopen = $record->timeopen ?? $quizobj->timestampopen;
$record->timeclose = $record->timeclose ?? $quizobj->timestampclose;
$record->timelimit = $record->timelimit ?? $quizobj->timestampopen;
$record = (object)array_merge((array)$record, $quizdata);
}
$allrecords = array_merge($allrecords, $records);
}

if (!empty($this->get_sql_sort())) {
Expand Down

0 comments on commit 9d17228

Please sign in to comment.