Merge branch 'MDL-48235-assign-reopen-until-pass' of git://github.com/mpetrowi/moodle
authorDavid Monllao <davidm@moodle.com>
Mon, 15 Dec 2014 09:30:40 +0000 (17:30 +0800)
committerDavid Monllao <davidm@moodle.com>
Mon, 15 Dec 2014 09:30:40 +0000 (17:30 +0800)
1  2 
mod/assign/locallib.php

diff --combined mod/assign/locallib.php
@@@ -1882,20 -1882,14 +1882,14 @@@ class assign 
              // Set it to the default.
              $grade->attemptnumber = 0;
          }
-         $result = $DB->update_record('assign_grades', $grade);
+         $DB->update_record('assign_grades', $grade);
  
-         // If the conditions are met, allow another attempt.
          $submission = null;
          if ($this->get_instance()->teamsubmission) {
              $submission = $this->get_group_submission($grade->userid, 0, false);
          } else {
              $submission = $this->get_user_submission($grade->userid, false);
          }
-         if ($submission && $submission->attemptnumber == $grade->attemptnumber) {
-             $this->reopen_submission_if_required($grade->userid,
-                                                  $submission,
-                                                  $reopenattempt);
-         }
  
          // Only push to gradebook if the update is for the latest attempt.
          // Not the latest attempt.
              return true;
          }
  
-         if ($result) {
-             $this->gradebook_item_update(null, $grade);
-             \mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger();
+         $this->gradebook_item_update(null, $grade);
+         // If the conditions are met, allow another attempt.
+         if ($submission) {
+             $this->reopen_submission_if_required($grade->userid,
+                     $submission,
+                     $reopenattempt);
          }
-         return $result;
+         \mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger();
+         return true;
      }
  
      /**
       *
       * @param int $groupid The id of the group whose members we want or 0 for the default group
       * @param bool $onlyids Whether to retrieve only the user id's
 +     * @param bool $excludesuspended Whether to exclude suspended users
       * @return array The users (possibly id's only)
       */
 -    public function get_submission_group_members($groupid, $onlyids) {
 +    public function get_submission_group_members($groupid, $onlyids, $excludesuspended = false) {
          $members = array();
          if ($groupid != 0) {
              if ($onlyids) {
              }
          }
          // Exclude suspended users, if user can't see them.
 -        if (!has_capability('moodle/course:viewsuspendedusers', $this->context)) {
 +        if ($excludesuspended || !has_capability('moodle/course:viewsuspendedusers', $this->context)) {
              foreach ($members as $key => $member) {
                  if (!$this->is_active_user($member->id)) {
                      unset($members[$key]);
              if ($gradeitem) {
                  $gradegrade = grade_grade::fetch(array('userid' => $userid, 'itemid' => $gradeitem->id));
  
-                 if ($gradegrade && !$gradegrade->is_passed()) {
+                 // Do not reopen if is_passed returns null, e.g. if there is no pass criterion set.
+                 if ($gradegrade && ($gradegrade->is_passed() === false)) {
                      $shouldreopen = true;
                  }
              }
                      $groupid = $group->id;
                  }
              }
 -            $members = $this->get_submission_group_members($groupid, true);
 +            $members = $this->get_submission_group_members($groupid, true, $this->show_only_active_users());
              foreach ($members as $member) {
                  // User may exist in multple groups (which should put them in the default group).
                  $this->apply_grade_to_user($data, $member->id, $data->attemptnumber);