Skip to content

Commit

Permalink
Merge branch 'MDL-58490-master' of git://github.com/lameze/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Apr 21, 2017
2 parents 992b296 + 4a995a1 commit 4707816
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
23 changes: 11 additions & 12 deletions blocks/myoverview/classes/output/courses_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,13 @@ public function export_for_template(renderer_base $output) {
$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);

Expand All @@ -109,7 +100,15 @@ public function export_for_template(renderer_base $output) {
$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);
Expand Down
14 changes: 12 additions & 2 deletions blocks/myoverview/classes/output/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4707816

Please sign in to comment.