From: skodak Date: Mon, 25 Feb 2008 12:39:48 +0000 (+0000) Subject: MDL-9657 better dealing with drafts in assignment; merged from MOODLE_19_STABLE X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=39bc9fbbbb13a5d38d9d9f3d8e0e35f09e550fb4;p=moodle.git MDL-9657 better dealing with drafts in assignment; merged from MOODLE_19_STABLE --- diff --git a/lang/en_utf8/assignment.php b/lang/en_utf8/assignment.php index d32dd13522..69233bea2a 100644 --- a/lang/en_utf8/assignment.php +++ b/lang/en_utf8/assignment.php @@ -88,6 +88,7 @@ $string['noassignments'] = 'There are no assignments yet'; $string['noattempts'] = 'No attempts have been made on this assignment'; $string['nofiles'] = 'No files were submitted'; $string['nofilesyet'] = 'No files submitted yet'; +$string['nomoresubmissions'] = 'No further submissions are allowed.'; $string['notavailableyet'] = 'Sorry, this assignment is not yet available.
Assignment instructions will be displayed here on the date given below.'; $string['notes'] = 'Notes'; $string['notesempty'] = 'No entry'; diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php index 7e81d71285..3d02b463a7 100644 --- a/mod/assignment/type/upload/assignment.class.php +++ b/mod/assignment/type/upload/assignment.class.php @@ -1,7 +1,8 @@ libdir.'/formslib.php'); -define('ASSIGNMENT_STATUS_SUBMITTED', 'submitted'); +define('ASSIGNMENT_STATUS_SUBMITTED', 'submitted'); // student thinks it is finished +define('ASSIGNMENT_STATUS_CLOSED', 'closed'); // teacher prevents more submissions /** * Extend the base assignment class for assignments where you upload a single file @@ -41,7 +42,7 @@ class assignment_upload extends assignment_base { $this->view_feedback(); - if ($this->is_finalized($submission)) { + if (!$this->isopen() or $this->is_finalized($submission)) { print_heading(get_string('submission', 'assignment'), '', 3); } else { print_heading(get_string('submissiondraft', 'assignment'), '', 3); @@ -50,7 +51,7 @@ class assignment_upload extends assignment_base { if ($filecount and $submission) { print_simple_box($this->print_user_files($USER->id, true), 'center'); } else { - if ($this->is_finalized($submission)) { + if (!$this->isopen() or $this->is_finalized($submission)) { print_simple_box(get_string('nofiles', 'assignment'), 'center'); } else { print_simple_box(get_string('nofilesyet', 'assignment'), 'center'); @@ -186,7 +187,7 @@ class assignment_upload extends assignment_base { $submission = $this->get_submission($USER->id); - if ($this->can_finalize($submission)) { + if ($this->isopen() and $this->can_finalize($submission)) { //print final submit button print_heading(get_string('submitformarking','assignment'), '', 3); echo '
'; @@ -198,19 +199,26 @@ class assignment_upload extends assignment_base { echo ''; echo ''; echo '
'; - } else if ($this->is_finalized($submission)) { - print_heading(get_string('submitedformarking','assignment'), '', 3); + } else if (!$this->isopen()) { + print_heading(get_string('nomoresubmissions','assignment'), '', 3); + + } else if ($state = $this->is_finalized($submission)) { + if ($state == ASSIGNMENT_STATUS_SUBMITTED) { + print_heading(get_string('submitedformarking','assignment'), '', 3); + } else { + print_heading(get_string('nomoresubmissions','assignment'), '', 3); + } } else { //no submission yet } } - - - /* + + + /** * Return true if var3 == hide description till available day - * + * *@return boolean - */ + */ function description_is_hidden() { return ($this->assignment->var3 && (time() <= $this->assignment->timeavailable)); } @@ -264,7 +272,7 @@ class assignment_upload extends assignment_base { $output = ''; if ($basedir = $this->file_area($userid)) { - if (!$this->is_finalized($submission)) { + if ($this->isopen() and !$this->is_finalized($submission)) { $output .= ''.get_string('draft', 'assignment').': '; } @@ -314,59 +322,57 @@ class assignment_upload extends assignment_base { $output = ''; - if ($submission = $this->get_submission($userid)) { - - $candelete = $this->can_delete_files($submission); - $strdelete = get_string('delete'); + $submission = $this->get_submission($userid); - if (!$this->is_finalized($submission) and !empty($mode)) { // only during grading - $output .= ''.get_string('draft', 'assignment').':
'; - } + $candelete = $this->can_delete_files($submission); + $strdelete = get_string('delete'); - if ($this->notes_allowed() and !empty($submission->data1) and !empty($mode)) { // only during grading + if ($this->isopen() and !$this->is_finalized($submission) and !empty($mode)) { // only during grading + $output .= ''.get_string('draft', 'assignment').':
'; + } - $npurl = $CFG->wwwroot."/mod/assignment/type/upload/notes.php?id={$this->cm->id}&userid=$userid&offset=$offset&mode=single"; - $output .= ''.get_string('notes', 'assignment').'
'; + if ($this->notes_allowed() and !empty($submission->data1) and !empty($mode)) { // only during grading - } + $npurl = $CFG->wwwroot."/mod/assignment/type/upload/notes.php?id={$this->cm->id}&userid=$userid&offset=$offset&mode=single"; + $output .= ''.get_string('notes', 'assignment').'
'; - if ($basedir = $this->file_area($userid)) { - if ($files = get_directory_list($basedir, 'responses')) { - require_once($CFG->libdir.'/filelib.php'); - foreach ($files as $key => $file) { + } - $icon = mimeinfo('icon', $file); + if ($basedir = $this->file_area($userid)) { + if ($files = get_directory_list($basedir, 'responses')) { + require_once($CFG->libdir.'/filelib.php'); + foreach ($files as $key => $file) { - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; + $icon = mimeinfo('icon', $file); + $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - $output .= ''.$icon.''.$file.''; - if ($candelete) { - $delurl = "$CFG->wwwroot/mod/assignment/delete.php?id={$this->cm->id}&file=$file&userid={$submission->userid}&mode=$mode&offset=$offset"; + $output .= ''.$icon.''.$file.''; - $output .= ' ' - .' '; - } + if ($candelete) { + $delurl = "$CFG->wwwroot/mod/assignment/delete.php?id={$this->cm->id}&file=$file&userid={$submission->userid}&mode=$mode&offset=$offset"; - $output .= '
'; + $output .= ' ' + .' '; } + + $output .= '
'; } } - if (has_capability('mod/assignment:grade', $this->context) and $mode != '') { // we do not want it on view.php page - if ($this->can_unfinalize($submission)) { - $options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'unfinalize', 'mode'=>$mode, 'offset'=>$offset); - $output .= print_single_button('upload.php', $options, get_string('unfinalize', 'assignment'), 'post', '_self', true); - } else if ($this->can_finalize($submission)) { - $options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'finalize', 'mode'=>$mode, 'offset'=>$offset); - $output .= print_single_button('upload.php', $options, get_string('finalize', 'assignment'), 'post', '_self', true); - } + } + if (has_capability('mod/assignment:grade', $this->context) and $mode != '') { // we do not want it on view.php page + if ($this->can_unfinalize($submission)) { + $options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'unfinalize', 'mode'=>$mode, 'offset'=>$offset); + $output .= print_single_button('upload.php', $options, get_string('unfinalize', 'assignment'), 'post', '_self', true); + } else if ($this->can_finalize($submission)) { + $options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'finalizeclose', 'mode'=>$mode, 'offset'=>$offset); + $output .= print_single_button('upload.php', $options, get_string('finalize', 'assignment'), 'post', '_self', true); } - - $output = '
'.$output.'
'; - } + $output = '
'.$output.'
'; + if ($return) { return $output; } @@ -429,6 +435,9 @@ class assignment_upload extends assignment_base { case 'finalize': $this->finalize(); break; + case 'finalizeclose': + $this->finalize(true); + break; case 'unfinalize': $this->unfinalize(); break; @@ -587,7 +596,7 @@ class assignment_upload extends assignment_base { die; } - function finalize() { + function finalize($forceclosing=false) { global $USER; $userid = optional_param('userid', 0, PARAM_INT); @@ -597,16 +606,16 @@ class assignment_upload extends assignment_base { $offset = required_param('offset', PARAM_INT); $returnurl = "submissions.php?id={$this->cm->id}&userid=$userid&mode=$mode&offset=$offset&forcerefresh=1"; $confirm = true; - $submission = $this->get_submission($userid); + $submission = $this->get_submission($userid, true); } else { $confirm = optional_param('confirm', 0, PARAM_BOOL); $returnurl = 'view.php?id='.$this->cm->id; - $submission = $this->get_submission($USER->id); + $submission = $this->get_submission($USER->id, true); } if (!$this->can_finalize($submission)) { - redirect($returnurl); // probably already graded, erdirect to assignment page, the reason should be obvious + redirect($returnurl); // probably already graded, redirect to assignment page, the reason should be obvious } if (!data_submitted('nomatch') or !$confirm) { @@ -621,7 +630,12 @@ class assignment_upload extends assignment_base { } else { $updated = new object(); $updated->id = $submission->id; - $updated->data2 = ASSIGNMENT_STATUS_SUBMITTED; + if ($forceclosing) { + $updated->data2 = ASSIGNMENT_STATUS_CLOSED; + } else { + $updated->data2 = ASSIGNMENT_STATUS_SUBMITTED; + } + $updated->timemodified = time(); if (update_record('assignment_submissions', $updated)) { add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finilize action to log @@ -654,7 +668,7 @@ class assignment_upload extends assignment_base { $updated->id = $submission->id; $updated->data2 = ''; if (update_record('assignment_submissions', $updated)) { - //TODO: add unfinilize action to log + //TODO: add unfinalize action to log add_to_log($this->course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id); } else { $this->view_header(get_string('submitformarking')); @@ -846,11 +860,20 @@ class assignment_upload extends assignment_base { } } + /** + * Returns submission status + * @param object $submission - may be empty + * @return string submission state - empty, ASSIGNMENT_STATUS_SUBMITTED or ASSIGNMENT_STATUS_CLOSED + */ function is_finalized($submission) { - if ($submission->data2 == ASSIGNMENT_STATUS_SUBMITTED) { - return true; + if (empty($submission)) { + return ''; + + } else if ($submission->data2 == ASSIGNMENT_STATUS_SUBMITTED or $submission->data2 == ASSIGNMENT_STATUS_CLOSED) { + return $submission->data2; + } else { - return false; + return ''; } }