Skip to content
Snippets Groups Projects
Commit 18656961 authored by Anupama Sarjoshi's avatar Anupama Sarjoshi
Browse files

Fix questiontestreport DB query to fetch all attempts of all versions

parent de0fb948
No related branches found
No related tags found
No related merge requests found
......@@ -125,9 +125,8 @@ flush();
// Later we only display inputs relevant to a particular PTR, so we sort out prt input requirements here.
$inputsbyprt = $question->get_cached('required');
if (stack_determine_moodle_version() < 400) {
$query = 'SELECT qa.*, qas_last.*
$params = [$questionid];
$query = "SELECT qa.*, qas_last.*
FROM {question_attempts} qa
LEFT JOIN {question_attempt_steps} qas_last ON qas_last.questionattemptid = qa.id
/* attach another copy of qas to those rows with the most recent timecreated,
......@@ -138,39 +137,25 @@ if (stack_determine_moodle_version() < 400) {
OR (qas_last.sequencenumber = qas_prev.sequencenumber
AND qas_last.id < qas_prev.id))
LEFT JOIN {user} u ON qas_last.userid = u.id
WHERE
qas_prev.timecreated IS NULL
AND qa.questionid = ' . $questionid . '
ORDER BY u.username, qas_last.timecreated';
WHERE qas_prev.timecreated IS NULL";
if (stack_determine_moodle_version() < 400) {
$query .= " AND qa.questionid = ?";
} else {
// In moodle 4 we look at all attemps at all versions.
// In moodle 4 we look at all attempts at all versions.
// Otherwise an edit, regrade and re-analysis becomes impossible.
$query = 'SELECT qa.*, qas_last.*
FROM {question_attempts} qa
LEFT JOIN {question_attempt_steps} qas_last ON qas_last.questionattemptid = qa.id
/* attach another copy of qas to those rows with the most recent timecreated,
using method from https://stackoverflow.com/a/28090544 */
LEFT JOIN {question_attempt_steps} qas_prev
ON qas_last.questionattemptid = qas_prev.questionattemptid
AND (qas_last.sequencenumber < qas_prev.sequencenumber
OR (qas_last.sequencenumber = qas_prev.sequencenumber
AND qas_last.id < qas_prev.id))
LEFT JOIN {user} u ON qas_last.userid = u.id
LEFT JOIN {question} q ON q.id = (SELECT qv.questionid FROM {question_versions} qv
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
WHERE qbe.id = (SELECT be.id FROM {question_bank_entries} be
JOIN {question_versions} v ON v.questionbankentryid = be.id
WHERE v.questionid = ' . $questionid . ')
)
WHERE
qas_prev.timecreated IS NULL
ORDER BY u.username, qas_last.timecreated';
$query .= " AND qa.questionid IN (
SELECT qv.questionid
FROM {question_versions} qv_original
JOIN {question_versions} qv ON
qv.questionbankentryid = qv_original.questionbankentryid
WHERE qv_original.questionid = ?)";
}
$query .= " ORDER BY u.username, qas_last.timecreated";
global $DB;
$result = $DB->get_records_sql($query);
$result = $DB->get_records_sql($query, $params);
$summary = array();
foreach ($result as $qattempt) {
if (!array_key_exists($qattempt->variant, $summary)) {
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment