MDL-44536 workshop: Instantiate with the plain course module record
When the workshop class constructor signature was designed, the class cm_info did not exist yet. Instead, plain course modules records were used everywhere - including the $mod parameter in the workshop_user_complete() callback. Even if cm_info is backwards compatible with the plain data record when it comes to behaviour, it must not be passed where the workshop API expects the stdClass (coding error is thrown). Alternative solution would be to remove the type hinting in the workshop constructor. That is what the 'assign' class does, for example (the inline docs describe the expected type to be stdClass, but that is not forced via the method declaration). As the problem seems to be pretty sole, I prefer not touching the workshop internal API for now. So we let the cm_info degrade back into the stdClass to make the workshop constructor happy without significant performance lost.
This commit is contained in:
@@ -301,6 +301,12 @@ function workshop_user_complete($course, $user, $mod, $workshop) {
|
||||
require_once(dirname(__FILE__).'/locallib.php');
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
|
||||
if ($mod instanceof cm_info) {
|
||||
// We need to degrade here as the {@link workshop} class constructor
|
||||
// expects the plain course module record.
|
||||
$mod = $mod->get_course_module_record();
|
||||
}
|
||||
|
||||
$workshop = new workshop($workshop, $mod, $course);
|
||||
$grades = grade_get_grades($course->id, 'mod', 'workshop', $workshop->id, $user->id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user