Merge branch 'master_MDL-65116' of https://github.com/yao9394/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 28 Aug 2019 14:39:49 +0000 (16:39 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 28 Aug 2019 14:39:49 +0000 (16:39 +0200)
1  2 
mod/assign/locallib.php

diff --combined mod/assign/locallib.php
@@@ -909,7 -909,7 +909,7 @@@ class assign 
          $keys = array('duedate', 'cutoffdate', 'allowsubmissionsfromdate');
          foreach ($keys as $key) {
              if (isset($override->{$key})) {
 -                $this->get_instance()->{$key} = $override->{$key};
 +                $this->get_instance($userid)->{$key} = $override->{$key};
              }
          }
  
                  $this->is_any_submission_plugin_enabled(),
                  $this->count_submissions_with_status($submitted, $activitygroup),
                  $instance->cutoffdate,
-                 $instance->duedate,
+                 $this->get_duedate($activitygroup),
                  $this->get_course_module()->id,
                  $this->count_submissions_need_grading($activitygroup),
                  $instance->teamsubmission,
                  $this->is_any_submission_plugin_enabled(),
                  $this->count_submissions_with_status($submitted, $activitygroup),
                  $instance->cutoffdate,
-                 $instance->duedate,
+                 $this->get_duedate($activitygroup),
                  $this->get_course_module()->id,
                  $this->count_submissions_need_grading($activitygroup),
                  $instance->teamsubmission,
          return $summary;
      }
  
+     /**
+      * Return group override duedate.
+      *
+      * @param int $activitygroup Activity active group
+      * @return int $duedate
+      */
+     private function  get_duedate($activitygroup = null) {
+         global $DB;
+         if ($activitygroup === null) {
+             $activitygroup = groups_get_activity_group($this->get_course_module());
+         }
+         if ($this->can_view_grades()) {
+             $params = array('groupid' => $activitygroup, 'assignid' => $this->get_instance()->id);
+             $groupoverride = $DB->get_record('assign_overrides', $params);
+             if (!empty($groupoverride->duedate)) {
+                 return $groupoverride->duedate;
+             }
+         }
+         return $this->get_instance()->duedate;
+     }
      /**
       * View submissions page (contains details of current submission).
       *