MDL-66147 mod_assign: submissions overview page shows time interval
authorJake Dallimore <jake@moodle.com>
Tue, 6 Aug 2019 08:30:26 +0000 (16:30 +0800)
committerJake Dallimore <jake@moodle.com>
Tue, 13 Aug 2019 07:09:11 +0000 (15:09 +0800)
Use get_time_interval_string() on the teacher only page, to show how
long after the course start the assignment is due for each user.

mod/assign/lang/en/assign.php
mod/assign/locallib.php
mod/assign/renderable.php
mod/assign/renderer.php

index 71878e8..c367b0a 100644 (file)
@@ -430,6 +430,9 @@ $string['quickgrading'] = 'Quick grading';
 $string['quickgradingresult'] = 'Quick grading';
 $string['quickgradingchangessaved'] = 'The grade changes were saved';
 $string['quickgrading_help'] = 'Quick grading allows you to assign grades (and outcomes) directly in the submissions table. Quick grading is not compatible with advanced grading and is not recommended when there are multiple markers.';
+$string['relativedatessubmissiontimeleft'] = 'Calculated for each student';
+$string['relativedatessubmissionduedateafter'] = '{$a->datediffstr} after course start';
+$string['relativedatessubmissionduedatebefore'] = '{$a->datediffstr} before course start';
 $string['removeallgroupoverrides'] = 'Delete all group overrides';
 $string['removealluseroverrides'] = 'Delete all user overrides';
 $string['reopenuntilpassincompatiblewithblindmarking'] = 'Reopen until pass option is incompatible with blind marking, because the grades are not released to the gradebook until the student identities are revealed.';
index a227530..8850123 100644 (file)
@@ -5562,8 +5562,9 @@ class assign {
      */
     public function get_assign_grading_summary_renderable($activitygroup = null) {
 
-        $instance = $this->get_instance();
+        $instance = $this->get_default_instance(); // Grading summary requires the raw dates, regardless of relativedates mode.
         $cm = $this->get_course_module();
+        $course = $this->get_course();
 
         $draft = ASSIGN_SUBMISSION_STATUS_DRAFT;
         $submitted = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
@@ -5584,35 +5585,43 @@ class assign {
                 }
             }
 
-            $summary = new assign_grading_summary($this->count_teams($activitygroup),
-                                                  $instance->submissiondrafts,
-                                                  $this->count_submissions_with_status($draft, $activitygroup),
-                                                  $this->is_any_submission_plugin_enabled(),
-                                                  $this->count_submissions_with_status($submitted, $activitygroup),
-                                                  $instance->cutoffdate,
-                                                  $instance->duedate,
-                                                  $this->get_course_module()->id,
-                                                  $this->count_submissions_need_grading($activitygroup),
-                                                  $instance->teamsubmission,
-                                                  $warnofungroupedusers,
-                                                  $this->can_grade(),
-                                                  $isvisible);
+            $summary = new assign_grading_summary(
+                $this->count_teams($activitygroup),
+                $instance->submissiondrafts,
+                $this->count_submissions_with_status($draft, $activitygroup),
+                $this->is_any_submission_plugin_enabled(),
+                $this->count_submissions_with_status($submitted, $activitygroup),
+                $instance->cutoffdate,
+                $instance->duedate,
+                $this->get_course_module()->id,
+                $this->count_submissions_need_grading($activitygroup),
+                $instance->teamsubmission,
+                $warnofungroupedusers,
+                $course->relativedatesmode,
+                $course->startdate,
+                $this->can_grade(),
+                $isvisible
+            );
         } else {
             // The active group has already been updated in groups_print_activity_menu().
             $countparticipants = $this->count_participants($activitygroup);
-            $summary = new assign_grading_summary($countparticipants,
-                                                  $instance->submissiondrafts,
-                                                  $this->count_submissions_with_status($draft, $activitygroup),
-                                                  $this->is_any_submission_plugin_enabled(),
-                                                  $this->count_submissions_with_status($submitted, $activitygroup),
-                                                  $instance->cutoffdate,
-                                                  $instance->duedate,
-                                                  $this->get_course_module()->id,
-                                                  $this->count_submissions_need_grading($activitygroup),
-                                                  $instance->teamsubmission,
-                                                  assign_grading_summary::WARN_GROUPS_NO,
-                                                  $this->can_grade(),
-                                                  $isvisible);
+            $summary = new assign_grading_summary(
+                $countparticipants,
+                $instance->submissiondrafts,
+                $this->count_submissions_with_status($draft, $activitygroup),
+                $this->is_any_submission_plugin_enabled(),
+                $this->count_submissions_with_status($submitted, $activitygroup),
+                $instance->cutoffdate,
+                $instance->duedate,
+                $this->get_course_module()->id,
+                $this->count_submissions_need_grading($activitygroup),
+                $instance->teamsubmission,
+                assign_grading_summary::WARN_GROUPS_NO,
+                $course->relativedatesmode,
+                $course->startdate,
+                $this->can_grade(),
+                $isvisible
+            );
         }
 
         return $summary;
