Exemple #1
0
 }
 // check if grade item is locked if so, abort
 if ($gradeitem->is_locked()) {
     $status = false;
     import_cleanup($importcode);
     echo $OUTPUT->notification(get_string('gradeitemlocked', 'grades'));
     break 3;
 }
 $newgrade = new stdClass();
 $newgrade->itemid = $gradeitem->id;
 if ($gradeitem->gradetype == GRADE_TYPE_SCALE and $verbosescales) {
     if ($value === '' or $value == '-') {
         $value = null;
         // no grade
     } else {
         $scale = $gradeitem->load_scale();
         $scales = explode(',', $scale->scale);
         $scales = array_map('trim', $scales);
         //hack - trim whitespace around scale options
         array_unshift($scales, '-');
         // scales start at key 1
         $key = array_search($value, $scales);
         if ($key === false) {
             echo "<br/>t0 is {$t0}";
             echo "<br/>grade is {$value}";
             $status = false;
             import_cleanup($importcode);
             echo $OUTPUT->notification(get_string('badgrade', 'grades'));
             break 3;
         }
         $value = $key;
Exemple #2
0
 /**
  * This updates existing grade items.
  *
  * @param int $courseid The course ID.
  * @param array $map Mapping information provided by the user.
  * @param int $key The line that we are currently working on.
  * @param bool $verbosescales Form setting for grading with scales.
  * @param string $value The grade value.
  * @return array grades to be updated.
  */
 protected function update_grade_item($courseid, $map, $key, $verbosescales, $value)
 {
     // Case of an id, only maps id of a grade_item.
     // This was idnumber.
     if (!($gradeitem = new grade_item(array('id' => $map[$key], 'courseid' => $courseid)))) {
         // Supplied bad mapping, should not be possible since user
         // had to pick mapping.
         $this->cleanup_import(get_string('importfailed', 'grades'));
         return null;
     }
     // Check if grade item is locked if so, abort.
     if ($gradeitem->is_locked()) {
         $this->cleanup_import(get_string('gradeitemlocked', 'grades'));
         return null;
     }
     $newgrade = new stdClass();
     $newgrade->itemid = $gradeitem->id;
     if ($gradeitem->gradetype == GRADE_TYPE_SCALE and $verbosescales) {
         if ($value === '' or $value == '-') {
             $value = null;
             // No grade.
         } else {
             $scale = $gradeitem->load_scale();
             $scales = explode(',', $scale->scale);
             $scales = array_map('trim', $scales);
             // Hack - trim whitespace around scale options.
             array_unshift($scales, '-');
             // Scales start at key 1.
             $key = array_search($value, $scales);
             if ($key === false) {
                 $this->cleanup_import(get_string('badgrade', 'grades'));
                 return null;
             }
             $value = $key;
         }
         $newgrade->finalgrade = $value;
     } else {
         if ($value === '' or $value == '-') {
             $value = null;
             // No grade.
         } else {
             // If the value has a local decimal or can correctly be unformatted, do it.
             $validvalue = unformat_float($value, true);
             if ($validvalue !== false) {
                 $value = $validvalue;
             } else {
                 // Non numeric grade value supplied, possibly mapped wrong column.
                 $this->cleanup_import(get_string('badgrade', 'grades'));
                 return null;
             }
         }
         $newgrade->finalgrade = $value;
     }
     $this->newgrades[] = $newgrade;
     return $this->newgrades;
 }