Exercise module add-on: Fatal error: Call to undefined function: exercise_get_best_submission_grades()

Exercise module add-on: Fatal error: Call to undefined function: exercise_get_best_submission_grades()

by Hans de Zwart -
Number of replies: 2
Hello Ray,

I have just tried my first real life assignment and was very happy to find out about its functionality. I love the way the students grade themselves first before I, as a teacher do the grading. From now on I will let them hand in all their project work that way. I think everybody that has never tried the exercise module because assignment does the job for them (like me) should go out of their way to try it.

Now my problem:
I have run the assignment and want to see the grades in my gradebook. When I press grades I get the following error:


Fatal error: Call to undefined function: exercise_get_best_submission_grades() in /var/www/moodle/mod/exercise/lib.php on line 274

I use the following versions:
Moodle: 2004083129
Exercise:
2004062301
I use no special Gradebooks or modifications and run the latest Moodle straight from CVS.

Any idea what could be going on?
Average of ratings: -
In reply to Hans de Zwart

Re: Exercise module add-on: Fatal error: Call to undefined function: exercise_get_best_submission_grades()

by Orville Canter -
Hello,

I got this to work (or at least, I got it to load the page without errors) by copying exercise_get_best_grade() and renaming it exercise_get_best_submission_grades().

Do you think this is the correct solution? That is, do you think the function call in line 274 simply has the name of the function wrong? Or is there another problem I should address? Has anybody else seen this?

Please forgive my newbie ignorance.


Thanks,
Orville

///////////////////////////////////////////////////////////////////////////////////////////////
// I am adding this function to fix an error a professor encountered accessing the gradebook
// for a course: https://ilearn.sfsu.edu/course/grades.php?id=13
// He received an error:
// Fatal error: Call to undefined function: exercise_get_best_submission_grades()
// in /Library/WebServer/Documents/mod/exercise/lib.php on line 274
// It appears to me that the the above function, exercise_get_best_grade($submission), is the one
// the programmer intended to call. I do not know for certain whether the above function is called
// by other php scripts in the moodle application, so I did not want to edit that function.
// Therefore, I copied that function and renamed it to match the name of the function that is
// called in line 274.

function exercise_get_best_submission_grades($submission) {
// Returns the best grade of students' submission (there may, occassionally be more than one assessment)
global $CFG;

return get_record_sql("SELECT MAX(a.grade) AS grade FROM
{$CFG->prefix}exercise_assessments a
WHERE a.submissionid = $submission->id
GROUP BY a.submissionid");
}
In reply to Orville Canter

Re: Exercise module add-on: Fatal error: Call to undefined function: exercise_get_best_submission_grades()

by Orville Canter -
OK, that was a disaster. It broke /mod/exercise/index.php, which requires locallib.php, and therefore generates errors about duplicate function calls to exercise_get_best_submission_grades().

I tried something else that seems to work better; I copied the function exercise_get_best_submission_grades() to lib.php and renamed it exercise_get_best_submission_grades_hack_ocanter(), then I changed lib.php to call that function instead. This at least  allows the gradebook to load, and it should not affect anything besides that one function call in mod/exercise/lib.php to exercise_get_best_submission_grades(), which was broken anyway. After I have a chance to test this a little, I will update the thread.

Does anyone have a more elegant solution to this problem?


Thanks
Orville