From 7f40888801ad1df80da82c19168d5759e8c6c1c7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Gaudreau Date: Tue, 31 Jan 2012 12:16:35 -0500 Subject: [PATCH] Fixing feedback's view when assignment is set to no grade. Also refactoring the use of method view_feedback for upload (single and advenced) assignments Conflicts: mod/assignment/type/upload/assignment.class.php mod/assignment/type/uploadsingle/assignment.class.php --- mod/assignment/lib.php | 85 +++++++------ .../type/upload/assignment.class.php | 115 ++++-------------- .../type/uploadsingle/assignment.class.php | 24 +++- 3 files changed, 94 insertions(+), 130 deletions(-) diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 20e1be1e74c..2dd715e4508 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -269,6 +269,7 @@ class assignment_base { * @global object * @global object * @param object $submission The submission object or NULL in which case it will be loaded + * @return boolean */ function view_feedback($submission=NULL) { global $USER, $CFG, $DB, $OUTPUT, $PAGE; @@ -290,31 +291,47 @@ class assignment_base { if (!$canviewfeedback) { // can not view or submit assignments -> no feedback - return; + return false; } $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid); $item = $grading_info->items[0]; $grade = $item->grades[$userid]; - if ($grade->hidden or $grade->grade === false) { // hidden or error - return; + $fs = get_file_storage(); + $noresponsefiles = $fs->is_area_empty($this->context->id, 'mod_assignment', 'response', $submission->id); + + if ($grade->grade === null ) { // No grade to show yet + if (empty($submission->submissioncomment) && $noresponsefiles) { // Nothing to show yet + return false; + } + + // We need the teacher info + if (!$teacher = $DB->get_record('user', array('id'=>$submission->teacher))) { + print_error('cannotfindteacher'); + } + + $feedback_date = $submission->timemarked; + $feedback = $submission->submissioncomment; + $str_long_grade = '-'; + } + else { + if ($grade->hidden or $grade->grade === false) { // hidden or error + return false; + } + + // We need the teacher info + if (!$teacher = $DB->get_record('user', array('id'=>$grade->usermodified))) { + print_error('cannotfindteacher'); + } + + $feedback_date = $grade->dategraded; + $feedback = $grade->str_feedback; + $str_long_grade = $grade->str_long_grade; } - if ($grade->grade === null and empty($grade->str_feedback)) { /// Nothing to show yet - return; - } - - $graded_date = $grade->dategraded; - $graded_by = $grade->usermodified; - - /// We need the teacher info - if (!$teacher = $DB->get_record('user', array('id'=>$graded_by))) { - print_error('cannotfindteacher'); - } - - /// Print the feedback - echo $OUTPUT->heading(get_string('feedbackfromteacher', 'assignment', fullname($teacher))); + // Print the feedback + echo $OUTPUT->heading(get_string('submissionfeedback', 'assignment'), 3); echo ''; @@ -329,7 +346,7 @@ class assignment_base { if ($teacher) { echo '
'.fullname($teacher).'
'; } - echo '
'.userdate($graded_date).'
'; + echo '
'.userdate($feedback_date).'
'; echo ''; echo ''; echo ''; @@ -337,32 +354,26 @@ class assignment_base { echo ''; echo ''; echo ''; - if ($this->type == 'uploadsingle') { //@TODO: move to overload view_feedback method in the class or is uploadsingle merging into upload? - $responsefiles = $this->print_responsefiles($submission->userid, true); - if (!empty($responsefiles)) { - echo ''; - echo ''; - echo ''; - } - } - echo '
 '; - $gradestr = '
'. get_string("grade").': '.$grade->str_long_grade. '
'; - if (!empty($submission) && $controller = get_grading_manager($this->context, 'mod_assignment', 'submission')->get_active_controller()) { - $controller->set_grade_range(make_grades_menu($this->assignment->grade)); - echo $controller->render_grade($PAGE, $submission->id, $item, $gradestr, has_capability('mod/assignment:grade', $this->context)); - } else { - echo $gradestr; + + if ($this->assignment->grade) { + $gradestr = '
'. get_string("grade").': '.$str_long_grade. '
'; + if (!empty($submission) && $controller = get_grading_manager($this->context, 'mod_assignment', 'submission')->get_active_controller()) { + $controller->set_grade_range(make_grades_menu($this->assignment->grade)); + echo $controller->render_grade($PAGE, $submission->id, $item, $gradestr, has_capability('mod/assignment:grade', $this->context)); + } else { + echo $gradestr; + } + echo '
'; } - echo '
'; echo '
'; - echo $grade->str_feedback; + echo $feedback; echo '
'; echo '
 '; - echo $responsefiles; - echo '
