Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-26969 Assignment module - upload: fixed get_submission() return v…

…alue to nothing when param is set to false.
  • Loading branch information...
commit 696123795765fb02849487b31cbc37f97046e61d 1 parent 947ba9c
@rwijaya rwijaya authored
Showing with 12 additions and 6 deletions.
  1. +6 −4 mod/assignment/lib.php
  2. +6 −2 mod/assignment/type/upload/upload.php
View
10 mod/assignment/lib.php
@@ -1813,10 +1813,10 @@ function process_outcomes($userid) {
*
* @global object
* @global object
- * @param $userid int The id of the user whose submission we want or 0 in which case USER->id is used
- * @param $createnew boolean optional Defaults to false. If set to true a new submission object will be created in the database
+ * @param int $userid int The id of the user whose submission we want or 0 in which case USER->id is used
+ * @param bool $createnew boolean optional Defaults to false. If set to true a new submission object will be created in the database
* @param bool $teachermodified student submission set if false
- * @return object The submission
+ * @return object|bool The submission or false if $createnew is false.
*/
function get_submission($userid=0, $createnew=false, $teachermodified=false) {
global $USER, $DB;
@@ -1827,8 +1827,10 @@ function get_submission($userid=0, $createnew=false, $teachermodified=false) {
$submission = $DB->get_record('assignment_submissions', array('assignment'=>$this->assignment->id, 'userid'=>$userid));
- if ($submission || !$createnew) {
+ if ($submission) {
return $submission;
+ } else if(!$createnew) {
+ return false;
}
$newsubmission = $this->prepare_new_submission($userid, $teachermodified);
$DB->insert_record("assignment_submissions", $newsubmission);
View
8 mod/assignment/type/upload/upload.php
@@ -59,7 +59,7 @@
$PAGE->set_heading($title);
$instance = new assignment_upload($cm->id, $assignment, $cm, $course);
-$submission = $instance->get_submission($formdata->userid, true);
+$submission = $instance->get_submission($formdata->userid, false);
$filemanager_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
@@ -77,8 +77,12 @@
echo $OUTPUT->box_start('generalbox');
if ($instance->can_upload_file($submission) && ($id==null)) {
$data = new stdClass();
+ $submissionid = null;
+ if (is_object($submission) && isset($submission->id)) {
+ $submissionid = $submission->id;
+ }
// move submission files to user draft area
- $data = file_prepare_standard_filemanager($data, 'files', $filemanager_options, $context, 'mod_assignment', 'submission', $submission->id);
+ $data = file_prepare_standard_filemanager($data, 'files', $filemanager_options, $context, 'mod_assignment', 'submission', $submissionid);
// set file manager itemid, so it will find the files in draft area
$mform->set_data($data);
$mform->display();
Please sign in to comment.
Something went wrong with that request. Please try again.