MDL-27734 Fixed weights of the example submission assessments
authorDavid Mudrak <david@moodle.com>
Mon, 6 Jun 2011 13:57:02 +0000 (15:57 +0200)
committerDavid Mudrak <david@moodle.com>
Mon, 6 Jun 2011 15:37:59 +0000 (17:37 +0200)
mod/workshop/db/upgradelib.php

index 4b79846..9dce148 100644 (file)
@@ -331,6 +331,9 @@ 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])) {
@@ -338,8 +341,9 @@ function workshop_upgrade_assessments() {
             $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,9 +358,10 @@ 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');
 
@@ -364,10 +369,21 @@ function workshop_upgrade_transform_assessment(stdClass $old, $newsubmissionid,
     $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) {