Hi all
Desired outcome:
- A configurable SQL report showing assignment items that require grading (note we've tried all such supplied reports and none fit the bill)
- We only want to see the latest attempt from the student in this report.
SELECT
asub.id,
CONCAT(u.firstname ,' ',u.lastname) AS User,
CONCAT('<a target="_new" href="%%WWWROOT%%/course/view.php',CHAR(63),'id=',c.id,'">',c.fullname,'</a>') AS Course,
ccat.name AS Course_category,
CONCAT('<a target="_new" href="%%WWWROOT%%/mod/assign/view.php',CHAR(63),'id=',cm.id,'">',a.name,'</a>') AS Assignment,
asub.status,
agr.grade,
# agr.grader,
CONCAT(u.firstname ,' ',u.lastname) AS User,
FROM_UNIXTIME(asub.timecreated) AS Submitted
FROM prefix_assign_submission AS asub
JOIN prefix_assign AS a ON a.id = asub.assignment
JOIN prefix_user AS u ON u.id = asub.userid
JOIN prefix_course AS c ON c.id = a.course
JOIN prefix_course_categories AS ccat ON ccat.id = c.category
JOIN prefix_course_modules cm ON cm.instance=a.id AND cm.course = a.course AND cm.module = 1
# note: cm.module equalling 1 represents the Assignment module
LEFT JOIN prefix_assign_grades agr ON agr.assignment = a.id AND agr.userid = asub.userid
WHERE agr.grade IS NULL AND asub.attemptnumber = asub.latest AND (asub.status = "submitted" OR asub.status = "new")
# grade is null because there will be no table entry here at all until graded
# WHERE 1=1
%%FILTER_CATEGORIES:c.category%%
ORDER BY asub.timecreated DESC
This produces a result as follows:
Our Issue:
Records are appearing in the report (e.g. Valerie Christie) stating the status is “submitted”, yet when we view this in the user interface, we see this:
The item in the report has a submission date of 25 October (when Valerie originally submitted), and we can see above it has a last modified date of 27 October, when the marker has accessed the submission, found it lacking, and provided feedback to Valerie that more detail is required (hence status of “reopened”).
So, given this submission has a status of “reopened”, it should not be appearing in this report whatsoever (the SQL asks only for status=submitted or status=new).
Looking at the database for Valerie’s submissions on this particular assignment we begin to understand why we are seeing this record flowing into the report...
...namely, it’s showing the first submission (the first row), yet there’s a later version. We don’t want this! In our SQL, we set the clause asub.attemptnumber = asub.latest to ensure we’re only seeing the latest submission (but it's clearly not working).
I do not understand how “attemptnumber” and “latest” are actually working in the system. I would expect the following:
attemptnumber | latest | Additional action: | |
First submission: | 0 | 0 | none |
Second attempt | 1 | 1 | First submission record “latest” is updated to 1 |
Third attempt | 2 | 2 | First submission record “latest” is updated to 2 Second submission record “latest” is updated to 2 |
Can anyone shed some light on the mechanics of this?
And we'd really appreciate any advice as to how to best alter our query to get the result we’re after, that is:
Only show us assignment items requiring grading
Don’t show us items that have been subsequently updated and are not the latest versions
Kind Regards
Lee Cujes