diff -Naur old/lib.php new/lib.php --- old/lib.php 2012-01-30 12:29:42.000000000 +0530 +++ new/lib.php 2012-03-26 10:40:43.000000000 +0530 @@ -54,8 +54,6 @@ var $cm; /** @var object */ var $course; - /** @var stdClass */ - var $coursecontext; /** @var object */ var $assignment; /** @var string */ @@ -121,8 +119,6 @@ } else if (! $this->course = $DB->get_record('course', array('id'=>$this->cm->course))) { print_error('invalidid', 'assignment'); } - $this->coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id); - $courseshortname = format_text($this->course->shortname, true, array('context' => $this->coursecontext)); if ($assignment) { $this->assignment = $assignment; @@ -137,7 +133,7 @@ $this->strassignments = get_string('modulenameplural', 'assignment'); $this->strsubmissions = get_string('submissions', 'assignment'); $this->strlastmodified = get_string('lastmodified'); - $this->pagetitle = strip_tags($courseshortname.': '.$this->strassignment.': '.format_string($this->assignment->name, true, array('context' => $this->context))); + $this->pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment.': '.format_string($this->assignment->name,true)); // visibility handled by require_login() with $cm parameter // get current group only when really needed @@ -257,8 +253,6 @@ * * This default method prints the teacher picture and name, date when marked, * grade and teacher submissioncomment. - * If advanced grading is used the method render_grade from the - * advanced grading controller is called to display the grade. * * @global object * @global object @@ -266,31 +260,30 @@ * @param object $submission The submission object or NULL in which case it will be loaded */ function view_feedback($submission=NULL) { - global $USER, $CFG, $DB, $OUTPUT, $PAGE; + global $USER, $CFG, $DB, $OUTPUT; require_once($CFG->libdir.'/gradelib.php'); - require_once("$CFG->dirroot/grade/grading/lib.php"); + + if (!is_enrolled($this->context, $USER, 'mod/assignment:view')) { + // can not submit assignments -> no feedback + return; + } if (!$submission) { /// Get submission for this assignment - $userid = $USER->id; - $submission = $this->get_submission($userid); - } else { - $userid = $submission->userid; + $submission = $this->get_submission($USER->id); } // Check the user can submit - $canviewfeedback = ($userid == $USER->id && has_capability('mod/assignment:submit', $this->context, $USER->id, false)); + $cansubmit = 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); + $cansubmit = $cansubmit || (!empty($submission) && has_capability('mod/assignment:view', $this->context, $USER->id, false)); - if (!$canviewfeedback) { - // can not view or submit assignments -> no feedback + if (!$cansubmit) { + // can not submit assignments -> no feedback return; } - $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid); + $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $USER->id); $item = $grading_info->items[0]; - $grade = $item->grades[$userid]; + $grade = $item->grades[$USER->id]; if ($grade->hidden or $grade->grade === false) { // hidden or error return; @@ -332,13 +325,9 @@ 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 get_string("grade").': '.$grade->str_long_grade; + echo '
'; echo '
'; echo '
'; @@ -627,7 +616,7 @@ if (is_null($mailinfo)) { if (optional_param('sesskey', null, PARAM_BOOL)) { - set_user_preference('assignment_mailinfo', 0); + set_user_preference('assignment_mailinfo', $mailinfo); } else { $mailinfo = get_user_preferences('assignment_mailinfo', 0); } @@ -635,12 +624,6 @@ set_user_preference('assignment_mailinfo', $mailinfo); } - if (!($this->validate_and_preprocess_feedback())) { - // form was submitted ('Save' or 'Save and next' was pressed, but validation failed) - $this->display_submission(); - return; - } - switch ($mode) { case 'grade': // We are in a main window grading if ($submission = $this->process_feedback()) { @@ -671,8 +654,8 @@ $col = 'submissioncomment'; $commenting = true; } - if (isset($_POST['menu'])) { - $col = 'menu'; + if (isset($_POST['mmenu'])) { + $col = 'mmenu'; $grading = true; } if (!$col) { @@ -700,7 +683,7 @@ $updatedb = false; if ($grading) { - $grade = $_POST['menu'][$id]; + $grade = $_POST['mmenu'][$id]; $updatedb = $updatedb || ($submission->grade != $grade); $submission->grade = $grade; } else { @@ -769,16 +752,9 @@ $offset = required_param('offset', PARAM_INT); $nextid = required_param('nextid', PARAM_INT); $id = required_param('id', PARAM_INT); - $filter = optional_param('filter', self::FILTER_ALL, PARAM_INT); - - if ($mode == 'next' || $filter !== self::FILTER_REQUIRE_GRADING) { - $offset = (int)$offset+1; - } - $redirect = new moodle_url('submissions.php', - array('id' => $id, 'offset' => $offset, 'userid' => $nextid, - 'mode' => 'single', 'filter' => $filter)); - - redirect($redirect); + $offset = (int)$offset+1; + //$this->display_submission($offset+1 , $nextid); + redirect('submissions.php?id='.$id.'&userid='. $nextid . '&mode=single&offset='.$offset); break; case 'singlenosave': @@ -792,23 +768,6 @@ } /** - * Checks if grading method allows quickgrade mode. At the moment it is hardcoded - * that advanced grading methods do not allow quickgrade. - * - * Assignment type plugins are not allowed to override this method - * - * @return boolean - */ - public final function quickgrade_mode_allowed() { - global $CFG; - require_once("$CFG->dirroot/grade/grading/lib.php"); - if ($controller = get_grading_manager($this->context, 'mod_assignment', 'submission')->get_active_controller()) { - return false; - } - return true; - } - - /** * Helper method updating the listing on the main script from popup using javascript * * @global object @@ -822,11 +781,11 @@ $perpage = get_user_preferences('assignment_perpage', 10); - $quickgrade = get_user_preferences('assignment_quickgrade', 0) && $this->quickgrade_mode_allowed(); + $quickgrade = get_user_preferences('assignment_quickgrade', 0); /// Run some Javascript to try and update the parent page $output .= '