assignment MDL-23820 improved grading pages for file type assignments.
authorAparup Banerjee <nebgor@gmail.com>
Mon, 30 Aug 2010 02:58:57 +0000 (02:58 +0000)
committerAparup Banerjee <nebgor@gmail.com>
Mon, 30 Aug 2010 02:58:57 +0000 (02:58 +0000)
 - uploadsingle response now uses file manager instead of file picker.
 - both uploadsingle and advancedupload assignment types have their grading pages with response file management in line (not a separate page).
 - bit of a css issue YUI's tree view rendering (a table) within a table that had borders is fixed.

mod/assignment/lang/en/assignment.php
mod/assignment/lib.php
mod/assignment/styles.css
mod/assignment/type/online/assignment.class.php
mod/assignment/type/upload/assignment.class.php
mod/assignment/type/upload/upload.php
mod/assignment/type/uploadsingle/assignment.class.php
mod/assignment/type/uploadsingle/upload.php

index f57c500..789c2ad 100644 (file)
@@ -154,6 +154,7 @@ $string['operation'] = 'Operation';
 $string['optionalsettings'] = 'Optional settings';
 $string['overwritewarning'] = 'Warning: uploading again will REPLACE your current submission';
 $string['pagesize'] = 'Submissions shown per page';
+$string['popupinnewwindow'] = 'Open in a popup window';
 $string['pluginadministration'] = 'Assignment administration';
 $string['pluginname'] = 'Assignment';
 $string['preventlate'] = 'Prevent late submissions';
