mod/assignment MDL-22609 Checking in Aparup's patch fixing the file upgrade (itemid now is submission->id, not user->id). Also fixed some buggy uses of $OUTPUT->notification in uploadsingle->upload() (redirect works better)
This commit is contained in:
@@ -68,15 +68,18 @@ function xmldb_assignment_upgrade($oldversion) {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $submission->cmid);
|
||||
|
||||
// migrate submitted files first
|
||||
$path = $basepath;
|
||||
$newpath = "$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->id/";
|
||||
if (!file_exists($newpath)) {
|
||||
mkdir($newpath);
|
||||
}
|
||||
$filearea = 'assignment_submission';
|
||||
$items = new DirectoryIterator($path);
|
||||
$items = new DirectoryIterator($basepath);
|
||||
foreach ($items as $item) {
|
||||
if (!$item->isFile()) {
|
||||
continue;
|
||||
}
|
||||
if (!$item->isReadable()) {
|
||||
echo $OUTPUT->notification(" File not readable, skipping: ".$path.$item->getFilename());
|
||||
echo $OUTPUT->notification(" File not readable, skipping: ".$basepath.$item->getFilename());
|
||||
continue;
|
||||
}
|
||||
$filename = clean_param($item->getFilename(), PARAM_FILE);
|
||||
@@ -84,19 +87,20 @@ function xmldb_assignment_upgrade($oldversion) {
|
||||
continue;
|
||||
}
|
||||
if (!$fs->file_exists($context->id, $filearea, $submission->userid, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'filearea'=>$filearea, 'itemid'=>$submission->userid, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$submission->userid);
|
||||
if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) {
|
||||
unlink($path.$item->getFilename());
|
||||
$file_record = array('contextid'=>$context->id, 'filearea'=>$filearea, 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$submission->userid);
|
||||
if ($fs->create_file_from_pathname($file_record, $basepath.$item->getFilename())) {
|
||||
unlink($basepath.$item->getFilename());
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($items); //release file handles
|
||||
|
||||
// migrate teacher response files
|
||||
$path = $basepath.'responses/';
|
||||
if (file_exists($path)) {
|
||||
$basepath = $basepath.'responses/';
|
||||
$newpath = $newpath.'responses/';
|
||||
if (file_exists($basepath)) {
|
||||
$filearea = 'assignment_response';
|
||||
$items = new DirectoryIterator($path);
|
||||
$items = new DirectoryIterator($basepath);
|
||||
foreach ($items as $item) {
|
||||
if (!$item->isFile()) {
|
||||
continue;
|
||||
@@ -106,13 +110,13 @@ function xmldb_assignment_upgrade($oldversion) {
|
||||
continue;
|
||||
}
|
||||
if (!$fs->file_exists($context->id, $filearea, $submission->userid, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'filearea'=>$filearea, 'itemid'=>$submission->userid, 'filepath'=>'/', 'filename'=>$filename,
|
||||
$file_record = array('contextid'=>$context->id, 'filearea'=>$filearea, 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename,
|
||||
'timecreated'=>$item->getCTime(), 'timemodified'=>$item->getMTime());
|
||||
if ($submission->teacher) {
|
||||
$file_record['userid'] = $submission->teacher;
|
||||
}
|
||||
if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) {
|
||||
unlink($path.$item->getFilename());
|
||||
if ($fs->create_file_from_pathname($file_record, $basepath.$item->getFilename())) {
|
||||
unlink($basepath.$item->getFilename());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ class assignment_upload extends assignment_base {
|
||||
$this->view_dates();
|
||||
|
||||
if (has_capability('mod/assignment:submit', $this->context)) {
|
||||
$filecount = $this->count_user_files($USER->id);
|
||||
$submission = $this->get_submission($USER->id);
|
||||
$filecount = $this->count_user_files($submission->id);
|
||||
|
||||
$this->view_feedback();
|
||||
|
||||
@@ -344,16 +344,16 @@ class assignment_upload extends assignment_base {
|
||||
$fs = get_file_storage();
|
||||
$browser = get_file_browser();
|
||||
|
||||
if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) {
|
||||
if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $submission->id, "timemodified", false)) {
|
||||
$button = new portfolio_add_button();
|
||||
foreach ($files as $file) {
|
||||
$filename = $file->get_filename();
|
||||
$mimetype = $file->get_mimetype();
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$submission->id.'/'.$filename);
|
||||
$output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>';
|
||||
|
||||
if ($candelete) {
|
||||
$delurl = "$CFG->wwwroot/mod/assignment/delete.php?id={$this->cm->id}&file=".rawurlencode($filename)."&userid={$submission->userid}&mode=$mode&offset=$offset";
|
||||
$delurl = "$CFG->wwwroot/mod/assignment/delete.php?id={$this->cm->id}&file=".rawurlencode($filename)."&userid=$userid&submissionid={$submission->id}&mode=$mode&offset=$offset";
|
||||
|
||||
$output .= '<a href="'.$delurl.'"> '
|
||||
.'<img title="'.$strdelete.'" src="'.$OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="" /></a> ';
|
||||
@@ -575,11 +575,13 @@ class assignment_upload extends assignment_base {
|
||||
$fs = get_file_storage();
|
||||
$filename = $mform->get_new_filename('newfile');
|
||||
if ($filename !== false) {
|
||||
if (!$fs->file_exists($this->context->id, 'assignment_submission', $USER->id, '/', $filename)) {
|
||||
if ($file = $mform->save_stored_file('newfile', $this->context->id, 'assignment_submission', $USER->id, '/', $filename, false, $USER->id)) {
|
||||
$submission = $this->get_submission($USER->id, true); //create new submission if needed
|
||||
$submission->timemodified = time();
|
||||
if ($DB->update_record('assignment_submissions', $submission)) {
|
||||
if (!$fs->file_exists($this->context->id, 'assignment_submission', $submission->id, '/', $filename)) {
|
||||
if ($file = $mform->save_stored_file('newfile', $this->context->id, 'assignment_submission', $submission->id, '/', $filename, false, $USER->id)) {
|
||||
$updates = new object();
|
||||
$updates->id = $submission->id;
|
||||
$updates->timemodified = time();
|
||||
if ($DB->update_record('assignment_submissions', $updates)) {
|
||||
add_to_log($this->course->id, 'assignment', 'upload',
|
||||
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
|
||||
$this->update_grade($submission);
|
||||
@@ -823,6 +825,7 @@ class assignment_upload extends assignment_base {
|
||||
|
||||
$file = required_param('file', PARAM_FILE);
|
||||
$userid = required_param('userid', PARAM_INT);
|
||||
$submissionid = required_param('submissionid', PARAM_INT);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
$mode = optional_param('mode', '', PARAM_ALPHA);
|
||||
$offset = optional_param('offset', 0, PARAM_INT);
|
||||
@@ -849,7 +852,7 @@ class assignment_upload extends assignment_base {
|
||||
}
|
||||
|
||||
if (!data_submitted() or !$confirm or !confirm_sesskey()) {
|
||||
$optionsyes = array ('id'=>$this->cm->id, 'file'=>$file, 'userid'=>$userid, 'confirm'=>1, 'sesskey'=>sesskey(), 'mode'=>$mode, 'offset'=>$offset, 'sesskey'=>sesskey());
|
||||
$optionsyes = array ('id'=>$this->cm->id, 'file'=>$file, 'userid'=>$userid, 'submissionid'=>$submissionid, 'confirm'=>1, 'sesskey'=>sesskey(), 'mode'=>$mode, 'offset'=>$offset, 'sesskey'=>sesskey());
|
||||
if (empty($mode)) {
|
||||
$this->view_header(get_string('delete'));
|
||||
} else {
|
||||
@@ -867,7 +870,7 @@ class assignment_upload extends assignment_base {
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
if ($file = $fs->get_file($this->context->id, 'assignment_submission', $userid, '/', $file)) {
|
||||
if ($file = $fs->get_file($this->context->id, 'assignment_submission', $submissionid, '/', $file)) {
|
||||
if ($file->delete()) {
|
||||
$submission->timemodified = time();
|
||||
if ($DB->update_record('assignment_submissions', $submission)) {
|
||||
|
||||
@@ -50,14 +50,15 @@ class assignment_uploadsingle extends assignment_base {
|
||||
|
||||
$this->view_dates();
|
||||
|
||||
$filecount = $this->count_user_files($USER->id);
|
||||
$filecount = false;
|
||||
|
||||
if ($submission = $this->get_submission()) {
|
||||
if ($submission = $this->get_submission($USER->id)) {
|
||||
$filecount = $this->count_user_files($submission->id);
|
||||
if ($submission->timemarked) {
|
||||
$this->view_feedback();
|
||||
}
|
||||
if ($filecount) {
|
||||
echo $OUTPUT->box($this->print_user_files($USER->id, true), 'generalbox boxaligncenter');
|
||||
echo $OUTPUT->box($this->print_user_files($submission->id, true), 'generalbox boxaligncenter');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,15 +83,13 @@ class assignment_uploadsingle extends assignment_base {
|
||||
|
||||
require_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id));
|
||||
|
||||
$this->view_header(get_string('upload'));
|
||||
|
||||
$filecount = $this->count_user_files($USER->id);
|
||||
$submission = $this->get_submission($USER->id);
|
||||
if ($this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) {
|
||||
if ($submission = $this->get_submission($USER->id)) {
|
||||
//TODO: change later to ">= 0", to prevent resubmission when graded 0
|
||||
if (($submission->grade > 0) and !$this->assignment->resubmit) {
|
||||
echo $OUTPUT->notification(get_string('alreadygraded', 'assignment'));
|
||||
redirect('view.php?id='.$this->cm->id, get_string('alreadygraded', 'assignment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,17 +98,22 @@ class assignment_uploadsingle extends assignment_base {
|
||||
$fs = get_file_storage();
|
||||
$filename = $mform->get_new_filename('newfile');
|
||||
if ($filename !== false) {
|
||||
$fs->delete_area_files($this->context->id, 'assignment_submission', $USER->id);
|
||||
if ($file = $mform->save_stored_file('newfile', $this->context->id, 'assignment_submission', $USER->id, '/', $filename, false, $USER->id)) {
|
||||
$fs->delete_area_files($this->context->id, 'assignment_submission', $submission->id);
|
||||
|
||||
if (empty($submission->id)) {
|
||||
$submission = $this->get_submission($USER->id, true); //create new submission if needed
|
||||
$submission->timemodified = time();
|
||||
$submission->numfiles = 1;
|
||||
if ($DB->update_record('assignment_submissions', $submission)) {
|
||||
}
|
||||
|
||||
if ($file = $mform->save_stored_file('newfile', $this->context->id, 'assignment_submission', $submission->id, '/', $filename, false, $USER->id)) {
|
||||
$updates = new object(); //just enough data for updating the submission
|
||||
$updates->timemodified = time();
|
||||
$updates->numfiles = 1;
|
||||
$updates->id = $submission->id;
|
||||
if ($DB->update_record('assignment_submissions', $updates)) {
|
||||
add_to_log($this->course->id, 'assignment', 'upload',
|
||||
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
|
||||
$this->update_grade($submission);
|
||||
$this->email_teachers($submission);
|
||||
echo $OUTPUT->heading(get_string('uploadedfile'));
|
||||
//trigger event with information about this file.
|
||||
$eventdata = new object();
|
||||
$eventdata->component = 'mod/assignment';
|
||||
@@ -120,21 +124,19 @@ class assignment_uploadsingle extends assignment_base {
|
||||
$eventdata->file = $file;
|
||||
events_trigger('assignment_file_sent', $eventdata);
|
||||
|
||||
redirect('view.php?id='.$this->cm->id);
|
||||
redirect('view.php?id='.$this->cm->id, get_string('uploadedfile'));
|
||||
} else {
|
||||
echo $OUTPUT->notification(get_string("uploadnotregistered", "assignment", $newfile_name) );
|
||||
$file->delete();
|
||||
redirect('view.php?id='.$this->cm->id, get_string('uploadnotregistered', 'assignment', $newfile_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo $OUTPUT->notification(get_string("uploaderror", "assignment")); //submitting not allowed!
|
||||
redirect('view.php?id='.$this->cm->id, get_string('uploaderror', 'assignment')); //submitting not allowed!
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->continue_button('view.php?id='.$this->cm->id);
|
||||
|
||||
$this->view_footer();
|
||||
redirect('view.php?id='.$this->cm->id);
|
||||
}
|
||||
|
||||
function setup_elements(&$mform) {
|
||||
|
||||
Reference in New Issue
Block a user