Merge branch 'MDL-58490-master' of git://github.com/lameze/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 21 Apr 2017 00:52:15 +0000 (08:52 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Fri, 21 Apr 2017 00:52:15 +0000 (08:52 +0800)
blocks/myoverview/classes/output/courses_view.php
blocks/myoverview/classes/output/main.php

index c92346a..198deb6 100644 (file)
@@ -85,22 +85,13 @@ class courses_view implements renderable, templatable {
             $exportedcourse = $exporter->export($output);
 
             if (isset($this->coursesprogress[$courseid])) {
-                $courseprogress = $this->coursesprogress[$courseid];
+                $coursecompleted = $this->coursesprogress[$courseid]['completed'];
+                $courseprogress = $this->coursesprogress[$courseid]['progress'];
                 $exportedcourse->hasprogress = !is_null($courseprogress);
                 $exportedcourse->progress = $courseprogress;
             }
 
-            if ($startdate > $today) {
-                // Courses that have not started yet.
-                $futurepages = floor($coursesbystatus['future'] / $this::COURSES_PER_PAGE);
-
-                $coursesview['future']['pages'][$futurepages]['courses'][] = $exportedcourse;
-                $coursesview['future']['pages'][$futurepages]['active'] = ($futurepages == 0 ? true : false);
-                $coursesview['future']['pages'][$futurepages]['page'] = $futurepages + 1;
-                $coursesview['future']['haspages'] = true;
-                $coursesbystatus['future']++;
-
-            } else if (!empty($enddate) && $enddate < $today) {
+            if ((isset($coursecompleted) && $coursecompleted) || (!empty($enddate) && $enddate < $today)) {
                 // Courses that have already ended.
                 $pastpages = floor($coursesbystatus['past'] / $this::COURSES_PER_PAGE);
 
@@ -109,7 +100,15 @@ class courses_view implements renderable, templatable {
                 $coursesview['past']['pages'][$pastpages]['page'] = $pastpages + 1;
                 $coursesview['past']['haspages'] = true;
                 $coursesbystatus['past']++;
+            } else if ($startdate > $today) {
+                // Courses that have not started yet.
+                $futurepages = floor($coursesbystatus['future'] / $this::COURSES_PER_PAGE);
 
+                $coursesview['future']['pages'][$futurepages]['courses'][] = $exportedcourse;
+                $coursesview['future']['pages'][$futurepages]['active'] = ($futurepages == 0 ? true : false);
+                $coursesview['future']['pages'][$futurepages]['page'] = $futurepages + 1;
+                $coursesview['future']['haspages'] = true;
+                $coursesbystatus['future']++;
             } else {
                 // Courses still in progress. Either their end date is not set, or the end date is not yet past the current date.
                 $inprogresspages = floor($coursesbystatus['inprogress'] / $this::COURSES_PER_PAGE);
index edfa153..e7896e0 100644 (file)
@@ -44,17 +44,27 @@ class main implements renderable, templatable {
      * @return stdClass
      */
     public function export_for_template(renderer_base $output) {
+        global $USER;
+
         $courses = enrol_get_my_courses('*', 'fullname ASC');
         $coursesprogress = [];
 
         foreach ($courses as $course) {
-            $percentage = progress::get_course_progress_percentage($course);
 
+            $completion = new \completion_info($course);
+
+            // First, let's make sure completion is enabled.
+            if (!$completion->is_enabled()) {
+                continue;
+            }
+
+            $percentage = progress::get_course_progress_percentage($course);
             if (!is_null($percentage)) {
                 $percentage = floor($percentage);
             }
 
-            $coursesprogress[$course->id] = $percentage;
+            $coursesprogress[$course->id]['completed'] = $completion->is_course_complete($USER->id);
+            $coursesprogress[$course->id]['progress'] = $percentage;
         }
 
         $coursesview = new courses_view($courses, $coursesprogress);