Skip to content

Commit

Permalink
Merge pull request #153 from marxjohnson/student-search-query-311
Browse files Browse the repository at this point in the history
Rewrite student_search_table query
  • Loading branch information
marxjohnson authored Feb 14, 2024
2 parents b5a9181 + aeb052c commit cb9a978
Show file tree
Hide file tree
Showing 2 changed files with 30 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
1 change: 1 addition & 0 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
$plugin->release = '2021101500';
$plugin->version = 2021101500;
$plugin->requires = 2018051712;
$plugin->supported = [311, 311];
$plugin->maturity = MATURITY_BETA;

0 comments on commit cb9a978

Please sign in to comment.