moodleou / moodle-quiz_answersheets

A Moodle quiz report to allow quiz attempts to be exported
8 stars 15 forks source link

Can no longer be used after clicking on "Create Attempt" #26

Closed OgreTransporter closed 3 years ago

OgreTransporter commented 3 years ago

I clicked on "Create Attempt". Now nothing works anymore:

Debug-Info:  Unknown column 'create_attempt' in 'order clause'
SELECT
DISTINCT CONCAT(u.id, '#', COALESCE(quiza.attempt, 0)) AS uniqueid,
quiza.uniqueid AS usageid,
quiza.id AS attempt,
u.id AS userid,
u.idnumber, u.firstnamephonetic,u.lastnamephonetic,u.middlename,u.alternatename,u.firstname,u.lastname,
u.picture,
u.username,
u.imagealt,
u.institution,
u.department,
u.email,
quiza.state,
quiza.sumgrades,
quiza.timefinish,
quiza.timestart,
CASE WHEN quiza.timefinish = 0 THEN null
WHEN quiza.timefinish > quiza.timestart THEN quiza.timefinish - quiza.timestart
ELSE 0 END AS duration, quiza.attempt AS attemptno
, CASE
-- If, for this user, attempts allowed (including overrids) is unlimited,
-- then they have not used all attempts.
WHEN COALESCE(
(SELECT attempts FROM mdl_quiz_overrides WHERE quiz = quiza.quiz AND userid = u.id),
(SELECT MIN(overrides1.attempts)
FROM mdl_quiz_overrides overrides1
JOIN mdl_groups_members overrides1_gm ON overrides1_gm.groupid = overrides1.groupid
WHERE overrides1.quiz = quiza.quiz
AND overrides1_gm.userid = u.id),
?) = 0 THEN 0
-- Or, if there is a finite limit, compare with the number of attempts they have.
WHEN (SELECT COUNT(1) FROM mdl_quiz_attempts WHERE quiz = quiza.quiz AND userid = quiza.userid) < COALESCE(
(SELECT attempts FROM mdl_quiz_overrides WHERE quiz = quiza.quiz AND userid = u.id),
(SELECT MAX(overrides2.attempts)
FROM mdl_quiz_overrides overrides2
JOIN mdl_groups_members overrides2_gm ON overrides2_gm.groupid = overrides2.groupid
WHERE overrides2.quiz = quiza.quiz
AND overrides2_gm.userid = u.id),
?) THEN 0
ELSE 1
END AS used_all_attempts
, CASE
-- User does not have an attempt yet, so only one row.
WHEN quiza.id IS NULL THEN 1
-- User woth one or more attempts.
WHEN quiza.attempt = (
SELECT MAX(attempt)
FROM mdl_quiz_attempts
WHERE quiz = quiza.quiz AND userid = quiza.userid
) THEN 1
ELSE 0
END AS last_attempt_for_this_user

FROM mdl_user u
LEFT JOIN mdl_quiz_attempts quiza ON
quiza.userid = u.id AND quiza.quiz = ?
JOIN mdl_user_enrolments ej1_ue ON ej1_ue.userid = u.id
JOIN mdl_enrol ej1_e ON (ej1_e.id = ej1_ue.enrolid AND ej1_e.courseid = ?)
JOIN (SELECT DISTINCT userid
FROM mdl_role_assignments
WHERE contextid IN (1,3,45,409)
AND roleid IN (5)
) ra ON ra.userid = u.id
WHERE (quiza.preview = 0 OR quiza.preview IS NULL) AND 1 = 1 AND u.deleted = 0 AND u.id <> ? AND u.deleted = 0
ORDER BY create_attempt DESC, quiza.id ASC LIMIT 0, 500
[array (
0 => '1',
1 => '1',
2 => '5',
3 => '2',
4 => '1',
)]
Error code: dmlreadexception
Stack trace:  
line 486 of /lib/dml/moodle_database.php: dml_read_exception thrown
line 1273 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 1997 of /lib/tablelib.php: call to mysqli_native_moodle_database->get_records_sql()
line 593 of /mod/quiz/report/attemptsreport_table.php: call to table_sql->query_db()
line 2019 of /lib/tablelib.php: call to quiz_attempts_report_table->query_db()
line 171 of /mod/quiz/report/answersheets/report.php: call to table_sql->out()
line 97 of /mod/quiz/report.php: call to quiz_answersheets_report->display()
timhunt commented 3 years ago

It's a minor bug. Simple work-around: Don't click on that column heading ;-)

If you log out and log in again, things should start working.

SAHellauer commented 3 years ago

This will fix that https://github.com/moodleou/moodle-quiz_answersheets/pull/28

timhunt commented 3 years ago

I;ve just pushed our latest code, which already had a fix for this.