Browse files

Fixing feedback's view when assignment is set to no grade. Also refac…

…toring 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
  • Loading branch information...
1 parent 5d6285c commit 7f40888801ad1df80da82c19168d5759e8c6c1c7 @gaudreaj gaudreaj committed with rajeshtaneja Jan 31, 2012
View
77 mod/assignment/lib.php
@@ -269,6 +269,7 @@ function view_footer() {
* @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 @@ function view_feedback($submission=NULL) {
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 and empty($grade->str_feedback)) { /// Nothing to show yet
- return;
+ 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;
+ }
- $graded_date = $grade->dategraded;
- $graded_by = $grade->usermodified;
+ // We need the teacher info
+ if (!$teacher = $DB->get_record('user', array('id'=>$grade->usermodified))) {
+ print_error('cannotfindteacher');
+ }
- /// We need the teacher info
- if (!$teacher = $DB->get_record('user', array('id'=>$graded_by))) {
- print_error('cannotfindteacher');
+ $feedback_date = $grade->dategraded;
+ $feedback = $grade->str_feedback;
+ $str_long_grade = $grade->str_long_grade;
}
- /// Print the feedback
- echo $OUTPUT->heading(get_string('feedbackfromteacher', 'assignment', fullname($teacher)));
+ // Print the feedback
+ echo $OUTPUT->heading(get_string('submissionfeedback', 'assignment'), 3);
echo '<table cellspacing="0" class="feedback">';
@@ -329,40 +346,34 @@ function view_feedback($submission=NULL) {
if ($teacher) {
echo '<div class="fullname">'.fullname($teacher).'</div>';
}
- echo '<div class="time">'.userdate($graded_date).'</div>';
+ echo '<div class="time">'.userdate($feedback_date).'</div>';
echo '</div>';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="left side">&nbsp;</td>';
echo '<td class="content">';
- $gradestr = '<div class="grade">'. get_string("grade").': '.$grade->str_long_grade. '</div>';
- 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 = '<div class="grade">'. get_string("grade").': '.$str_long_grade. '</div>';
+ 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 '<div class="clearer"></div>';
}
- echo '<div class="clearer"></div>';
echo '<div class="comment">';
- echo $grade->str_feedback;
+ echo $feedback;
echo '</div>';
echo '</tr>';
- 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 '<tr>';
- echo '<td class="left side">&nbsp;</td>';
- echo '<td class="content">';
- echo $responsefiles;
- echo '</tr>';
- }
- }
-
echo '</table>';
+
+ return true;
}
/**
View
115 mod/assignment/type/upload/assignment.class.php
@@ -64,12 +64,17 @@ function view() {
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 @@ function view() {
$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;
- }
-
- // 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 '<table cellspacing="0" class="feedback">';
-
- echo '<tr>';
- echo '<td class="left picture">';
- echo $OUTPUT->user_picture($teacher);
- echo '</td>';
- echo '<td class="topic">';
- echo '<div class="from">';
- echo '<div class="fullname">'.fullname($teacher).'</div>';
- echo '<div class="time">'.userdate($graded_date).'</div>';
- echo '</div>';
- echo '</td>';
- echo '</tr>';
-
- echo '<tr>';
- echo '<td class="left side">&nbsp;</td>';
- echo '<td class="content">';
- $gradestr = '<div class="grade">'. get_string("grade").': '.$grade->str_long_grade. '</div>';
- 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;
+ /**
+ * 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 '<table cellspacing="0" class="feedback">';
+ echo '<tr>';
+ echo '<td class="left side">&nbsp;</td>';
+ echo '<td class="content">';
+ echo $responsefiles;
+ echo '</tr>';
+ echo '</table>';
}
- echo '<div class="clearer"></div>';
-
- echo '<div class="comment">';
- echo $grade->str_feedback;
- echo '</div>';
- echo '</tr>';
-
- echo '<tr>';
- echo '<td class="left side">&nbsp;</td>';
- echo '<td class="content">';
- echo $this->print_responsefiles($userid, true);
- echo '</tr>';
-
- echo '</table>';
}
-
function view_upload_form() {
global $CFG, $USER, $OUTPUT;
View
24 mod/assignment/type/uploadsingle/assignment.class.php
@@ -78,7 +78,9 @@ function view() {
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 @@ function view() {
$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 '<table cellspacing="0" class="feedback">';
+ echo '<tr>';
+ echo '<td class="left side">&nbsp;</td>';
+ echo '<td class="content">';
+ echo $responsefiles;
+ echo '</tr>';
+ echo '</table>';
+ }
+ }
+
function process_feedback($formdata=null) {
if (!$feedback = data_submitted() or !confirm_sesskey()) { // No incoming data?
return false;

0 comments on commit 7f40888

Please sign in to comment.