コード例 #1
0
ファイル: querylib.php プロジェクト: vuchannguyen/web
/**
 * Returns the aggregated or calculated course grade for the given user(s).
 * @public
 * @param int $userid
 * @param int $courseid optional id of course or array of ids, empty means all uses courses (returns array if not present)
 * @return mixed grade info or grades array including item info, false if error
 */
function grade_get_course_grade($userid, $courseid_or_ids = null)
{
    if (!is_array($courseid_or_ids)) {
        if (empty($courseid_or_ids)) {
            if (!($courses = enrol_get_users_courses($userid))) {
                return false;
            }
            $courseids = array_keys($courses);
            return grade_get_course_grade($userid, $courseids);
        }
        if (!is_numeric($courseid_or_ids)) {
            return false;
        }
        if (!($grades = grade_get_course_grade($userid, array($courseid_or_ids)))) {
            return false;
        } else {
            // only one grade - not array
            $grade = reset($grades);
            return $grade;
        }
    }
    foreach ($courseid_or_ids as $courseid) {
        $grade_item = grade_item::fetch_course_item($courseid);
        $course_items[$grade_item->courseid] = $grade_item;
    }
    $grades = array();
    foreach ($course_items as $grade_item) {
        if ($grade_item->needsupdate) {
            grade_regrade_final_grades($courseid);
        }
        $item = new stdClass();
        $item->scaleid = $grade_item->scaleid;
        $item->name = $grade_item->get_name();
        $item->grademin = $grade_item->grademin;
        $item->grademax = $grade_item->grademax;
        $item->gradepass = $grade_item->gradepass;
        $item->locked = $grade_item->is_locked();
        $item->hidden = $grade_item->is_hidden();
        switch ($grade_item->gradetype) {
            case GRADE_TYPE_NONE:
                continue;
            case GRADE_TYPE_VALUE:
                $item->scaleid = 0;
                break;
            case GRADE_TYPE_TEXT:
                $item->scaleid = 0;
                $item->grademin = 0;
                $item->grademax = 0;
                $item->gradepass = 0;
                break;
        }
        $grade_grade = new grade_grade(array('userid' => $userid, 'itemid' => $grade_item->id));
        $grade_grade->grade_item =& $grade_item;
        $grade = new stdClass();
        $grade->grade = $grade_grade->finalgrade;
        $grade->locked = $grade_grade->is_locked();
        $grade->hidden = $grade_grade->is_hidden();
        $grade->overridden = $grade_grade->overridden;
        $grade->feedback = $grade_grade->feedback;
        $grade->feedbackformat = $grade_grade->feedbackformat;
        $grade->usermodified = $grade_grade->usermodified;
        $grade->dategraded = $grade_grade->get_dategraded();
        $grade->item = $item;
        // create text representation of grade
        if ($grade_item->needsupdate) {
            $grade->grade = false;
            $grade->str_grade = get_string('error');
            $grade->str_long_grade = $grade->str_grade;
        } else {
            if (is_null($grade->grade)) {
                $grade->str_grade = '-';
                $grade->str_long_grade = $grade->str_grade;
            } else {
                $grade->str_grade = grade_format_gradevalue($grade->grade, $grade_item);
                if ($grade_item->gradetype == GRADE_TYPE_SCALE or $grade_item->get_displaytype() != GRADE_DISPLAY_TYPE_REAL) {
                    $grade->str_long_grade = $grade->str_grade;
                } else {
                    $a = new stdClass();
                    $a->grade = $grade->str_grade;
                    $a->max = grade_format_gradevalue($grade_item->grademax, $grade_item);
                    $grade->str_long_grade = get_string('gradelong', 'grades', $a);
                }
            }
        }
        // create html representation of feedback
        if (is_null($grade->feedback)) {
            $grade->str_feedback = '';
        } else {
            $grade->str_feedback = format_text($grade->feedback, $grade->feedbackformat);
        }
        $grades[$grade_item->courseid] = $grade;
    }
    return $grades;
}
コード例 #2
0
ファイル: lib.php プロジェクト: Chocolate-lightning/moodle
 /**
  * Fill the table with data.
  *
  * @param $element - An array containing the table data for the current row.
  */
 private function fill_table_recursive(&$element)
 {
     global $DB, $CFG;
     $type = $element['type'];
     $depth = $element['depth'];
     $grade_object = $element['object'];
     $eid = $grade_object->id;
     $element['userid'] = $this->user->id;
     $fullname = $this->gtree->get_element_header($element, true, true, true, true, true);
     $data = array();
     $gradeitemdata = array();
     $hidden = '';
     $excluded = '';
     $itemlevel = $type == 'categoryitem' || $type == 'category' || $type == 'courseitem' ? $depth : $depth + 1;
     $class = 'level' . $itemlevel . ' level' . ($itemlevel % 2 ? 'odd' : 'even');
     $classfeedback = '';
     // If this is a hidden grade category, hide it completely from the user
     if ($type == 'category' && $grade_object->is_hidden() && !$this->canviewhidden && ($this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN || $this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_object->is_hiddenuntil())) {
         return false;
     }
     if ($type == 'category') {
         $this->evenodd[$depth] = ($this->evenodd[$depth] + 1) % 2;
     }
     $alter = $this->evenodd[$depth] == 0 ? 'even' : 'odd';
     /// Process those items that have scores associated
     if ($type == 'item' or $type == 'categoryitem' or $type == 'courseitem') {
         $header_row = "row_{$eid}_{$this->user->id}";
         $header_cat = "cat_{$grade_object->categoryid}_{$this->user->id}";
         if (!($grade_grade = grade_grade::fetch(array('itemid' => $grade_object->id, 'userid' => $this->user->id)))) {
             $grade_grade = new grade_grade();
             $grade_grade->userid = $this->user->id;
             $grade_grade->itemid = $grade_object->id;
         }
         $grade_grade->load_grade_item();
         /// Hidden Items
         if ($grade_grade->grade_item->is_hidden()) {
             $hidden = ' dimmed_text';
         }
         $hide = false;
         // If this is a hidden grade item, hide it completely from the user.
         if ($grade_grade->is_hidden() && !$this->canviewhidden && ($this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN || $this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_grade->is_hiddenuntil())) {
             $hide = true;
         } else {
             if (!empty($grade_object->itemmodule) && !empty($grade_object->iteminstance)) {
                 // The grade object can be marked visible but still be hidden if
                 // the student cannot see the activity due to conditional access
                 // and it's set to be hidden entirely.
                 $instances = $this->modinfo->get_instances_of($grade_object->itemmodule);
                 if (!empty($instances[$grade_object->iteminstance])) {
                     $cm = $instances[$grade_object->iteminstance];
                     $gradeitemdata['cmid'] = $cm->id;
                     if (!$cm->uservisible) {
                         // If there is 'availableinfo' text then it is only greyed
                         // out and not entirely hidden.
                         if (!$cm->availableinfo) {
                             $hide = true;
                         }
                     }
                 }
             }
         }
         // Actual Grade - We need to calculate this whether the row is hidden or not.
         $gradeval = $grade_grade->finalgrade;
         $hint = $grade_grade->get_aggregation_hint();
         if (!$this->canviewhidden) {
             /// Virtual Grade (may be calculated excluding hidden items etc).
             $adjustedgrade = $this->blank_hidden_total_and_adjust_bounds($this->courseid, $grade_grade->grade_item, $gradeval);
             $gradeval = $adjustedgrade['grade'];
             // We temporarily adjust the view of this grade item - because the min and
             // max are affected by the hidden values in the aggregation.
             $grade_grade->grade_item->grademax = $adjustedgrade['grademax'];
             $grade_grade->grade_item->grademin = $adjustedgrade['grademin'];
             $hint['status'] = $adjustedgrade['aggregationstatus'];
             $hint['weight'] = $adjustedgrade['aggregationweight'];
         } else {
             // The max and min for an aggregation may be different to the grade_item.
             if (!is_null($gradeval)) {
                 $grade_grade->grade_item->grademax = $grade_grade->get_grade_max();
                 $grade_grade->grade_item->grademin = $grade_grade->get_grade_min();
             }
         }
         if (!$hide) {
             /// Excluded Item
             /**
                             if ($grade_grade->is_excluded()) {
                                 $fullname .= ' ['.get_string('excluded', 'grades').']';
                                 $excluded = ' excluded';
                             }
                             **/
             /// Other class information
             $class .= $hidden . $excluded;
             if ($this->switch) {
                 // alter style based on whether aggregation is first or last
                 $class .= ($type == 'categoryitem' or $type == 'courseitem') ? " " . $alter . "d{$depth} baggt b2b" : " item b1b";
             } else {
                 $class .= ($type == 'categoryitem' or $type == 'courseitem') ? " " . $alter . "d{$depth} baggb" : " item b1b";
             }
             if ($type == 'categoryitem' or $type == 'courseitem') {
                 $header_cat = "cat_{$grade_object->iteminstance}_{$this->user->id}";
             }
             /// Name
             $data['itemname']['content'] = $fullname;
             $data['itemname']['class'] = $class;
             $data['itemname']['colspan'] = $this->maxdepth - $depth;
             $data['itemname']['celltype'] = 'th';
             $data['itemname']['id'] = $header_row;
             // Basic grade item information.
             $gradeitemdata['id'] = $grade_object->id;
             $gradeitemdata['itemtype'] = $grade_object->itemtype;
             $gradeitemdata['itemmodule'] = $grade_object->itemmodule;
             $gradeitemdata['iteminstance'] = $grade_object->iteminstance;
             $gradeitemdata['itemnumber'] = $grade_object->itemnumber;
             $gradeitemdata['categoryid'] = $grade_object->categoryid;
             $gradeitemdata['outcomeid'] = $grade_object->outcomeid;
             $gradeitemdata['scaleid'] = $grade_object->outcomeid;
             if ($this->showfeedback) {
                 // Copy $class before appending itemcenter as feedback should not be centered
                 $classfeedback = $class;
             }
             $class .= " itemcenter ";
             if ($this->showweight) {
                 $data['weight']['class'] = $class;
                 $data['weight']['content'] = '-';
                 $data['weight']['headers'] = "{$header_cat} {$header_row} weight";
                 // has a weight assigned, might be extra credit
                 // This obliterates the weight because it provides a more informative description.
                 if (is_numeric($hint['weight'])) {
                     $data['weight']['content'] = format_float($hint['weight'] * 100.0, 2) . ' %';
                     $gradeitemdata['weightraw'] = $hint['weight'];
                     $gradeitemdata['weightformatted'] = $data['weight']['content'];
                 }
                 if ($hint['status'] != 'used' && $hint['status'] != 'unknown') {
                     $data['weight']['content'] .= '<br>' . get_string('aggregationhint' . $hint['status'], 'grades');
                     $gradeitemdata['status'] = $hint['status'];
                 }
             }
             if ($this->showgrade) {
                 $gradeitemdata['graderaw'] = null;
                 $gradeitemdata['gradehiddenbydate'] = false;
                 $gradeitemdata['gradeneedsupdate'] = $grade_grade->grade_item->needsupdate;
                 $gradeitemdata['gradeishidden'] = $grade_grade->is_hidden();
                 $gradeitemdata['gradedatesubmitted'] = $grade_grade->get_datesubmitted();
                 $gradeitemdata['gradedategraded'] = $grade_grade->get_dategraded();
                 if ($grade_grade->grade_item->needsupdate) {
                     $data['grade']['class'] = $class . ' gradingerror';
                     $data['grade']['content'] = get_string('error');
                 } else {
                     if (!empty($CFG->grade_hiddenasdate) and $grade_grade->get_datesubmitted() and !$this->canviewhidden and $grade_grade->is_hidden() and !$grade_grade->grade_item->is_category_item() and !$grade_grade->grade_item->is_course_item()) {
                         // the problem here is that we do not have the time when grade value was modified, 'timemodified' is general modification date for grade_grades records
                         $class .= ' datesubmitted';
                         $data['grade']['class'] = $class;
                         $data['grade']['content'] = get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort')));
                         $gradeitemdata['gradehiddenbydate'] = true;
                     } else {
                         if ($grade_grade->is_hidden()) {
                             $data['grade']['class'] = $class . ' dimmed_text';
                             $data['grade']['content'] = '-';
                             if ($this->canviewhidden) {
                                 $gradeitemdata['graderaw'] = $gradeval;
                                 $data['grade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true);
                             }
                         } else {
                             $data['grade']['class'] = $class;
                             $data['grade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true);
                             $gradeitemdata['graderaw'] = $gradeval;
                         }
                     }
                 }
                 $data['grade']['headers'] = "{$header_cat} {$header_row} grade";
                 $gradeitemdata['gradeformatted'] = $data['grade']['content'];
             }
             // Range
             if ($this->showrange) {
                 $data['range']['class'] = $class;
                 $data['range']['content'] = $grade_grade->grade_item->get_formatted_range(GRADE_DISPLAY_TYPE_REAL, $this->rangedecimals);
                 $data['range']['headers'] = "{$header_cat} {$header_row} range";
                 $gradeitemdata['rangeformatted'] = $data['range']['content'];
                 $gradeitemdata['grademin'] = $grade_grade->grade_item->grademin;
                 $gradeitemdata['grademax'] = $grade_grade->grade_item->grademax;
             }
             // Percentage
             if ($this->showpercentage) {
                 if ($grade_grade->grade_item->needsupdate) {
                     $data['percentage']['class'] = $class . ' gradingerror';
                     $data['percentage']['content'] = get_string('error');
                 } else {
                     if ($grade_grade->is_hidden()) {
                         $data['percentage']['class'] = $class . ' dimmed_text';
                         $data['percentage']['content'] = '-';
                         if ($this->canviewhidden) {
                             $data['percentage']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE);
                         }
                     } else {
                         $data['percentage']['class'] = $class;
                         $data['percentage']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE);
                     }
                 }
                 $data['percentage']['headers'] = "{$header_cat} {$header_row} percentage";
                 $gradeitemdata['percentageformatted'] = $data['percentage']['content'];
             }
             // Lettergrade
             if ($this->showlettergrade) {
                 if ($grade_grade->grade_item->needsupdate) {
                     $data['lettergrade']['class'] = $class . ' gradingerror';
                     $data['lettergrade']['content'] = get_string('error');
                 } else {
                     if ($grade_grade->is_hidden()) {
                         $data['lettergrade']['class'] = $class . ' dimmed_text';
                         if (!$this->canviewhidden) {
                             $data['lettergrade']['content'] = '-';
                         } else {
                             $data['lettergrade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_LETTER);
                         }
                     } else {
                         $data['lettergrade']['class'] = $class;
                         $data['lettergrade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_LETTER);
                     }
                 }
                 $data['lettergrade']['headers'] = "{$header_cat} {$header_row} lettergrade";
                 $gradeitemdata['lettergradeformatted'] = $data['lettergrade']['content'];
             }
             // Rank
             if ($this->showrank) {
                 $gradeitemdata['rank'] = 0;
                 if ($grade_grade->grade_item->needsupdate) {
                     $data['rank']['class'] = $class . ' gradingerror';
                     $data['rank']['content'] = get_string('error');
                 } elseif ($grade_grade->is_hidden()) {
                     $data['rank']['class'] = $class . ' dimmed_text';
                     $data['rank']['content'] = '-';
                 } else {
                     if (is_null($gradeval)) {
                         // no grade, no rank
                         $data['rank']['class'] = $class;
                         $data['rank']['content'] = '-';
                     } else {
                         /// find the number of users with a higher grade
                         $sql = "SELECT COUNT(DISTINCT(userid))\n                                  FROM {grade_grades}\n                                 WHERE finalgrade > ?\n                                       AND itemid = ?\n                                       AND hidden = 0";
                         $rank = $DB->count_records_sql($sql, array($grade_grade->finalgrade, $grade_grade->grade_item->id)) + 1;
                         $data['rank']['class'] = $class;
                         $numusers = $this->get_numusers(false);
                         $data['rank']['content'] = "{$rank}/{$numusers}";
                         // Total course users.
                         $gradeitemdata['rank'] = $rank;
                         $gradeitemdata['numusers'] = $numusers;
                     }
                 }
                 $data['rank']['headers'] = "{$header_cat} {$header_row} rank";
             }
             // Average
             if ($this->showaverage) {
                 $gradeitemdata['averageformatted'] = '';
                 $data['average']['class'] = $class;
                 if (!empty($this->gtree->items[$eid]->avg)) {
                     $data['average']['content'] = $this->gtree->items[$eid]->avg;
                     $gradeitemdata['averageformatted'] = $this->gtree->items[$eid]->avg;
                 } else {
                     $data['average']['content'] = '-';
                 }
                 $data['average']['headers'] = "{$header_cat} {$header_row} average";
             }
             // Feedback
             if ($this->showfeedback) {
                 $gradeitemdata['feedback'] = '';
                 $gradeitemdata['feedbackformat'] = $grade_grade->feedbackformat;
                 if ($grade_grade->overridden > 0 and ($type == 'categoryitem' or $type == 'courseitem')) {
                     $data['feedback']['class'] = $classfeedback . ' feedbacktext';
                     $data['feedback']['content'] = get_string('overridden', 'grades') . ': ' . format_text($grade_grade->feedback, $grade_grade->feedbackformat);
                     $gradeitemdata['feedback'] = $grade_grade->feedback;
                 } else {
                     if (empty($grade_grade->feedback) or !$this->canviewhidden and $grade_grade->is_hidden()) {
                         $data['feedback']['class'] = $classfeedback . ' feedbacktext';
                         $data['feedback']['content'] = '&nbsp;';
                     } else {
                         $data['feedback']['class'] = $classfeedback . ' feedbacktext';
                         $data['feedback']['content'] = format_text($grade_grade->feedback, $grade_grade->feedbackformat);
                         $gradeitemdata['feedback'] = $grade_grade->feedback;
                     }
                 }
                 $data['feedback']['headers'] = "{$header_cat} {$header_row} feedback";
             }
             // Contribution to the course total column.
             if ($this->showcontributiontocoursetotal) {
                 $data['contributiontocoursetotal']['class'] = $class;
                 $data['contributiontocoursetotal']['content'] = '-';
                 $data['contributiontocoursetotal']['headers'] = "{$header_cat} {$header_row} contributiontocoursetotal";
             }
             $this->gradeitemsdata[] = $gradeitemdata;
         }
         // We collect the aggregation hints whether they are hidden or not.
         if ($this->showcontributiontocoursetotal) {
             $hint['grademax'] = $grade_grade->grade_item->grademax;
             $hint['grademin'] = $grade_grade->grade_item->grademin;
             $hint['grade'] = $gradeval;
             $parent = $grade_object->load_parent_category();
             if ($grade_object->is_category_item()) {
                 $parent = $parent->load_parent_category();
             }
             $hint['parent'] = $parent->load_grade_item()->id;
             $this->aggregationhints[$grade_grade->itemid] = $hint;
         }
     }
     /// Category
     if ($type == 'category') {
         $data['leader']['class'] = $class . ' ' . $alter . "d{$depth} b1t b2b b1l";
         $data['leader']['rowspan'] = $element['rowspan'];
         if ($this->switch) {
             // alter style based on whether aggregation is first or last
             $data['itemname']['class'] = $class . ' ' . $alter . "d{$depth} b1b b1t";
         } else {
             $data['itemname']['class'] = $class . ' ' . $alter . "d{$depth} b2t";
         }
         $data['itemname']['colspan'] = $this->maxdepth - $depth + count($this->tablecolumns) - 1;
         $data['itemname']['content'] = $fullname;
         $data['itemname']['celltype'] = 'th';
         $data['itemname']['id'] = "cat_{$grade_object->id}_{$this->user->id}";
     }
     /// Add this row to the overall system
     foreach ($data as $key => $celldata) {
         $data[$key]['class'] .= ' column-' . $key;
     }
     $this->tabledata[] = $data;
     /// Recursively iterate through all child elements
     if (isset($element['children'])) {
         foreach ($element['children'] as $key => $child) {
             $this->fill_table_recursive($element['children'][$key]);
         }
     }
     // Check we are showing this column, and we are looking at the root of the table.
     // This should be the very last thing this fill_table_recursive function does.
     if ($this->showcontributiontocoursetotal && ($type == 'category' && $depth == 1)) {
         // We should have collected all the hints by now - walk the tree again and build the contributions column.
         $this->fill_contributions_column($element);
     }
 }
コード例 #3
0
ファイル: load_data.php プロジェクト: evltuma/moodle
 /**
  * Checks and prepares grade data for inserting into the gradebook.
  *
  * @param array $header Column headers of the CSV file.
  * @param object $formdata Mapping information from the preview page.
  * @param object $csvimport csv import reader object for iterating over the imported CSV file.
  * @param int $courseid The course ID.
  * @param bool $separatemode If we have groups are they separate?
  * @param mixed $currentgroup current group information.
  * @param bool $verbosescales Form setting for grading with scales.
  * @return bool True if the status for importing is okay, false if there are errors.
  */
 public function prepare_import_grade_data($header, $formdata, $csvimport, $courseid, $separatemode, $currentgroup, $verbosescales)
 {
     global $DB, $USER;
     // The import code is used for inserting data into the grade tables.
     $this->importcode = $formdata->importcode;
     $this->status = true;
     $this->headers = $header;
     $this->studentid = null;
     $this->gradebookerrors = null;
     $forceimport = $formdata->forceimport;
     // Temporary array to keep track of what new headers are processed.
     $this->newgradeitems = array();
     $this->trim_headers();
     $timeexportkey = null;
     $map = array();
     // Loops mapping_0, mapping_1 .. mapping_n and construct $map array.
     foreach ($header as $i => $head) {
         if (isset($formdata->{'mapping_' . $i})) {
             $map[$i] = $formdata->{'mapping_' . $i};
         }
         if ($head == get_string('timeexported', 'gradeexport_txt')) {
             $timeexportkey = $i;
         }
     }
     // If mapping information is supplied.
     $map[clean_param($formdata->mapfrom, PARAM_RAW)] = clean_param($formdata->mapto, PARAM_RAW);
     // Check for mapto collisions.
     $maperrors = array();
     foreach ($map as $i => $j) {
         if ($j == 0) {
             // You can have multiple ignores.
             continue;
         } else {
             if (!isset($maperrors[$j])) {
                 $maperrors[$j] = true;
             } else {
                 // Collision.
                 print_error('cannotmapfield', '', '', $j);
             }
         }
     }
     $this->raise_limits();
     $csvimport->init();
     while ($line = $csvimport->next()) {
         if (count($line) <= 1) {
             // There is no data on this line, move on.
             continue;
         }
         // Array to hold all grades to be inserted.
         $this->newgrades = array();
         // Array to hold all feedback.
         $this->newfeedbacks = array();
         // Each line is a student record.
         foreach ($line as $key => $value) {
             $value = clean_param($value, PARAM_RAW);
             $value = trim($value);
             /*
              * the options are
              * 1) userid, useridnumber, usermail, username - used to identify user row
              * 2) new - new grade item
              * 3) id - id of the old grade item to map onto
              * 3) feedback_id - feedback for grade item id
              */
             // Explode the mapping for feedback into a label 'feedback' and the identifying number.
             $mappingbase = explode("_", $map[$key]);
             $mappingidentifier = $mappingbase[0];
             // Set the feedback identifier if it exists.
             if (isset($mappingbase[1])) {
                 $feedbackgradeid = (int) $mappingbase[1];
             } else {
                 $feedbackgradeid = '';
             }
             $this->map_user_data_with_value($mappingidentifier, $value, $header, $map, $key, $courseid, $feedbackgradeid, $verbosescales);
             if ($this->status === false) {
                 return $this->status;
             }
         }
         // No user mapping supplied at all, or user mapping failed.
         if (empty($this->studentid) || !is_numeric($this->studentid)) {
             // User not found, abort whole import.
             $this->cleanup_import(get_string('usermappingerrorusernotfound', 'grades'));
             break;
         }
         if ($separatemode and !groups_is_member($currentgroup, $this->studentid)) {
             // Not allowed to import into this group, abort.
             $this->cleanup_import(get_string('usermappingerrorcurrentgroup', 'grades'));
             break;
         }
         // Insert results of this students into buffer.
         if ($this->status and !empty($this->newgrades)) {
             foreach ($this->newgrades as $newgrade) {
                 // Check if grade_grade is locked and if so, abort.
                 if (!empty($newgrade->itemid) and $gradegrade = new grade_grade(array('itemid' => $newgrade->itemid, 'userid' => $this->studentid))) {
                     if ($gradegrade->is_locked()) {
                         // Individual grade locked.
                         $this->cleanup_import(get_string('gradelocked', 'grades'));
                         return $this->status;
                     }
                     // Check if the force import option is disabled and the last exported date column is present.
                     if (!$forceimport && !empty($timeexportkey)) {
                         $exportedtime = $line[$timeexportkey];
                         if (clean_param($exportedtime, PARAM_INT) != $exportedtime || $exportedtime > time() || $exportedtime < strtotime("-1 year", time())) {
                             // The date is invalid, or in the future, or more than a year old.
                             $this->cleanup_import(get_string('invalidgradeexporteddate', 'grades'));
                             return $this->status;
                         }
                         $timemodified = $gradegrade->get_dategraded();
                         if (!empty($timemodified) && $exportedtime < $timemodified) {
                             // The item was graded after we exported it, we return here not to override it.
                             $user = core_user::get_user($this->studentid);
                             $this->cleanup_import(get_string('gradealreadyupdated', 'grades', fullname($user)));
                             return $this->status;
                         }
                     }
                 }
                 $insertid = self::insert_grade_record($newgrade, $this->studentid);
                 // Check to see if the insert was successful.
                 if (empty($insertid)) {
                     return null;
                 }
             }
         }
         // Updating/inserting all comments here.
         if ($this->status and !empty($this->newfeedbacks)) {
             foreach ($this->newfeedbacks as $newfeedback) {
                 $sql = "SELECT *\n                              FROM {grade_import_values}\n                             WHERE importcode=? AND userid=? AND itemid=? AND importer=?";
                 if ($feedback = $DB->get_record_sql($sql, array($this->importcode, $this->studentid, $newfeedback->itemid, $USER->id))) {
                     $newfeedback->id = $feedback->id;
                     $DB->update_record('grade_import_values', $newfeedback);
                 } else {
                     // The grade item for this is not updated.
                     $newfeedback->importonlyfeedback = true;
                     $insertid = self::insert_grade_record($newfeedback, $this->studentid);
                     // Check to see if the insert was successful.
                     if (empty($insertid)) {
                         return null;
                     }
                 }
             }
         }
     }
     return $this->status;
 }