Merge branch 'MDL-69297-39' of git://github.com/peterRd/moodle into MOODLE_39_STABLE
authorVictor Deniz Falcon <victor@moodle.com>
Wed, 19 Aug 2020 22:45:32 +0000 (23:45 +0100)
committerVictor Deniz Falcon <victor@moodle.com>
Wed, 19 Aug 2020 22:45:32 +0000 (23:45 +0100)
1  2 
mod/assign/locallib.php

diff --combined mod/assign/locallib.php
@@@ -5129,18 -5129,33 +5129,33 @@@ class assign 
          require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
  
          // Check that all of the submission plugins are ready for this submission.
+         // Also check whether there is something to be submitted as well against atleast one.
          $notifications = array();
          $submission = $this->get_user_submission($USER->id, false);
+         if ($this->get_instance()->teamsubmission) {
+             $submission = $this->get_group_submission($USER->id, 0, false);
+         }
          $plugins = $this->get_submission_plugins();
+         $hassubmission = false;
          foreach ($plugins as $plugin) {
              if ($plugin->is_enabled() && $plugin->is_visible()) {
                  $check = $plugin->precheck_submission($submission);
                  if ($check !== true) {
                      $notifications[] = $check;
                  }
+                 if (is_object($submission) && !$plugin->is_empty($submission)) {
+                     $hassubmission = true;
+                 }
              }
          }
  
+         // If there are no submissions and no existing notifications to be displayed the stop.
+         if (!$hassubmission && !$notifications) {
+             $notifications[] = get_string('addsubmission_help', 'assign');
+         }
          $data = new stdClass();
          $adminconfig = $this->get_admin_config();
          $requiresubmissionstatement = $this->get_instance()->requiresubmissionstatement;
                      $gradefordisplay = $this->display_grade($gradebookgrade->grade, false);
                  }
                  $gradeddate = $gradebookgrade->dategraded;
 -                if (isset($grade->grader) && $grade->grader > 0) {
 -                    $grader = $DB->get_record('user', array('id' => $grade->grader));
 -                } else if (isset($gradebookgrade->usermodified) && $gradebookgrade->usermodified > 0) {
 -                    $grader = $DB->get_record('user', array('id' => $gradebookgrade->usermodified));
 +
 +                // Only display the grader if it is in the right state.
 +                if (in_array($gradingstatus, [ASSIGN_GRADING_STATUS_GRADED, ASSIGN_MARKING_WORKFLOW_STATE_RELEASED])){
 +                    if (isset($grade->grader) && $grade->grader > 0) {
 +                        $grader = $DB->get_record('user', array('id' => $grade->grader));
 +                    } else if (isset($gradebookgrade->usermodified)
 +                        && $gradebookgrade->usermodified > 0
 +                        && has_capability('mod/assign:grade', $this->get_context(), $gradebookgrade->usermodified)) {
 +                        // Grader not provided. Check that usermodified is a user who can grade.
 +                        // Case 1: When an assignment is reopened an empty assign_grade is created so the feedback
 +                        // plugin can know which attempt it's referring to. In this case, usermodifed is a student.
 +                        // Case 2: When an assignment's grade is overrided via the gradebook, usermodified is a grader
 +                        $grader = $DB->get_record('user', array('id' => $gradebookgrade->usermodified));
 +                    }
                  }
              }