* @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 .
+ * @param string $value The grade value.
* @return array grades to be updated.
*/
protected function update_grade_item($courseid, $map, $key, $verbosescales, $value) {
$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.
return $this->status;
}
}
+
+ // The grade was modified since the export.
+ if ($forceimport === 0 && !empty($timeexportkey) && ($line[$timeexportkey] < $gradegrade->get_dategraded())) {
+ $user = core_user::get_user($this->studentid);
+ $this->cleanup_import(get_string('gradealreadyupdated', 'grades', fullname($user)));
+ break;
+ }
+
$insertid = self::insert_grade_record($newgrade, $this->studentid);
// Check to see if the insert was successful.
if (empty($insertid)) {
$verbosescales = optional_param('verbosescales', 1, PARAM_BOOL);
$iid = optional_param('iid', null, PARAM_INT);
$importcode = optional_param('importcode', '', PARAM_FILE);
+$forceimport = optional_param('forceimport', 0, PARAM_BOOL);
$url = new moodle_url('/grade/import/csv/index.php', array('id'=>$id));
if ($separator !== '') {
// If the import form has been submitted.
if ($formdata = $mform->get_data()) {
+
$text = $mform->get_file_content('userfile');
$csvimport = new gradeimport_csv_load_data();
$csvimport->load_csv_content($text, $formdata->encoding, $separator, $formdata->previewrows);
'iid' => $iid,
'id' => $id,
'importcode' => $importcode,
+ 'forceimport' => $forceimport,
'verbosescales' => $verbosescales
);
// we create a form to handle mapping data from the file to the database.
$mform->setType('previewrows', PARAM_INT);
$mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
$mform->setType('groupid', PARAM_INT);
+ $mform->addElement('advcheckbox', 'forceimport', get_string('forceimport', 'grades'));
+ $mform->addHelpButton('forceimport', 'forceimport', 'grades');
+ $mform->setDefault('forceimport', 0);
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
}
}
$mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
$mform->setType('groupid', PARAM_INT);
$mform->setConstant('groupid', groups_get_course_group($COURSE));
+ $mform->addElement('hidden', 'forceimport', $this->_customdata['forceimport']);
+ $mform->setType('forceimport', PARAM_INT);
+ $mform->setConstant('forceimport', $this->_customdata['forceimport']);
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
}
}
$verbosescales = optional_param('verbosescales', 1, PARAM_BOOL);
$iid = optional_param('iid', null, PARAM_INT);
$importcode = optional_param('importcode', '', PARAM_FILE);
+$forceimport = optional_param('forceimport', null, PARAM_INT);
$url = new moodle_url('/grade/import/direct/index.php', array('id' => $id));
'header' => $header,
'iid' => $iid,
'id' => $id,
+ 'forceimport' => $forceimport,
'importcode' => $importcode,
'verbosescales' => $verbosescales
);
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
$mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
$mform->setType('previewrows', PARAM_INT);
+ $mform->addElement('checkbox', 'forceimport', get_string('forceimport', 'grades'));
+ $mform->addHelpButton('forceimport', 'forceimport', 'grades');
+ $mform->setDefault('forceimport', 0);
$mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
$mform->setType('groupid', PARAM_INT);
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
$mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
$mform->setType('groupid', PARAM_INT);
$mform->setConstant('groupid', groups_get_course_group($COURSE));
+ $mform->addElement('hidden', 'forceimport', $this->_customdata['forceimport']);
+ $mform->setType('forceimport', PARAM_BOOL);
+ $mform->setConstant('forceimport', $this->_customdata['forceimport']);
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
}
$string['feedbackview'] = 'View feedback';
$string['finalgrade'] = 'Final grade';
$string['finalgrade_help'] = 'If the overridden checkbox is ticked, a grade may be added or amended.';
+$string['fixedstudents'] = 'Static students column';
+$string['fixedstudents_help'] = 'Allows grades to scroll horizontally without losing sight of the students column, by making it static.';
+$string['forceimport'] = 'Force import';
+$string['forceimport_help'] = 'Force import of grades even if the grades were updated after the import file was exported';
$string['forceoff'] = 'Force: Off';
$string['forceon'] = 'Force: On';
$string['forelementtypes'] = 'for the selected {$a}';
$string['generalsettings'] = 'General settings';
$string['grade'] = 'Grade';
$string['gradeadministration'] = 'Grade administration';
+$string['gradealreadyupdated'] = '{$a} grades have not been imported because the grades in the import file are older than in the grader report. To proceed with the grade import anyway, use the force import option.';
$string['gradeanalysis'] = 'Grade analysis';
$string['gradebook'] = 'Gradebook';
$string['gradebookhiddenerror'] = 'The gradebook is currently set to hide everything from students.';