Merge branch 'wip-MDL-52566-master' of https://github.com/cdsmith-umn/moodle
authorDavid Monllao <davidm@moodle.com>
Mon, 15 Feb 2016 07:17:13 +0000 (15:17 +0800)
committerDavid Monllao <davidm@moodle.com>
Mon, 15 Feb 2016 07:17:13 +0000 (15:17 +0800)
1  2 
mod/assign/locallib.php

diff --combined mod/assign/locallib.php
@@@ -5399,7 -5399,6 +5399,7 @@@ class assign 
          // Gets a list of possible users and look for values based upon that.
          foreach ($participants as $userid => $unused) {
              $modified = optional_param('grademodified_' . $userid, -1, PARAM_INT);
 +            $attemptnumber = optional_param('gradeattempt_' . $userid, -1, PARAM_INT);
              // Gather the userid, updated grade and last modified value.
              $record = new stdClass();
              $record->userid = $userid;
                  // This user was not in the grading table.
                  continue;
              }
 +            $record->attemptnumber = $attemptnumber;
              $record->lastmodified = $modified;
              $record->gradinginfo = grade_get_grades($this->get_course()->id,
                                                      'mod',
          $params['assignid2'] = $this->get_instance()->id;
  
          // Check them all for currency.
 -        $grademaxattempt = 'SELECT mxg.userid, MAX(mxg.attemptnumber) AS maxattempt
 -                            FROM {assign_grades} mxg
 -                            WHERE mxg.assignment = :assignid1 GROUP BY mxg.userid';
 -
 -        $sql = 'SELECT u.id as userid, g.grade as grade, g.timemodified as lastmodified, uf.workflowstate, uf.allocatedmarker
 -                    FROM {user} u
 -                LEFT JOIN ( ' . $grademaxattempt . ' ) gmx ON u.id = gmx.userid
 -                LEFT JOIN {assign_grades} g ON
 -                    u.id = g.userid AND
 -                    g.assignment = :assignid2 AND
 -                    g.attemptnumber = gmx.maxattempt
 -                LEFT JOIN {assign_user_flags} uf ON uf.assignment = g.assignment AND uf.userid = g.userid
 -                WHERE u.id ' . $userids;
 +        $grademaxattempt = 'SELECT s.userid, s.attemptnumber AS maxattempt
 +                              FROM {assign_submission} s
 +                             WHERE s.assignment = :assignid1 AND s.latest = 1';
 +
 +        $sql = 'SELECT u.id AS userid, g.grade AS grade, g.timemodified AS lastmodified,
 +                       uf.workflowstate, uf.allocatedmarker, gmx.maxattempt AS attemptnumber
 +                  FROM {user} u
 +             LEFT JOIN ( ' . $grademaxattempt . ' ) gmx ON u.id = gmx.userid
 +             LEFT JOIN {assign_grades} g ON
 +                       u.id = g.userid AND
 +                       g.assignment = :assignid2 AND
 +                       g.attemptnumber = gmx.maxattempt
 +             LEFT JOIN {assign_user_flags} uf ON uf.assignment = g.assignment AND uf.userid = g.userid
 +                 WHERE u.id ' . $userids;
          $currentgrades = $DB->get_recordset_sql($sql, $params);
  
          $modifiedusers = array();
                  if ($this->grading_disabled($modified->userid)) {
                      continue;
                  }
 -                if ((int)$current->lastmodified > (int)$modified->lastmodified) {
 +                $badmodified = (int)$current->lastmodified > (int)$modified->lastmodified;
 +                $badattempt = (int)$current->attemptnumber != (int)$modified->attemptnumber;
 +                if ($badmodified || $badattempt) {
                      // Error - record has been modified since viewing the page.
                      return get_string('errorrecordmodified', 'assign');
                  } else {
  
          $this->update_submission($submission, $userid, true, $instance->teamsubmission);
  
+         if ($instance->teamsubmission && !$instance->requireallteammemberssubmit) {
+             $team = $this->get_submission_group_members($submission->groupid, true);
+             foreach ($team as $member) {
+                 if ($member->id != $userid) {
+                     $membersubmission = clone($submission);
+                     $this->update_submission($membersubmission, $member->id, true, $instance->teamsubmission);
+                 }
+             }
+         }
          // Logging.
          if (isset($data->submissionstatement) && ($userid == $USER->id)) {
              \mod_assign\event\statement_accepted::create_from_submission($this, $submission)->trigger();