Marking block & uncategorised grades in version 1.6 error

Marking block & uncategorised grades in version 1.6 error

by Nikki Macfarlane -
Number of replies: 1
I have come across a problem in the marking block when using it with Moodle version 1.6

If there are no uncategorised grades in the gradebook, students receive an error where the marking block would normally be seen by teachers. The error is"

Warning: Invalid argument supplied for foreach() in /home/admin/website.com/html/moodle/blocks/marking/lib.php on line 18

I have tried to create a temporary fix on my site by having an assignment that is hidden to students but the error still occurred. Also tried to hide uncategorised grades in teh gradebook, but no luck.

The only way I have been able to fix this is to have the assignment in uncategorised in the gradebook and have the assignments weight set to 0.

I never had this problem previously on Moodle 1.5.3 but have recently installed the latest marking block so that may be the problem. In /marking/lib line 18 reads:

        foreach ($allinfo['uncategorised'] as $gname => $ginfo) {

and this seems to be causing the problem. Any suggestions for a permanent fix?

Nikki Macfarlane
Average of ratings: -
In reply to Nikki Macfarlane

Re: Marking block & uncategorised grades in version 1.6 error

by Colin McQueen -

I have come across this foreach() problem with several non_standrd modules or blocks. I thin it happens whenever there is code that has the assumption built in that there will always be at least one of whatever object the foreach() is trying to act upon. I suppose it means that testing on moodles that don't have these objects hasn't been doen. An understandable mistake.

Even code on MoodleDocs has stuff like this in it. Take the resetting blocks code at http://docs.moodle.org/en/Block_layout . The foreach() there would fail if there was no courses in a moodle when it it run. Not that that's likely as I guess every moodle has course 1.

I have fixed these myself usually by putting an if obect existst then do the foreach() code else don't but that could cause issues. You may need to substitute in a string such as "No assignments set" or something like that depending on the block/module etc.

However I do believe there are better ways of coding this mentioned elsewhere on the forums.

In this instance if it doesn't occur in the same circumstances on 1.53 it may be the way 1.6 determines if a block is shown?

Sorry I can't help further.

What I can do is point you to an en lang file that has many if not all the strings filled in. I believe the copy on MoodleDocs has an old en lang file. I attached my copy to this post http://moodle.org/mod/forum/discuss.php?d=45432

HTH