index bf60f02..bc8d8cc 100644 (file)
@@ -899,10 +899,11 @@ class assignment_base {
      * @global object
      * @param string $extra_javascript
      */
-    function display_submission($offset=-1,$userid =-1) {
+    function display_submission($offset=-1,$userid =-1, $display=true) {
         global $CFG, $DB, $PAGE, $OUTPUT;
         require_once($CFG->libdir.'/gradelib.php');
         require_once($CFG->libdir.'/tablelib.php');
+        require_once("$CFG->dirroot/repository/lib.php");
         if ($userid==-1) {
             $userid = required_param('userid', PARAM_INT);
         }
@@ -1010,9 +1011,21 @@ class assignment_base {
         $mformdata->submissioncommentformat= FORMAT_HTML;
         $mformdata->submission_content= $this->print_user_files($user->id,true);
         $mformdata->filter = $filter;
+         if ($assignment->assignmenttype == 'upload') {
+            $mformdata->fileui_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+        } elseif ($assignment->assignmenttype == 'uploadsingle') {
+            $mformdata->fileui_options = array('subdirs'=>0, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+        }
 
         $submitform = new mod_assignment_grading_form( null, $mformdata );
 
+         if (!$display) {
+            $ret_data = new stdClass();
+            $ret_data->mform = $submitform;
+            $ret_data->fileui_options = $mformdata->fileui_options;
+            return $ret_data;
+        }
+
         if ($submitform->is_cancelled()) {
             redirect('submissions.php?id='.$this->cm->id);
         }
@@ -1021,7 +1034,8 @@ class assignment_base {
 
         $PAGE->set_title($this->course->fullname . ': ' .get_string('feedback', 'assignment').' - '.fullname($user, true));
         $PAGE->set_heading($this->course->fullname);
-        $PAGE->navbar->add( get_string('submissions', 'assignment') );
+        $PAGE->navbar->add(get_string('submissions', 'assignment'), new moodle_url('/mod/assignment/submissions.php', array('id'=>$cm->id)));
+        $PAGE->navbar->add(fullname($user, true));
 
         echo $OUTPUT->header();
         echo $OUTPUT->heading(get_string('feedback', 'assignment').': '.fullname($user, true));
@@ -1491,7 +1505,7 @@ class assignment_base {
      * @global object
      * @return object|bool The updated submission object or false
      */
-    function process_feedback() {
+    function process_feedback($formdata=null) {
         global $CFG, $USER, $DB;
         require_once($CFG->libdir.'/gradelib.php');
 
@@ -1545,6 +1559,12 @@ class assignment_base {
 
             add_to_log($this->course->id, 'assignment', 'update grades',
                        'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
+             if (!is_null($formdata)) {
+                    if ($this->type == 'upload' || $this->type == 'uploadsingle') {
+                        $mformdata = $formdata->mform->get_data();
+                        $mformdata = file_postupdate_standard_filemanager($mformdata, 'files', $formdata->fileui_options, $this->context, 'mod_assignment', 'response', $submission->id);
+                    }
+             }
         }
 
         return $submission;
@@ -2168,21 +2188,21 @@ class mod_assignment_grading_form extends moodleform {
                                                 userdate($this->_customdata->submission->timemodified) .
                                                 $this->_customdata->lateness );
 
+        $this->add_submission_content();
         $this->add_grades_section();
 
         $this->add_feedback_section();
 
         if ($this->_customdata->submission->timemarked) {
+            $datestring = userdate($this->_customdata->submission->timemarked)."&nbsp; (".format_time(time() - $this->_customdata->submission->timemarked).")";
             $mform->addElement('header', 'Last Grade', get_string('lastgrade', 'assignment'));
             $mform->addElement('static', 'picture', $OUTPUT->user_picture($this->_customdata->teacher) ,
                                                     fullname($this->_customdata->teacher,true).
-                                                    '<br/>'.
-                                                    userdate($this->_customdata->submission->timemarked));
+                                                    '<br/>'.$datestring);
         }
         // buttons
         $this->add_action_buttons();
 
-        $this->add_submission_content();
     }
 
     function add_grades_section() {
@@ -2245,7 +2265,14 @@ class mod_assignment_grading_form extends moodleform {
             $mform->setType('submissioncomment_editor', PARAM_RAW); // to be cleaned before display
             $mform->setDefault('submissioncomment_editor', $this->_customdata->submission->submissioncomment);
             //$mform->addRule('submissioncomment', get_string('required'), 'required', null, 'client');
-
+            switch ($this->_customdata->assignment->assignmenttype) {
+                case 'upload' :
+                case 'uploadsingle' :
+                    $mform->addElement('filemanager', 'files_filemanager', get_string('responsefiles', 'assignment'). ':', null, $this->_customdata->fileui_options);
+                    break;
+                default :
+                    break;
+            }
             $lastmailinfo = get_user_preferences('assignment_mailinfo', 1) ? array('checked'=>'checked') : array();
             $mform->addElement('hidden', 'mailinfo_h', "0");
             $mform->setType('mailinfo_h', PARAM_INT);
@@ -2258,7 +2285,6 @@ class mod_assignment_grading_form extends moodleform {
 
     function add_action_buttons() {
         $mform =& $this->_form;
-        $mform->addElement('header', 'Operation', get_string('operation', 'assignment'));
         //if there are more to be graded.
         if ($this->_customdata->nextid>0) {
             $buttonarray=array();
@@ -2273,6 +2299,7 @@ class mod_assignment_grading_form extends moodleform {
             $buttonarray[] = &$mform->createElement('cancel');
         }
         $mform->addGroup($buttonarray, 'grading_buttonar', '', array(' '), false);
+        $mform->closeHeaderBefore('grading_buttonar');
         $mform->setType('grading_buttonar', PARAM_RAW);
     }
 
@@ -2309,6 +2336,15 @@ class mod_assignment_grading_form extends moodleform {
             $itemid = null;
         }
 
+        switch ($this->_customdata->assignment->assignmenttype) {
+                case 'upload' :
+                case 'uploadsingle' :
+                    $data = file_prepare_standard_filemanager($data, 'files', $editoroptions, $this->_customdata->context, 'mod_assignment', 'response', $itemid);
+                    break;
+                default :
+                    break;
+        }
+
         $data = file_prepare_standard_editor($data, 'submissioncomment', $editoroptions, $this->_customdata->context, $editoroptions['component'], $editoroptions['filearea'], $itemid);
         return parent::set_data($data);
     }
@@ -2324,8 +2360,15 @@ class mod_assignment_grading_form extends moodleform {
 
         if ($data) {
             $editoroptions = $this->get_editor_options();
+            switch ($this->_customdata->assignment->assignmenttype) {
+                case 'upload' :
+                case 'uploadsingle' :
+                    $data = file_postupdate_standard_filemanager($data, 'files', $editoroptions, $this->_customdata->context, 'mod_assignment', 'response', $itemid);
+                    break;
+                default :
+                    break;
+            }
             $data = file_postupdate_standard_editor($data, 'submissioncomment', $editoroptions, $this->_customdata->context, $editoroptions['component'], $editoroptions['filearea'], $itemid);
-            $data->format = $data->textformat;
         }
         return $data;
     }
index d70314b..2e36c92 100644 (file)
@@ -15,6 +15,7 @@
 .path-mod-assignment .late {color: red;}
 
 /** Styles for submissions.php **/
+#page-mod-assignment-submissions fieldset.felement {margin-left: 16%;}
 #page-mod-assignment-submissions form#options div {text-align:right;margin-left:auto;margin-right:20px;}
 #page-mod-assignment-submissions .header .commands {display: inline;}
 #page-mod-assignment-submissions .picture {width: 35px;}
index 5b42cf5..90947a8 100644 (file)
@@ -214,19 +214,19 @@ class assignment_online extends assignment_base {
 
         $link = new moodle_url("/mod/assignment/type/online/file.php?id={$this->cm->id}&userid={$submission->userid}");
         $action = new popup_action('click', $link, 'file'.$userid, array('height' => 450, 'width' => 580));
-        $popup = $OUTPUT->action_link($link, shorten_text(trim(strip_tags(format_text($submission->data1,$submission->data2))), 15), $action, array('title'=>get_string('submission', 'assignment')));
+        $popup = $OUTPUT->action_link($link, get_string('popupinnewwindow','assignment'), $action, array('title'=>get_string('submission', 'assignment')));
 
         $output = '<div class="files">'.
                   '<img align="middle" src="'.$OUTPUT->pix_url('f/html') . '" height="16" width="16" alt="html" />'.
                   $popup .
                   '</div>';
 
-        $wordcount = '<p id="wordcount">';
+        $wordcount = '<p id="wordcount">'. $popup . '&nbsp;';
     /// Decide what to count
         if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_WORDS) {
-            $wordcount .= ' ('.get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))).')';
+            $wordcount .= '('.get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))).')';
         } else if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_LETTERS) {
-            $wordcount .= ' ('.get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))).')';
+            $wordcount .= '('.get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))).')';
         }
         $wordcount .= '</p>';
 
