|
@@ -90,10 +90,7 @@ function read_csv ($content, $context, $data, $zipfiles = null) {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // Already used all files, so delete extra copies
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -117,32 +114,43 @@ function prepare_csv ($content) {
|
|
}
|
|
}
|
|
|
|
|
|
function store_feedback ($feedback, $contextid, $submissionid) {
|
|
function store_feedback ($feedback, $contextid, $submissionid) {
|
|
- global $DB;
|
|
|
|
|
|
+ global $DB, $USER;
|
|
// Prepare data to submit to gradeimporter_feedback table
|
|
// Prepare data to submit to gradeimporter_feedback table
|
|
- $entry = new stdClass();
|
|
|
|
- $entry->id = null;
|
|
|
|
|
|
+ $entry = feedback_exists($feedback, $submissionid);
|
|
|
|
+ $isnewentry = false;
|
|
|
|
+ if (!$entry) {
|
|
|
|
+ $entry = new stdClass();
|
|
|
|
+ $entry->id = null;
|
|
|
|
+ $entry->timecreated = time();
|
|
|
|
+ $entry->submissionid = $submissionid;
|
|
|
|
+ $entry->studentid = $feedback['id'];
|
|
|
|
+ $entry->contextid = $contextid;
|
|
|
|
+ $isnewentry = true;
|
|
|
|
+ } else {
|
|
|
|
+ // If already had a feedback
|
|
|
|
+ // Deletes its files and remove its entry on DB
|
|
|
|
+ delete_feedback_files($entry);
|
|
|
|
+ $DB->delete_records('gradeimporter_feedback',
|
|
|
|
+ array('submissionid' => $submissionid,
|
|
|
|
+ 'studentid' => $feedback['id'])
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
|
|
- $entry->timecreated = time();
|
|
|
|
$entry->timemodified = time();
|
|
$entry->timemodified = time();
|
|
-
|
|
|
|
- $entry->submissionid = $submissionid;
|
|
|
|
- $entry->studentid = $feedback['id'];
|
|
|
|
$entry->grade = $feedback['grade'];
|
|
$entry->grade = $feedback['grade'];
|
|
$entry->comment = $feedback['comment'];
|
|
$entry->comment = $feedback['comment'];
|
|
$entry->name = $feedback['file'];
|
|
$entry->name = $feedback['file'];
|
|
- $entry->fileid = 0;
|
|
|
|
- $entry->usermodified = 1;
|
|
|
|
- $entry->contextid = $contextid;
|
|
|
|
-
|
|
|
|
- // Insert data into gradeimporter_feedback table and gets ID
|
|
|
|
- $entry->id = $DB->insert_record('gradeimporter_feedback', $entry);
|
|
|
|
|
|
+ $entry->fileid = 0; // To be removed fileid is now feedbackid
|
|
|
|
+ $entry->usermodified = $USER->id;
|
|
|
|
|
|
- return $entry->id;
|
|
|
|
|
|
+ // If is not a new feedback update previous record and return id
|
|
|
|
+ return $DB->insert_record('gradeimporter_feedback', $entry);
|
|
}
|
|
}
|
|
|
|
|
|
function store_feedback_file ($feedback, $context, $submission, $filetostore, $feedbackid) {
|
|
function store_feedback_file ($feedback, $context, $submission, $filetostore, $feedbackid) {
|
|
// Prepare file
|
|
// Prepare file
|
|
$fs = get_file_storage();
|
|
$fs = get_file_storage();
|
|
|
|
+ // Create file information needed
|
|
$fileinfo = array(
|
|
$fileinfo = array(
|
|
'contextid' => $context->id,
|
|
'contextid' => $context->id,
|
|
'component' => 'mod_gradeimporter',
|
|
'component' => 'mod_gradeimporter',
|
|
@@ -153,9 +161,8 @@ function store_feedback_file ($feedback, $context, $submission, $filetostore, $f
|
|
'timecreated' => time(), 'timemodified' => time()
|
|
'timecreated' => time(), 'timemodified' => time()
|
|
);
|
|
);
|
|
|
|
|
|
- $fileinfo = $fs->create_file_from_storedfile($fileinfo, $filetostore);
|
|
|
|
-
|
|
|
|
- return $fileinfo;
|
|
|
|
|
|
+ // store files in correct area
|
|
|
|
+ return $fs->create_file_from_storedfile($fileinfo, $filetostore);
|
|
}
|
|
}
|
|
|
|
|
|
function read_zip ($file, $context, $fs) {
|
|
function read_zip ($file, $context, $fs) {
|
|
@@ -202,3 +209,27 @@ function validate_formdata($data) {
|
|
throw new moodle_exception(get_string('invalidtype', 'gradeimporter'));
|
|
throw new moodle_exception(get_string('invalidtype', 'gradeimporter'));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+function feedback_exists($feedback, $submissionid) {
|
|
|
|
+ global $DB;
|
|
|
|
+ $feedback = $DB->get_record('gradeimporter_feedback',
|
|
|
|
+ array('submissionid' => $submissionid,
|
|
|
|
+ 'studentid' => $feedback['id']),
|
|
|
|
+ );
|
|
|
|
+ return $feedback;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Searches if a feedback has a file when updating it
|
|
|
|
+ * If already has file then delete it to open space for a new file
|
|
|
|
+ * Or if updated feedback doesnt have associated file
|
|
|
|
+ * @param $feedback - record of already submited feedback
|
|
|
|
+ * @return void
|
|
|
|
+ */
|
|
|
|
+function delete_feedback_files($feedback) {
|
|
|
|
+ $fs = get_file_storage();
|
|
|
|
+ $file = $fs->get_file($feedback->contextid, 'mod_gradeimporter', 'submissionfiles', $feedback->id, '/', $feedback->name);
|
|
|
|
+ if ($file) {
|
|
|
|
+ $file->delete();
|
|
|
|
+ }
|
|
|
|
+}
|