Merge branch 'wip-mdl-29689' of git://github.com/rajeshtaneja/moodle

This commit is contained in:
Sam Hemelryk
2012-11-06 10:34:06 +13:00
3 changed files with 95 additions and 149 deletions
+52 -35
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 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 '<table cellspacing="0" class="feedback">';
@@ -329,7 +350,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($feedbackdate).'</div>';
echo '</div>';
echo '</td>';
echo '</tr>';
@@ -337,32 +358,28 @@ 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").': '.$strlonggrade. '</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>';
}
}
if (method_exists($this, 'view_responsefile')) {
$this->view_responsefile($submission);
}
echo '</table>';
return true;
}
/**
+21 -102
View File
@@ -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 '<tr>';
echo '<td class="left side">&nbsp;</td>';
echo '<td class="content">';
echo $this->print_responsefiles($submission->userid);
echo '</td></tr>';
}
// 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;
@@ -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');
@@ -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 '<tr>';
echo '<td class="left side">&nbsp;</td>';
echo '<td class="content">';
echo $this->print_responsefiles($submission->userid);
echo '</td></tr>';
}
}
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;