index 9574acc..12885f9 100644 (file)
@@ -264,42 +264,6 @@ class assignment_upload extends assignment_base {
         return ($this->assignment->var3 && (time() <= $this->assignment->timeavailable));
     }
 
-    function custom_feedbackform($submission, $return=false) {
-        global $CFG, $OUTPUT;
-
-        $mode         = optional_param('mode', '', PARAM_ALPHA);
-        $offset       = optional_param('offset', 0, PARAM_INT);
-        $forcerefresh = optional_param('forcerefresh', 0, PARAM_BOOL);
-
-        if ($this->count_responsefiles($submission->userid) > 0) {
-            $str = get_string('editthesefiles', 'assignment');
-        } else {
-            $str = get_string('uploadfiles', 'assignment');
-        }
-
-        $output = get_string('responsefiles', 'assignment').': ';
-
-        $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);
-        }
-
-        $responsefiles = $this->print_responsefiles($submission->userid, true);
-        if (!empty($responsefiles)) {
-            $output .= $responsefiles;
-        }
-
-        if ($return) {
-            return $output;
-        }
-        echo $output;
-        return;
-    }
-
-
     function print_student_answer($userid, $return=false){
         global $CFG, $OUTPUT, $PAGE;
 
@@ -400,6 +364,16 @@ class assignment_upload extends assignment_base {
         parent::submissions($mode);
     }
 
+    function process_feedback() {
+        if (!$feedback = data_submitted() or !confirm_sesskey()) {      // No incoming data?
+            return false;
+        }
+        $userid = required_param('userid', PARAM_INT);
+        $offset = required_param('offset', PARAM_INT);
+        $mform = $this->display_submission($offset, $userid, false);
+        parent::process_feedback($mform);
+    }
+
     function print_responsefiles($userid, $return=false) {
         global $CFG, $USER, $OUTPUT, $PAGE;
 
index bd828e4..877b2de 100644 (file)
@@ -61,22 +61,10 @@ $submission = $instance->get_submission($formdata->userid, true);
 
 $filemanager_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
 
-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()) {
-    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;
@@ -92,13 +80,7 @@ if ($instance->can_upload_file($submission) && ($id==null)) {
     // 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 {
+}else {
     echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
     echo $OUTPUT->continue_button(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
 }
index 5126d5a..23f746d 100644 (file)
@@ -90,36 +90,16 @@ class assignment_uploadsingle extends assignment_base {
         $this->view_footer();
     }
 
-    function custom_feedbackform($submission, $return=false) {
-        global $CFG, $OUTPUT;
 
-        $mode         = optional_param('mode', '', PARAM_ALPHA);
-        $offset       = optional_param('offset', 0, PARAM_INT);
-
-        $fs = get_file_storage();
-        if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'response', $submission->id, "timemodified", false)) {
-            $str = get_string('editthisfile', 'assignment');
-        } else {
-            $str = get_string('uploadafile', 'assignment');
-        }
-
-        $output = get_string('responsefiles', 'assignment').': ';
-
-        $output .= $OUTPUT->single_button(new moodle_url('/mod/assignment/type/uploadsingle/upload.php',
-                    array('contextid'=>$this->context->id,'id'=>$this->cm->id, 'offset'=>$offset,
-                          'userid'=>$submission->userid, 'mode'=>$mode)), $str, 'get');
-
-        $responsefiles = $this->print_responsefiles($submission->userid, true);
-        if (!empty($responsefiles)) {
-            $output .= $responsefiles;
+    function process_feedback() {
+        if (!$feedback = data_submitted() or !confirm_sesskey()) {      // No incoming data?
+            return false;
         }
-
-        if ($return) {
-            return $output;
+        $userid = required_param('userid', PARAM_INT);
+        $offset = required_param('offset', PARAM_INT);
+        $mform = $this->display_submission($offset, $userid, false);
+        parent::process_feedback($mform);
         }
-        echo $output;
-        return;
-    }
 
     function print_responsefiles($userid, $return=false) {
         global $CFG, $USER, $OUTPUT, $PAGE;
index 01d84d9..83aa186 100644 (file)
@@ -59,22 +59,10 @@ $PAGE->set_heading($title);
 
 $options = array('subdirs'=>0, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
 
-if ($id==null) {
     $mform = new mod_assignment_uploadsingle_form(null, array('contextid'=>$contextid, 'userid'=>$formdata->userid, 'options'=>$options));
-} else {
-    $formdata->cm->id = $id;
-    $formdata->contextid = $contextid;
-    $formdata->options = $options;
-    $mform = new mod_assignment_uploadsingle_response_form(null, $formdata);
-}
 
 if ($mform->is_cancelled()) {
-    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 ($mform->get_data()) {
     $instance->upload($mform);
     die();