index 86c3787..6167ca0 100644 (file)
@@ -748,6 +748,10 @@ class assign_grading_summary implements renderable {
     public $teamsubmission = false;
     /** @var boolean warnofungroupedusers - Do we need to warn people that there are users without groups */
     public $warnofungroupedusers = false;
+    /** @var boolean relativedatesmode - Is the course a relative dates mode course or not */
+    public $courserelativedatesmode = false;
+    /** @var int coursestartdate - start date of the course as a unix timestamp*/
+    public $coursestartdate;
     /** @var boolean cangrade - Can the current user grade students? */
     public $cangrade = false;
     /** @var boolean isvisible - Is the assignment's context module visible to students? */
@@ -774,6 +778,8 @@ class assign_grading_summary implements renderable {
      * @param int $submissionsneedgradingcount
      * @param bool $teamsubmission
      * @param string $warnofungroupedusers
+     * @param bool $courserelativedatesmode true if the course is using relative dates, false otherwise.
+     * @param int $coursestartdate unix timestamp representation of the course start date.
      * @param bool $cangrade
      * @param bool $isvisible
      */
@@ -788,6 +794,8 @@ class assign_grading_summary implements renderable {
                                 $submissionsneedgradingcount,
                                 $teamsubmission,
                                 $warnofungroupedusers,
+                                $courserelativedatesmode,
+                                $coursestartdate,
                                 $cangrade = true,
                                 $isvisible = true) {
         $this->participantcount = $participantcount;
@@ -801,6 +809,8 @@ class assign_grading_summary implements renderable {
         $this->submissionsneedgradingcount = $submissionsneedgradingcount;
         $this->teamsubmission = $teamsubmission;
         $this->warnofungroupedusers = $warnofungroupedusers;
+        $this->courserelativedatesmode = $courserelativedatesmode;
+        $this->coursestartdate = $coursestartdate;
         $this->cangrade = $cangrade;
         $this->isvisible = $isvisible;
     }
index 1046f9a..225b23a 100644 (file)
@@ -312,15 +312,30 @@ class mod_assign_renderer extends plugin_renderer_base {
         if ($summary->duedate) {
             // Due date.
             $duedate = $summary->duedate;
+            if ($summary->courserelativedatesmode) {
+                // Returns a formatted string, in the format '10d 10h 45m'.
+                $diffstr = get_time_interval_string($duedate, $summary->coursestartdate);
+                if ($duedate >= $summary->coursestartdate) {
+                    $userduedate = get_string('relativedatessubmissionduedateafter', 'mod_assign', ['datediffstr' => $diffstr]);
+                } else {
+                    $userduedate = get_string('relativedatessubmissionduedatebefore', 'mod_assign', ['datediffstr' => $diffstr]);
+                }
+            } else {
+                $userduedate = userdate($duedate);
+            }
             $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
-                                       userdate($duedate));
+                                       $userduedate);
 
             // Time remaining.
-            $due = '';
-            if ($duedate - $time <= 0) {
-                $due = get_string('assignmentisdue', 'assign');
+            if ($summary->courserelativedatesmode) {
+                $due = get_string('relativedatessubmissiontimeleft', 'mod_assign');
             } else {
-                $due = format_time($duedate - $time);
+                $due = '';
+                if ($duedate - $time <= 0) {
+                    $due = get_string('assignmentisdue', 'assign');
+                } else {
+                    $due = format_time($duedate - $time);
+                }
             }
             $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);