diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php
index 20e1be1e74c..33ce9bd24b4 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 bool
*/
function view_feedback($submission=NULL) {
global $USER, $CFG, $DB, $OUTPUT, $PAGE;
@@ -290,7 +291,7 @@ 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);
@@ -298,23 +299,43 @@ class assignment_base {
$grade = $item->grades[$userid];
if ($grade->hidden or $grade->grade === false) { // hidden or error
- return;
+ return false;
}
- if ($grade->grade === null and empty($grade->str_feedback)) { /// Nothing to show yet
- return;
+ if ($grade->grade === null and empty($grade->str_feedback)) { // No grade to show yet
+ // If sumbission then check if feedback is avaiable to show else return.
+ if (!$submission) {
+ return false;
+ }
+
+ $fs = get_file_storage();
+ $noresponsefiles = $fs->is_area_empty($this->context->id, 'mod_assignment', 'response', $submission->id);
+ 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');
+ }
+
+ $feedbackdate = $submission->timemarked;
+ $feedback = format_text($submission->submissioncomment, $submission->format);
+ $strlonggrade = '-';
+ }
+ else {
+ // We need the teacher info
+ if (!$teacher = $DB->get_record('user', array('id'=>$grade->usermodified))) {
+ print_error('cannotfindteacher');
+ }
+
+ $feedbackdate = $grade->dategraded;
+ $feedback = $grade->str_feedback;
+ $strlonggrade = $grade->str_long_grade;
}
- $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 +350,7 @@ class assignment_base {
if ($teacher) {
echo ''.fullname($teacher).'
';
}
- echo ''.userdate($graded_date).'
';
+ echo ''.userdate($feedbackdate).'
';
echo '';
echo '';
echo '';
@@ -337,32 +358,28 @@ class assignment_base {
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").': '.$strlonggrade. ' ';
+ 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 ' |
';
-
- 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 $responsefiles;
- echo ' |
';
- }
- }
-
+ if (method_exists($this, 'view_responsefile')) {
+ $this->view_responsefile($submission);
+ }
echo '
';
+
+ return true;
}
/**
diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php
index 4aedca399aa..f636871fcb6 100644
--- a/mod/assignment/type/upload/assignment.class.php
+++ b/mod/assignment/type/upload/assignment.class.php
@@ -64,12 +64,15 @@ class assignment_upload extends assignment_base {
if (is_enrolled($this->context, $USER)) {
if ($submission = $this->get_submission($USER->id)) {
+ if ($submission->timemarked) {
+ $this->view_feedback($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 +103,25 @@ 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) {
+ $fs = get_file_storage();
+ $noresponsefiles = $fs->is_area_empty($this->context->id, 'mod_assignment', 'response', $submission->id);
+ if (!$noresponsefiles) {
+ echo '';
+ echo '| | ';
+ echo '';
+ echo $this->print_responsefiles($submission->userid);
+ 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 $OUTPUT->user_picture($teacher);
- echo ' | ';
- echo '';
- echo '';
- echo ' '.fullname($teacher).' ';
- echo ' '.userdate($graded_date).' ';
- echo ' ';
- echo ' | ';
- 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;
- }
- echo '';
-
- echo '';
- echo ' |
';
-
- echo '';
- echo '| | ';
- echo '';
- echo $this->print_responsefiles($userid, true);
- echo ' |
';
-
- echo '
';
}
-
function view_upload_form() {
global $CFG, $USER, $OUTPUT;
@@ -427,19 +355,10 @@ class assignment_upload extends assignment_base {
}
function print_responsefiles($userid, $return=false) {
- global $CFG, $USER, $OUTPUT, $PAGE;
-
- $mode = optional_param('mode', '', PARAM_ALPHA);
- $offset = optional_param('offset', 0, PARAM_INT);
+ global $OUTPUT, $PAGE;
$output = $OUTPUT->box_start('responsefiles');
- $candelete = $this->can_manage_responsefiles();
- $strdelete = get_string('delete');
-
- $fs = get_file_storage();
- $browser = get_file_browser();
-
if ($submission = $this->get_submission($userid)) {
$renderer = $PAGE->get_renderer('mod_assignment');
$output .= $renderer->assignment_files($this->context, $submission->id, 'response');
diff --git a/mod/assignment/type/uploadsingle/assignment.class.php b/mod/assignment/type/uploadsingle/assignment.class.php
index 54217581150..30536cef788 100644
--- a/mod/assignment/type/uploadsingle/assignment.class.php
+++ b/mod/assignment/type/uploadsingle/assignment.class.php
@@ -78,7 +78,7 @@ 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();
+ $this->view_feedback($submission);
}
if ($filecount) {
echo $OUTPUT->box($this->print_user_files($USER->id, true), 'generalbox boxaligncenter');
@@ -92,6 +92,25 @@ 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) {
+ $fs = get_file_storage();
+ $noresponsefiles = $fs->is_area_empty($this->context->id, 'mod_assignment', 'response', $submission->id);
+ if (!$noresponsefiles) {
+ echo '';
+ echo '| | ';
+ echo '';
+ echo $this->print_responsefiles($submission->userid);
+ echo ' |
';
+ }
+ }
+
function process_feedback($formdata=null) {
if (!$feedback = data_submitted() or !confirm_sesskey()) { // No incoming data?
return false;
@@ -130,24 +149,15 @@ class assignment_uploadsingle extends assignment_base {
}
function print_responsefiles($userid, $return=false) {
- global $CFG, $USER, $OUTPUT, $PAGE;
-
- $mode = optional_param('mode', '', PARAM_ALPHA);
- $offset = optional_param('offset', 0, PARAM_INT);
+ global $OUTPUT, $PAGE;
$output = $OUTPUT->box_start('responsefiles');
- $candelete = $this->can_manage_responsefiles();
- $strdelete = get_string('delete');
-
- $fs = get_file_storage();
- $browser = get_file_browser();
-
if ($submission = $this->get_submission($userid)) {
$renderer = $PAGE->get_renderer('mod_assignment');
$output .= $renderer->assignment_files($this->context, $submission->id, 'response');
- $output .= $OUTPUT->box_end();
}
+ $output .= $OUTPUT->box_end();
if ($return) {
return $output;