'; + + return true; } /** diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php index 5f76748053f..85a9633313e 100644 --- a/mod/assignment/type/upload/assignment.class.php +++ b/mod/assignment/type/upload/assignment.class.php @@ -64,12 +64,17 @@ class assignment_upload extends assignment_base { if (is_enrolled($this->context, $USER)) { if ($submission = $this->get_submission($USER->id)) { + if ($submission->timemarked) { + if($this->view_feedback($submission)) { + $this->view_responsefile($submission); + } + } + $filecount = $this->count_user_files($submission->id); } else { $filecount = 0; } if ($cansubmit or !empty($filecount)) { //if a user has submitted files using a previous role we should still show the files - $this->view_feedback(); if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) { echo $OUTPUT->heading(get_string('submission', 'assignment'), 3); @@ -100,100 +105,26 @@ class assignment_upload extends assignment_base { $this->view_footer(); } - - function view_feedback($submission=NULL) { - global $USER, $CFG, $DB, $OUTPUT, $PAGE; - require_once($CFG->libdir.'/gradelib.php'); - require_once("$CFG->dirroot/grade/grading/lib.php"); - - if (!$submission) { /// Get submission for this assignment - $userid = $USER->id; - $submission = $this->get_submission($userid); - } else { - $userid = $submission->userid; + /** + * Display the response file to the student + * + * This default method prints the response file + * + * @param object $submission The submission object + */ + function view_responsefile($submission) { + $responsefiles = $this->print_responsefiles($submission->userid, true); + if (!empty($responsefiles)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo '
 '; + echo $responsefiles; + echo '
'; } - - // Check the user can submit - $canviewfeedback = ($userid == $USER->id && has_capability('mod/assignment:submit', $this->context, $USER->id, false)); - // If not then check if the user still has the view cap and has a previous submission - $canviewfeedback = $canviewfeedback || (!empty($submission) && $submission->userid == $USER->id && has_capability('mod/assignment:view', $this->context)); - // Or if user can grade (is a teacher or admin) - $canviewfeedback = $canviewfeedback || has_capability('mod/assignment:grade', $this->context); - - if (!$canviewfeedback) { - // can not view or submit assignments -> no feedback - return; - } - - $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid); - $item = $grading_info->items[0]; - $grade = $item->grades[$userid]; - - if ($grade->hidden or $grade->grade === false) { // hidden or error - return; - } - - if ($grade->grade === null and empty($grade->str_feedback)) { // No grade to show yet - if ($this->count_responsefiles($userid)) { // but possibly response files are present - echo $OUTPUT->heading(get_string('responsefiles', 'assignment'), 3); - $responsefiles = $this->print_responsefiles($userid, true); - echo $OUTPUT->box($responsefiles, 'generalbox boxaligncenter'); - } - return; - } - - $graded_date = $grade->dategraded; - $graded_by = $grade->usermodified; - - /// We need the teacher info - if (!$teacher = $DB->get_record('user', array('id'=>$graded_by))) { - print_error('cannotfindteacher'); - } - - /// Print the feedback - echo $OUTPUT->heading(get_string('submissionfeedback', 'assignment'), 3); - - echo ''; - - echo ''; - echo ''; - echo ''; - echo ''; - - echo ''; - echo ''; - echo ''; - - echo ''; - echo ''; - echo ''; - - echo '
'; - echo $OUTPUT->user_picture($teacher); - echo ''; - echo '
'; - echo '
'.fullname($teacher).'
'; - echo '
'.userdate($graded_date).'
'; - echo '
'; - echo '
 '; - $gradestr = '
'. get_string("grade").': '.$grade->str_long_grade. '
'; - if (!empty($submission) && $controller = get_grading_manager($this->context, 'mod_assignment', 'submission')->get_active_controller()) { - $controller->set_grade_range(make_grades_menu($this->assignment->grade)); - echo $controller->render_grade($PAGE, $submission->id, $item, $gradestr, has_capability('mod/assignment:grade', $this->context)); - } else { - echo $gradestr; - } - echo '
'; - - echo '
'; - echo $grade->str_feedback; - echo '
'; - echo '
 '; - echo $this->print_responsefiles($userid, true); - echo '
'; } - function view_upload_form() { global $CFG, $USER, $OUTPUT; diff --git a/mod/assignment/type/uploadsingle/assignment.class.php b/mod/assignment/type/uploadsingle/assignment.class.php index 54217581150..4332c3475bc 100644 --- a/mod/assignment/type/uploadsingle/assignment.class.php +++ b/mod/assignment/type/uploadsingle/assignment.class.php @@ -78,7 +78,9 @@ class assignment_uploadsingle extends assignment_base { if ($submission = $this->get_submission($USER->id)) { $filecount = $this->count_user_files($submission->id); if ($submission->timemarked) { - $this->view_feedback(); + if($this->view_feedback($submission)) { + $this->view_responsefile($submission); + } } if ($filecount) { echo $OUTPUT->box($this->print_user_files($USER->id, true), 'generalbox boxaligncenter'); @@ -92,6 +94,26 @@ class assignment_uploadsingle extends assignment_base { $this->view_footer(); } + /** + * Display the response file to the student + * + * This default method prints the response file + * + * @param object $submission The submission object + */ + function view_responsefile($submission) { + $responsefiles = $this->print_responsefiles($submission->userid, true); + if (!empty($responsefiles)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo '
 '; + echo $responsefiles; + echo '
'; + } + } + function process_feedback($formdata=null) { if (!$feedback = data_submitted() or !confirm_sesskey()) { // No incoming data? return false;