/** * Print the grading page for a single user submission. * * @param array $args Optional args array (better than pulling args from _GET and _POST) * @return string */ protected function view_single_grading_panel($args) { global $DB, $CFG, $SESSION, $PAGE; $o = ''; $instance = $this->get_instance(); require_once($CFG->dirroot . '/mod/assign/gradeform.php'); // Need submit permission to submit an assignment. require_capability('mod/assign:grade', $this->context); // If userid is passed - we are only grading a single student. $userid = $args['userid']; $attemptnumber = $args['attemptnumber']; // Apply overrides. $this->update_effective_access($userid); $rownum = 0; $useridlist = array($userid); $last = true; // This variation on the url will link direct to this student, with no next/previous links. // The benefit is the url will be the same every time for this student, so Atto autosave drafts can match up. $returnparams = array('userid' => $userid, 'rownum' => 0, 'useridlistid' => 0); $this->register_return_link('grade', $returnparams); $user = $DB->get_record('user', array('id' => $userid)); $submission = $this->get_user_submission($userid, false, $attemptnumber); $submissiongroup = null; $teamsubmission = null; $notsubmitted = array(); if ($instance->teamsubmission) { $teamsubmission = $this->get_group_submission($userid, 0, false, $attemptnumber); $submissiongroup = $this->get_submission_group($userid); $groupid = 0; if ($submissiongroup) { $groupid = $submissiongroup->id; } $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false); } // Get the requested grade. $grade = $this->get_user_grade($userid, false, $attemptnumber); $flags = $this->get_user_flags($userid, false); if ($this->can_view_submission($userid)) { $gradelocked = ($flags && $flags->locked) || $this->grading_disabled($userid); $extensionduedate = null; if ($flags) { $extensionduedate = $flags->extensionduedate; } $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled()); $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context()); $usergroups = $this->get_all_groups($user->id); $submissionstatus = new assign_submission_status_compact($instance->allowsubmissionsfromdate, $instance->alwaysshowdescription, $submission, $instance->teamsubmission, $teamsubmission, $submissiongroup, $notsubmitted, $this->is_any_submission_plugin_enabled(), $gradelocked, $this->is_graded($userid), $instance->duedate, $instance->cutoffdate, $this->get_submission_plugins(), $this->get_return_action(), $this->get_return_params(), $this->get_course_module()->id, $this->get_course()->id, assign_submission_status::GRADER_VIEW, $showedit, false, $viewfullnames, $extensionduedate, $this->get_context(), $this->is_blind_marking(), '', $instance->attemptreopenmethod, $instance->maxattempts, $this->get_grading_status($userid), $instance->preventsubmissionnotingroup, $usergroups); $o .= $this->get_renderer()->render($submissionstatus); } if ($grade) { $data = new stdClass(); if ($grade->grade !== null && $grade->grade >= 0) { $data->grade = format_float($grade->grade, $this->get_grade_item()->get_decimals()); } } else { $data = new stdClass(); $data->grade = ''; } if (!empty($flags->workflowstate)) { $data->workflowstate = $flags->workflowstate; } if (!empty($flags->allocatedmarker)) { $data->allocatedmarker = $flags->allocatedmarker; } // Warning if required. $allsubmissions = $this->get_all_submissions($userid); if ($attemptnumber != -1 && ($attemptnumber + 1) != count($allsubmissions)) { $params = array('attemptnumber' => $attemptnumber + 1, 'totalattempts' => count($allsubmissions)); $message = get_string('editingpreviousfeedbackwarning', 'assign', $params); $o .= $this->get_renderer()->notification($message); } $pagination = array('rownum' => $rownum, 'useridlistid' => 0, 'last' => $last, 'userid' => $userid, 'attemptnumber' => $attemptnumber, 'gradingpanel' => true); if (!empty($args['formdata'])) { $data = (array) $data; $data = (object) array_merge($data, $args['formdata']); } $formparams = array($this, $data, $pagination); $mform = new mod_assign_grade_form(null, $formparams, 'post', '', array('class' => 'gradeform')); if (!empty($args['formdata'])) { // If we were passed form data - we want the form to check the data // and show errors. $mform->is_validated(); } $o .= $this->get_renderer()->heading(get_string('grade'), 3); $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform)); if (count($allsubmissions) > 1) { $allgrades = $this->get_all_grades($userid); $history = new assign_attempt_history_chooser($allsubmissions, $allgrades, $this->get_course_module()->id, $userid); $o .= $this->get_renderer()->render($history); } \mod_assign\event\grading_form_viewed::create_from_user($this, $user)->trigger(); return $o; }