Permalink
Browse files

MDL-27734 Fixed weights of the example submission assessments

  • Loading branch information...
mudrd8mz committed Jun 6, 2011
1 parent dba2410 commit 0f37e97dc68b6672916645f7a1a0cea910d5924b
Showing with 21 additions and 5 deletions.
  1. +21 −5 mod/workshop/db/upgradelib.php
@@ -331,15 +331,19 @@ function workshop_upgrade_assessments() {
// list of teachers in every workshop: array of (int)workshopid => array of (int)userid => notused
$workshopteachers = array();
// get the list of ids of the new example submissions
$examplesubmissions = $DB->get_records('workshop_submissions', array('example' => 1), '', 'id');
$rs = $DB->get_recordset_select('workshop_assessments_old', 'newid IS NULL');
foreach ($rs as $old) {
if (!isset($workshopteachers[$old->workshopid])) {
$cm = get_coursemodule_from_instance('workshop', $old->workshopid, 0, false, MUST_EXIST);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$workshopteachers[$old->workshopid] = get_users_by_capability($context, 'mod/workshop:manage', 'u.id');
}
$ofexample = isset($examplesubmissions[$newsubmissionids[$old->submissionid]]);
$new = workshop_upgrade_transform_assessment($old, $newsubmissionids[$old->submissionid],
$workshopteachers[$old->workshopid], $teacherweights[$old->workshopid]);
$workshopteachers[$old->workshopid], $teacherweights[$old->workshopid], $ofexample);
$newid = $DB->insert_record('workshop_assessments', $new, true, true);
$DB->set_field('workshop_assessments_old', 'newplugin', 'assessments', array('id' => $old->id));
$DB->set_field('workshop_assessments_old', 'newid', $newid, array('id' => $old->id));
@@ -354,20 +358,32 @@ function workshop_upgrade_assessments() {
* @param int $newsubmissionid new submission id
* @param array $legacyteachers (int)userid => notused the list of legacy workshop teachers for the submission's workshop
* @param int $legacyteacherweight weight of teacher's assessment in legacy workshop
* @param bool $ofexample is this the assessment of an example submission?
* @return stdClass
*/
function workshop_upgrade_transform_assessment(stdClass $old, $newsubmissionid, array $legacyteachers, $legacyteacherweight) {
function workshop_upgrade_transform_assessment(stdClass $old, $newsubmissionid, array $legacyteachers, $legacyteacherweight, $ofexample) {
global $CFG;
require_once($CFG->libdir . '/gradelib.php');
$new = new stdclass();
$new->submissionid = $newsubmissionid;
$new->reviewerid = $old->userid;
if (isset($legacyteachers[$old->userid])) {
$new->weight = $legacyteacherweight;
if ($ofexample) {
// this is the assessment of an example submission
if (isset($legacyteachers[$old->userid])) {
// this is probably the reference assessment of the example submission
$new->weight = 1;
} else {
$new->weight = 0;
}
} else {
$new->weight = 1;
if (isset($legacyteachers[$old->userid])) {
$new->weight = $legacyteacherweight;
} else {
$new->weight = 1;
}
}
if ($old->grade < 0) {

0 comments on commit 0f37e97

Please sign in to comment.