Skip to content

Commit

Permalink
Assignment MDL-22893
Browse files Browse the repository at this point in the history
 - response files uploading now uses the new file manager element in advanced upload type. (@todo: single upload->use file picker)
 - fixed file manager using $USER->id, now using the submission->userid to display the file area files.
  • Loading branch information
aparup committed Jul 13, 2010
1 parent d39595c commit 6ad4b78
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 30 deletions.
51 changes: 25 additions & 26 deletions mod/assignment/type/upload/assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function view_upload_form() {
} else {
$str = get_string('uploadfiles', 'assignment');
}
echo $OUTPUT->single_button(new moodle_url('/mod/assignment/type/upload/upload.php', array('contextid'=>$this->context->id)), $str, 'get');
echo $OUTPUT->single_button(new moodle_url('/mod/assignment/type/upload/upload.php', array('contextid'=>$this->context->id, 'userid'=>$submission->userid)), $str, 'get');
}

}
Expand Down Expand Up @@ -265,21 +265,23 @@ function description_is_hidden() {
}

function custom_feedbackform($submission, $return=false) {
global $CFG;
global $CFG, $OUTPUT;

$mode = optional_param('mode', '', PARAM_ALPHA);
$offset = optional_param('offset', 0, PARAM_INT);
$forcerefresh = optional_param('forcerefresh', 0, PARAM_BOOL);

$mform = new mod_assignment_upload_response_form("$CFG->wwwroot/mod/assignment/upload.php", $this);

$mform->set_data(array('id'=>$this->cm->id, 'offset'=>$offset, 'forcerefresh'=>$forcerefresh, 'userid'=>$submission->userid, 'mode'=>$mode));
if ($this->count_responsefiles($submission->userid) > 0) {
$str = get_string('editthesefiles', 'assignment');
} else {
$str = get_string('uploadfiles', 'assignment');
}

$output = get_string('responsefiles', 'assignment').': ';

ob_start();
$mform->display();
$output = ob_get_clean();
$output .= $OUTPUT->single_button(new moodle_url('/mod/assignment/type/upload/upload.php',
array('contextid'=>$this->context->id,'id'=>$this->cm->id, 'offset'=>$offset,
'forcerefresh'=>$forcerefresh, 'userid'=>$submission->userid, 'mode'=>$mode)), $str, 'get');

if ($forcerefresh) {
$output .= $this->update_main_listing($submission);
Expand Down Expand Up @@ -418,7 +420,6 @@ function print_responsefiles($userid, $return=false) {
*/
function upload($mform = null, $filemanager_options = null) {
$action = required_param('action', PARAM_ALPHA);
error_log($action);
switch ($action) {
case 'finalize':
$this->finalize();
Expand All @@ -430,7 +431,7 @@ function upload($mform = null, $filemanager_options = null) {
$this->unfinalize();
break;
case 'uploadresponse':
$this->upload_responsefile();
$this->upload_responsefile($mform, $filemanager_options);
break;
case 'uploadfile':
$this->upload_file($mform, $filemanager_options);
Expand Down Expand Up @@ -508,25 +509,21 @@ function upload_notes() {
die;
}

function upload_responsefile() {
function upload_responsefile($mform, $options) {
global $CFG, $USER, $OUTPUT, $PAGE;

$userid = required_param('userid', PARAM_INT);
$mode = required_param('mode', PARAM_ALPHA);
$offset = required_param('offset', PARAM_INT);

$returnurl = new moodle_url("submissions.php", array('id'=>$this->cm->id,'userid'=>$userid,'mode'=>$mode,'offset'=>$offset)); //not xhtml, just url.
$mform = new mod_assignment_upload_response_form(null, $this);
if ($mform->get_data() and $this->can_manage_responsefiles()) {

if ($formdata = $mform->get_data() and $this->can_manage_responsefiles()) {
$fs = get_file_storage();
$filename = $mform->get_new_filename('newfile');
if ($filename !== false) {
$submission = $this->get_submission($userid, true, true);
if (!$fs->file_exists($this->context->id, 'mod_assignment', 'response', $submission->id, '/', $filename)) {
if ($file = $mform->save_stored_file('newfile', $this->context->id, 'mod_assignment', 'response', $submission->id, '/', $filename, false, $USER->id)) {
redirect($returnurl->out(false));
}
}
$submission = $this->get_submission($userid, true, true);
if ($formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'response', $submission->id)) {
$returnurl = new moodle_url("/mod/assignment/submissions.php", array('id'=>$this->cm->id,'userid'=>$formdata->userid,'mode'=>$formdata->mode,'offset'=>$formdata->offset));
redirect($returnurl->out(false));
}
}
$PAGE->set_title(get_string('upload'));
Expand Down Expand Up @@ -1187,20 +1184,22 @@ function definition() {
$instance = $this->_customdata;

// visible elements
$mform->addElement('file', 'newfile', get_string('uploadafile'));
$mform->addElement('filemanager', 'files_filemanager', get_string('uploadafile'), null, $instance->options);

// hidden params
$mform->addElement('hidden', 'id', $instance->cm->id);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'contextid', $instance->contextid);
$mform->setType('contextid', PARAM_INT);
$mform->addElement('hidden', 'action', 'uploadresponse');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('hidden', 'mode');
$mform->addElement('hidden', 'mode', $instance->mode);
$mform->setType('mode', PARAM_ALPHA);
$mform->addElement('hidden', 'offset');
$mform->addElement('hidden', 'offset', $instance->offset);
$mform->setType('offset', PARAM_INT);
$mform->addElement('hidden', 'forcerefresh');
$mform->addElement('hidden', 'forcerefresh' , $instance->forcerefresh);
$mform->setType('forcerefresh', PARAM_INT);
$mform->addElement('hidden', 'userid');
$mform->addElement('hidden', 'userid', $instance->userid);
$mform->setType('userid', PARAM_INT);

// buttons
Expand Down
34 changes: 30 additions & 4 deletions mod/assignment/type/upload/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@
require_once("$CFG->dirroot/repository/lib.php");

$contextid = required_param('contextid', PARAM_INT);
$id = optional_param('id', null, PARAM_INT);

$url = new moodle_url('/mod/assignment/type/upload/upload.php', array('contextid'=>$contextid));
$formdata = new object();
$formdata->userid = required_param('userid', PARAM_INT);
$formdata->offset = optional_param('offset', null, PARAM_INT);
$formdata->forcerefresh = optional_param('forcerefresh', null, PARAM_INT);
$formdata->mode = optional_param('mode', null, PARAM_ALPHA);

$url = new moodle_url('/mod/assignment/type/upload/upload.php', array('contextid'=>$contextid,
'id'=>$id,'offset'=>$formdata->offset,'forcerefresh'=>$formdata->forcerefresh,'userid'=>$formdata->userid,'mode'=>$formdata->mode));

list($context, $course, $cm) = get_context_info_array($contextid);

Expand All @@ -49,14 +57,26 @@
$PAGE->set_heading($title);

$instance = new assignment_upload($cm->id, $assignment, $cm, $course);
$submission = $instance->get_submission($USER->id, true);
$submission = $instance->get_submission($formdata->userid, true);

$filemanager_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);

$mform = new mod_assignment_upload_form(null, array('contextid'=>$contextid, 'options'=>$filemanager_options));
if ($id==null) {
$mform = new mod_assignment_upload_form(null, array('contextid'=>$contextid, 'userid'=>$formdata->userid, 'options'=>$filemanager_options));
} else {
$formdata->cm->id = $id;
$formdata->contextid = $contextid;
$formdata->options = $filemanager_options;
$mform = new mod_assignment_upload_response_form(null, $formdata);
}

if ($mform->is_cancelled()) {
redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
if ($id==null) {
redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
} else {
$instance->display_submission($formdata->offset, $formdata->userid);
die();
}
} else if ($formdata = $mform->get_data()) {
$instance->upload($mform, $filemanager_options);
die;
Expand All @@ -72,6 +92,12 @@
// set file manager itemid, so it will find the files in draft area
$mform->set_data($data);
$mform->display();
} else if ($instance->can_manage_responsefiles() && !($id==null)) { //a 'response' files upload
// move submission files to user draft area
$formdata = file_prepare_standard_filemanager($formdata, 'files', $filemanager_options, $context, 'mod_assignment', 'response', $submission->id);
// set file manager itemid, so it will find the files in draft area
$mform->set_data($formdata);
$mform->display();
} else {
echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
echo $OUTPUT->continue_button(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
Expand Down
2 changes: 2 additions & 0 deletions mod/assignment/type/upload/upload_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function definition() {
// hidden params
$mform->addElement('hidden', 'contextid', $instance['contextid']);
$mform->setType('contextid', PARAM_INT);
$mform->addElement('hidden', 'userid', $instance['userid']);
$mform->setType('userid', PARAM_INT);
$mform->addElement('hidden', 'action', 'uploadfile');
$mform->setType('action', PARAM_ALPHA);

Expand Down

0 comments on commit 6ad4b78

Please sign in to comment.