diff --git a/blocks/completionstatus/block_completionstatus.php b/blocks/completionstatus/block_completionstatus.php
index 449e632e7e7..2e00684ddfb 100644
--- a/blocks/completionstatus/block_completionstatus.php
+++ b/blocks/completionstatus/block_completionstatus.php
@@ -83,148 +83,145 @@ class block_completionstatus extends block_base {
}
// Check this user is enroled
- if (!$info->is_tracked_user($USER->id)) {
- // If not enrolled, but are can view the report:
- if (has_capability('report/completion:view', get_context_instance(CONTEXT_COURSE, $course->id))) {
- $report = new moodle_url('/report/completion/index.php', array('course' => $course->id));
- $this->content->text = ''.get_string('viewcoursereport', 'completion').'';
- return $this->content;
+ if ($info->is_tracked_user($USER->id)) {
+
+ // Generate markup for criteria statuses
+ $shtml = '';
+
+ // For aggregating activity completion
+ $activities = array();
+ $activities_complete = 0;
+
+ // For aggregating course prerequisites
+ $prerequisites = array();
+ $prerequisites_complete = 0;
+
+ // Flag to set if current completion data is inconsistent with
+ // what is stored in the database
+ $pending_update = false;
+
+ // Loop through course criteria
+ foreach ($completions as $completion) {
+
+ $criteria = $completion->get_criteria();
+ $complete = $completion->is_complete();
+
+ if (!$pending_update && $criteria->is_pending($completion)) {
+ $pending_update = true;
+ }
+
+ // Activities are a special case, so cache them and leave them till last
+ if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
+ $activities[$criteria->moduleinstance] = $complete;
+
+ if ($complete) {
+ $activities_complete++;
+ }
+
+ continue;
+ }
+
+ // Prerequisites are also a special case, so cache them and leave them till last
+ if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
+ $prerequisites[$criteria->courseinstance] = $complete;
+
+ if ($complete) {
+ $prerequisites_complete++;
+ }
+
+ continue;
+ }
+
+ $shtml .= '
| ';
+ $shtml .= $criteria->get_title();
+ $shtml .= ' | ';
+ $shtml .= $completion->get_status();
+ $shtml .= ' |
';
}
- // Otherwise, show error
+ // Aggregate activities
+ if (!empty($activities)) {
+
+ $shtml .= '| ';
+ $shtml .= get_string('activitiescompleted', 'completion');
+ $shtml .= ' | ';
+ $a = new stdClass();
+ $a->first = $activities_complete;
+ $a->second = count($activities);
+ $shtml .= get_string('firstofsecond', 'block_completionstatus', $a);
+ $shtml .= ' |
';
+ }
+
+ // Aggregate prerequisites
+ if (!empty($prerequisites)) {
+
+ $phtml = '| ';
+ $phtml .= get_string('prerequisitescompleted', 'completion');
+ $phtml .= ' | ';
+ $a = new stdClass();
+ $a->first = $prerequisites_complete;
+ $a->second = count($prerequisites);
+ $phtml .= get_string('firstofsecond', 'block_completionstatus', $a);
+ $phtml .= ' |
';
+
+ $shtml = $phtml . $shtml;
+ }
+
+ // Display completion status
+ $this->content->text = '';
+ $this->content->text .= '| '.get_string('status').': ';
+
+ // Is course complete?
+ $coursecomplete = $info->is_course_complete($USER->id);
+
+ // Load course completion
+ $params = array(
+ 'userid' => $USER->id,
+ 'course' => $course->id
+ );
+ $ccompletion = new completion_completion($params);
+
+ // Has this user completed any criteria?
+ $criteriacomplete = $info->count_course_user_data($USER->id);
+
+ if ($pending_update) {
+ $this->content->text .= ''.get_string('pending', 'completion').'';
+ } else if ($coursecomplete) {
+ $this->content->text .= get_string('complete');
+ } else if (!$criteriacomplete && !$ccompletion->timestarted) {
+ $this->content->text .= ''.get_string('notyetstarted', 'completion').'';
+ } else {
+ $this->content->text .= ''.get_string('inprogress','completion').'';
+ }
+
+ $this->content->text .= ' |
';
+ $this->content->text .= '| ';
+
+ // Get overall aggregation method
+ $overall = $info->get_aggregation_method();
+
+ if ($overall == COMPLETION_AGGREGATION_ALL) {
+ $this->content->text .= get_string('criteriarequiredall', 'completion');
+ } else {
+ $this->content->text .= get_string('criteriarequiredany', 'completion');
+ }
+
+ $this->content->text .= ': |
';
+ $this->content->text .= '| '.get_string('requiredcriteria', 'completion').' | '.get_string('status').' |
';
+ $this->content->text .= $shtml.'
';
+
+ // Display link to detailed view
+ $details = new moodle_url('/blocks/completionstatus/details.php', array('course' => $course->id));
+ $this->content->footer = '
'.get_string('moredetails', 'completion').'';
+ } else {
+ // If user is not enrolled, show error
$this->content->text = get_string('notenroled', 'completion');
- return $this->content;
}
- // Generate markup for criteria statuses
- $shtml = '';
-
- // For aggregating activity completion
- $activities = array();
- $activities_complete = 0;
-
- // For aggregating course prerequisites
- $prerequisites = array();
- $prerequisites_complete = 0;
-
- // Flag to set if current completion data is inconsistent with
- // what is stored in the database
- $pending_update = false;
-
- // Loop through course criteria
- foreach ($completions as $completion) {
-
- $criteria = $completion->get_criteria();
- $complete = $completion->is_complete();
-
- if (!$pending_update && $criteria->is_pending($completion)) {
- $pending_update = true;
- }
-
- // Activities are a special case, so cache them and leave them till last
- if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
- $activities[$criteria->moduleinstance] = $complete;
-
- if ($complete) {
- $activities_complete++;
- }
-
- continue;
- }
-
- // Prerequisites are also a special case, so cache them and leave them till last
- if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
- $prerequisites[$criteria->courseinstance] = $complete;
-
- if ($complete) {
- $prerequisites_complete++;
- }
-
- continue;
- }
-
- $shtml .= '| ';
- $shtml .= $criteria->get_title();
- $shtml .= ' | ';
- $shtml .= $completion->get_status();
- $shtml .= ' |
';
+ if (has_capability('report/completion:view', $context)) {
+ $report = new moodle_url('/report/completion/index.php', array('course' => $course->id));
+ $this->content->footer .= '
'.get_string('viewcoursereport', 'completion').'';
}
-
- // Aggregate activities
- if (!empty($activities)) {
-
- $shtml .= '| ';
- $shtml .= get_string('activitiescompleted', 'completion');
- $shtml .= ' | ';
- $a = new stdClass();
- $a->first = $activities_complete;
- $a->second = count($activities);
- $shtml .= get_string('firstofsecond', 'block_completionstatus', $a);
- $shtml .= ' |
';
- }
-
- // Aggregate prerequisites
- if (!empty($prerequisites)) {
-
- $phtml = '| ';
- $phtml .= get_string('prerequisitescompleted', 'completion');
- $phtml .= ' | ';
- $a = new stdClass();
- $a->first = $prerequisites_complete;
- $a->second = count($prerequisites);
- $phtml .= get_string('firstofsecond', 'block_completionstatus', $a);
- $phtml .= ' |
';
-
- $shtml = $phtml . $shtml;
- }
-
- // Display completion status
- $this->content->text = '';
- $this->content->text .= '| '.get_string('status').': ';
-
- // Is course complete?
- $coursecomplete = $info->is_course_complete($USER->id);
-
- // Load course completion
- $params = array(
- 'userid' => $USER->id,
- 'course' => $course->id
- );
- $ccompletion = new completion_completion($params);
-
- // Has this user completed any criteria?
- $criteriacomplete = $info->count_course_user_data($USER->id);
-
- if ($pending_update) {
- $this->content->text .= ''.get_string('pending', 'completion').'';
- } else if ($coursecomplete) {
- $this->content->text .= get_string('complete');
- } else if (!$criteriacomplete && !$ccompletion->timestarted) {
- $this->content->text .= ''.get_string('notyetstarted', 'completion').'';
- } else {
- $this->content->text .= ''.get_string('inprogress','completion').'';
- }
-
- $this->content->text .= ' |
';
- $this->content->text .= '| ';
-
- // Get overall aggregation method
- $overall = $info->get_aggregation_method();
-
- if ($overall == COMPLETION_AGGREGATION_ALL) {
- $this->content->text .= get_string('criteriarequiredall', 'completion');
- } else {
- $this->content->text .= get_string('criteriarequiredany', 'completion');
- }
-
- $this->content->text .= ': |
';
- $this->content->text .= '| '.get_string('requiredcriteria', 'completion').' | '.get_string('status').' |
';
- $this->content->text .= $shtml.'
';
-
- // Display link to detailed view
- $details = new moodle_url('/blocks/completionstatus/details.php', array('course' => $course->id));
- $this->content->footer = '
'.get_string('moredetails', 'completion').'';
-
return $this->content;
}
}