Skip to content

Commit

Permalink
MDL-72097 mod_assign: pass gradinginfo to disabled check.
Browse files Browse the repository at this point in the history
  • Loading branch information
danmarsden authored and ilyatregubov committed Aug 19, 2021
1 parent 036800d commit 8aba9d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions mod/assign/gradingtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ public function get_rows_per_page() {
public function col_workflowstatus(stdClass $row) {
$o = '';

$gradingdisabled = $this->assignment->grading_disabled($row->id);
$gradingdisabled = $this->assignment->grading_disabled($row->id, true, $this->gradinginfo);
// The function in the assignment keeps a static cache of this list of states.
$workflowstates = $this->assignment->get_marking_workflow_states_for_current_user();
$workflowstate = $row->workflowstate;
Expand Down Expand Up @@ -946,7 +946,7 @@ private function get_gradebook_data_for_user($userid) {
* @return string
*/
public function col_gradecanbechanged(stdClass $row) {
$gradingdisabled = $this->assignment->grading_disabled($row->id);
$gradingdisabled = $this->assignment->grading_disabled($row->id, true, $this->gradinginfo);
if ($gradingdisabled) {
return get_string('no');
} else {
Expand Down Expand Up @@ -981,7 +981,7 @@ public function col_grade(stdClass $row) {
$link = '';
$separator = $this->output->spacer(array(), true);
$grade = '';
$gradingdisabled = $this->assignment->grading_disabled($row->id);
$gradingdisabled = $this->assignment->grading_disabled($row->id, true, $this->gradinginfo);

if (!$this->is_downloading() && $this->hasgrade) {
$urlparams = array('id' => $this->assignment->get_course_module()->id,
Expand Down
18 changes: 11 additions & 7 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -7585,22 +7585,26 @@ protected function process_save_submission(&$mform, &$notices) {
*
* @param int $userid - The student userid
* @param bool $checkworkflow - whether to include a check for the workflow state.
* @param stdClass $gradinginfo - optional, allow gradinginfo to be passed for performance.
* @return bool $gradingdisabled
*/
public function grading_disabled($userid, $checkworkflow=true) {
global $CFG;
public function grading_disabled($userid, $checkworkflow = true, $gradinginfo = null) {
if ($checkworkflow && $this->get_instance()->markingworkflow) {
$grade = $this->get_user_grade($userid, false);
$validstates = $this->get_marking_workflow_states_for_current_user();
if (!empty($grade) && !empty($grade->workflowstate) && !array_key_exists($grade->workflowstate, $validstates)) {
return true;
}
}
$gradinginfo = grade_get_grades($this->get_course()->id,
'mod',
'assign',
$this->get_instance()->id,
array($userid));

if (is_null($gradinginfo)) {
$gradinginfo = grade_get_grades($this->get_course()->id,
'mod',
'assign',
$this->get_instance()->id,
array($userid));
}

if (!$gradinginfo) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions mod/assign/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
This files describes API changes in the assign code.
=== 4.0 ===
* The method \assign::grading_disabled() now has optional $gradinginfo parameter to improve performance

=== 3.9 ===

Expand Down

0 comments on commit 8aba9d1

Please sign in to comment.