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
This commit is contained in:
Jean-Philippe Gaudreau
2012-10-03 14:41:32 +08:00
committed by Rajesh Taneja
parent 5d6285c220
commit 7f40888801
3 changed files with 94 additions and 130 deletions
+48 -37
View File
@@ -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 '<table cellspacing="0" class="feedback">';
@@ -329,7 +346,7 @@ class assignment_base {
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>';
@@ -337,32 +354,26 @@ class assignment_base {
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;
}
/**
+23 -92
View File
@@ -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 '<table cellspacing="0" class="feedback">';
echo '<tr>';
echo '<td class="left side">&nbsp;</td>';
echo '<td class="content">';
echo $responsefiles;
echo '</tr>';
echo '</table>';
}
// 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;
}
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;
@@ -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 '<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;