Example #1
0
 /**
  * Perform minimal validation on the grade form
  * @param array $data
  * @param array $files
  */
 public function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $instance = $this->setaskment->get_instance();
     if ($instance->markingworkflow && !empty($data['sendstudentnotifications']) && $data['workflowstate'] != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
         $errors['sendstudentnotifications'] = get_string('studentnotificationworkflowstateerror', 'setask');
     }
     // Advanced grading.
     if (!array_key_exists('grade', $data)) {
         return $errors;
     }
     if ($instance->grade > 0) {
         if (!unformat_float($data['grade'], true) && !empty($data['grade'])) {
             $errors['grade'] = get_string('invalidfloatforgrade', 'setask', $data['grade']);
         } else {
             if (unformat_float($data['grade']) > $instance->grade) {
                 $errors['grade'] = get_string('gradeabovemaximum', 'setask', $instance->grade);
             } else {
                 if (unformat_float($data['grade']) < 0) {
                     $errors['grade'] = get_string('gradebelowzero', 'setask');
                 }
             }
         }
     } else {
         // This is a scale.
         if ($scale = $DB->get_record('scale', array('id' => -$instance->grade))) {
             $scaleoptions = make_menu_from_list($scale->scale);
             if ((int) $data['grade'] !== -1 && !array_key_exists((int) $data['grade'], $scaleoptions)) {
                 $errors['grade'] = get_string('invalidgradeforscale', 'setask');
             }
         }
     }
     return $errors;
 }
 /**
  * Get the next row of data from the csv file (only the columns we care about)
  *
  * @return stdClass or false The stdClass is an object containing user, grade and lastmodified
  */
 public function next()
 {
     global $DB;
     $result = new stdClass();
     while ($record = $this->csvreader->next()) {
         $idstr = $record[$this->idindex];
         // Strip the integer from the end of the participant string.
         $id = substr($idstr, strlen(get_string('hiddenuser', 'setask')));
         if ($userid = $this->setaskment->get_user_id_for_uniqueid($id)) {
             if (array_key_exists($userid, $this->validusers)) {
                 $result->grade = $record[$this->gradeindex];
                 $result->modified = strtotime($record[$this->modifiedindex]);
                 $result->user = $this->validusers[$userid];
                 $result->feedback = array();
                 foreach ($this->feedbackcolumnindexes as $description => $details) {
                     if (!empty($details['index'])) {
                         $details['value'] = $record[$details['index']];
                         $result->feedback[] = $details;
                     }
                 }
                 return $result;
             }
         }
     }
     // If we got here the csvreader had no more rows.
     return false;
 }