Student report - double output

Student report - double output

by Eva Adam -
Number of replies: 6

Dear All,

We plan to use the attendance plugin from the next academic year in our school and it seems that it could meet all our needs and its user interface is quite pleasant smile

However, when I started to test it, I realised that the student detailed report shows all completed sessions twice. I attached a print screen file to this post to show how it looks. I added the attendance module to a course, defined 5 sessions and filled in the first 2 sessions for a test student. The image shows how the student can see his own detailed attendance report for the course.

I have two test servers at the moment: we plan to switch to 2.5 during the summer and use 2.4.3+ at the moment. The attendance module is the newest one for 2.4 (ver 2012120700) and this behaviour is the same on both Moodle servers.

I am not a programmer but had a quick look at the code and it seems to me that in locallib.php around line 1051 the function get_user_filtered_sessions_log_extended uses 2 queries to gather all sessions (one for "all taked sessions (including previous groups)", the other is for "all sessions for current groups"). I have a feeling that when these two sessions are merged, the records for the filled in sessions are doubled. This is definitely not a theme issue, as it looks the same with several themes (including the formal white).

Thanks for any help or advice,

Éva

Average of ratings: -
In reply to Eva Adam

Re: Student report - double output

by Jeff King -

Ever find a solution for this? I am seeing the same thing. Using version 2011071601 of the plugin for a Moodle 2.3.2 site.

In reply to Eva Adam

Re: Student report - double output

by Jeff King -

I looked closer and you are right: the problem is the 2 queries. They don't merge properly. This is because an array_merge does not treat numeric array keys the same as text keys. The arrays from the two queries are indexed by the attendance session ID, which is a number. The point of the merge is that two records for attendance session 5 for example will merge into one, but array_merge simply spits out an ordered array with both entries.

I came up with a quick fix that seems to work, but you should test it first (may behave differently depending on your database). You have to get the index of the array to be text. Moodle uses the first item a SELECT query as the index, so just add a new field as the first field that has some text concatenated.

For the two SELECT queries in the get_user_filtered_sessions_log_extended() function, the start of the query would look like this:

$sql = "SELECT CONCAT( 'key', ats.id) as tempkey, ats.id, ats.groupid, ....

I am just adding the text 'key' to the ID as an additional field so that PHP will treat the resulting array keys as text and it will merge properly.

Hope that helps.

 

In reply to Jeff King

Re: Student report - double output

by Eva Adam -

Hi Jeff,

Thanks for sharing your solution with us smile

I am about to go on holiday now but when I get back, I will definitely test your code.

Best,

Éva

In reply to Eva Adam

Re: Student report - double output

by Eva Adam -

Hi Jeff,

Your solution seems to work smile I have tested it on Moodle 2.5.1 (Build: 20130712) and the mod_attendance plugin is the newest I found on github:  2013070403. 

Thanks again,

Éva

In reply to Eva Adam

Re: Student report - double output

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

NeillM has just filed a pull request to fix this by improving the SQL query used to obtain the data - I've checked this for security but haven't tested it or looked at the performance implications - If others here could test this and let me know that would be appreciated - please also provide information on the Database type you have tested it on (mysql/postgres/MS SQl) etc

you can get the latest code with the patch here:
https://github.com/danmarsden/moodle-mod_attendance/archive/master.zip

This code hasn't been pushed to the version in the Moodle plugins db yet - I'll wait for confirmation from others before I do this.

thanks to Neill!

In reply to Dan Marsden

Re: Student report - double output

by Neill Magill -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

No problem. I'm crossing my fingers for no problems being found.