diff --git a/grade/import/csv/classes/load_data.php b/grade/import/csv/classes/load_data.php index 3cbb069ae64..080c77ea6fa 100644 --- a/grade/import/csv/classes/load_data.php +++ b/grade/import/csv/classes/load_data.php @@ -267,7 +267,7 @@ class gradeimport_csv_load_data { * @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) { @@ -425,16 +425,20 @@ class gradeimport_csv_load_data { $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. @@ -528,6 +532,14 @@ class gradeimport_csv_load_data { 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)) { diff --git a/grade/import/csv/index.php b/grade/import/csv/index.php index 21c72704ae0..0c2a5d27ab4 100644 --- a/grade/import/csv/index.php +++ b/grade/import/csv/index.php @@ -27,6 +27,7 @@ $separator = optional_param('separator', '', PARAM_ALPHA); $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 !== '') { @@ -67,6 +68,7 @@ if (!$iid) { // 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); @@ -100,6 +102,7 @@ $mappingformdata = array( 'iid' => $iid, 'id' => $id, 'importcode' => $importcode, + 'forceimport' => $forceimport, 'verbosescales' => $verbosescales ); // we create a form to handle mapping data from the file to the database. diff --git a/grade/import/direct/classes/import_form.php b/grade/import/direct/classes/import_form.php index bab48caae0b..0a10b1139eb 100644 --- a/grade/import/direct/classes/import_form.php +++ b/grade/import/direct/classes/import_form.php @@ -66,6 +66,9 @@ class gradeimport_direct_import_form extends moodleform { $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')); } } diff --git a/grade/import/direct/classes/mapping_form.php b/grade/import/direct/classes/mapping_form.php index 5dc7c56110c..a097332c006 100644 --- a/grade/import/direct/classes/mapping_form.php +++ b/grade/import/direct/classes/mapping_form.php @@ -106,6 +106,9 @@ class gradeimport_direct_mapping_form extends moodleform { $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')); } } diff --git a/grade/import/direct/index.php b/grade/import/direct/index.php index 1a9fc67c142..c620e6f8879 100644 --- a/grade/import/direct/index.php +++ b/grade/import/direct/index.php @@ -24,6 +24,7 @@ $id = required_param('id', PARAM_INT); // Course id. $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)); @@ -96,6 +97,7 @@ $mappingformdata = array( 'header' => $header, 'iid' => $iid, 'id' => $id, + 'forceimport' => $forceimport, 'importcode' => $importcode, 'verbosescales' => $verbosescales ); diff --git a/grade/import/grade_import_form.php b/grade/import/grade_import_form.php index 1bc546eec6c..7ce9c9490ae 100644 --- a/grade/import/grade_import_form.php +++ b/grade/import/grade_import_form.php @@ -70,6 +70,9 @@ class grade_import_form extends moodleform { $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')); @@ -152,6 +155,9 @@ class grade_import_mapping_form extends moodleform { $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')); } diff --git a/lang/en/grades.php b/lang/en/grades.php index 118d3663db4..fce23246449 100644 --- a/lang/en/grades.php +++ b/lang/en/grades.php @@ -223,6 +223,10 @@ $string['feedbacksaved'] = 'Feedback saved'; $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}'; @@ -232,6 +236,7 @@ $string['fullmode'] = 'Full view'; $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.';