Permalink
Browse files

MDL-26190 completion blocks: Completion blocks shouldn't ever be blank

  • Loading branch information...
1 parent 0baa1ee commit 90061a6d95e48f87eb50eed488822d907407eaea Aaron Barnes committed Mar 17, 2011
@@ -47,19 +47,34 @@ public function get_content() {
// Create empty content
$this->content = new stdClass;
+ // Can edit settings?
+ $can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
+
+ // Get course completion data
+ $info = new completion_info($this->page->course);
+
// Don't display if completion isn't enabled!
- if (!$this->page->course->enablecompletion) {
- $this->content->text = get_string('completionnotenabled', 'block_completionstatus');
+ if (!completion_info::is_enabled_for_site()) {
+ if ($can_edit) {
+ $this->content->text = get_string('completionnotenabledforsite', 'completion');
+ }
+ return $this->content;
+
+ } else if (!$info->is_enabled()) {
+ if ($can_edit) {
+ $this->content->text = get_string('completionnotenabledforcourse', 'completion');
+ }
return $this->content;
}
// Load criteria to display
- $info = new completion_info($this->page->course);
$completions = $info->get_completions($USER->id);
// Check if this course has any criteria
if (empty($completions)) {
- $this->content->text = get_string('nocriteria', 'block_completionstatus');
+ if ($can_edit) {
+ $this->content->text = get_string('nocriteriaset', 'completion');
+ }
return $this->content;
}
@@ -60,14 +60,11 @@
// Can view own report
if ($USER->id == $user->id) {
$can_view = true;
-}
-elseif (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
+} else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
$can_view = true;
-}
-elseif (has_capability('coursereport/completion:view', $coursecontext)) {
+} else if (has_capability('coursereport/completion:view', $coursecontext)) {
$can_view = true;
-}
-elseif (has_capability('coursereport/completion:view', $personalcontext)) {
+} else if (has_capability('coursereport/completion:view', $personalcontext)) {
$can_view = true;
}
@@ -76,23 +73,31 @@
}
+// Load completion data
+$info = new completion_info($course);
+
+$returnurl = "{$CFG->wwwroot}/course/view.php?id={$id}";
+
// Don't display if completion isn't enabled!
-if (!$course->enablecompletion) {
- print_error('completionnotenabled', 'block_completionstatus');
+if (!$info->is_enabled()) {
+ print_error('completionnotenabled', 'completion', $returnurl);
}
// Load criteria to display
-$info = new completion_info($course);
$completions = $info->get_completions($user->id);
// Check if this course has any criteria
if (empty($completions)) {
- print_error('nocriteria', 'block_completionstatus');
+ print_error('nocriteriaset', 'completion', $returnurl);
}
// Check this user is enroled
if (!$info->is_tracked_user($user->id)) {
- print_error('notenroled', 'completion');
+ if ($USER->id == $user->id) {
+ print_error('notenroled', 'completion', $returnurl);
+ } else {
+ print_error('usernotenroled', 'completion', $returnurl);
+ }
}
@@ -1,9 +1,7 @@
<?php
-$string['completionnotenabled'] = 'Course completion is not enabled';
$string['completionprogressdetails'] = 'Completion progress details';
$string['completionstatus'] = 'Course completion status';
$string['criteriagroup'] = 'Criteria group';
-$string['nocriteria'] = 'No criteria have been set for this course';
$string['pluginname'] = 'Course completion status';
$string['requirement'] = 'Requirement';
@@ -40,36 +40,44 @@ public function init() {
}
public function get_content() {
- global $USER;
+ global $CFG, $USER;
// If content is cached
if ($this->content !== NULL) {
return $this->content;
}
- global $CFG;
-
// Create empty content
$this->content = new stdClass;
- // Don't display if completion isn't enabled!
- if (!$this->page->course->enablecompletion) {
- $this->content->text = get_string('completionnotenabled', 'block_selfcompletion');
- return $this->content;
- }
+ // Can edit settings?
+ $can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
// Get course completion data
$info = new completion_info($this->page->course);
- $completion = $info->get_completion($USER->id, COMPLETION_CRITERIA_TYPE_SELF);
- // Is course complete?
- if ($info->is_course_complete($USER->id)) {
+ // Don't display if completion isn't enabled!
+ if (!completion_info::is_enabled_for_site()) {
+ if ($can_edit) {
+ $this->content->text = get_string('completionnotenabledforsite', 'completion');
+ }
+ return $this->content;
+
+ } else if (!$info->is_enabled()) {
+ if ($can_edit) {
+ $this->content->text = get_string('completionnotenabledforcourse', 'completion');
+ }
return $this->content;
}
+ // Get this user's data
+ $completion = $info->get_completion($USER->id, COMPLETION_CRITERIA_TYPE_SELF);
+
// Check if self completion is one of this course's criteria
if (empty($completion)) {
- $this->content->text = get_string('selfcompletionnotenabled', 'block_selfcompletion');
+ if ($can_edit) {
+ $this->content->text = get_string('selfcompletionnotenabled', 'block_selfcompletion');
+ }
return $this->content;
}
@@ -79,13 +87,21 @@ public function get_content() {
return $this->content;
}
+ // Is course complete?
+ if ($info->is_course_complete($USER->id)) {
+ $this->content->text = get_string('coursealreadycompleted', 'completion');
+ return $this->content;
+
// Check if the user has already marked themselves as complete
- if ($completion->is_complete()) {
+ } else if ($completion->is_complete()) {
+ $this->content->text = get_string('alreadyselfcompleted', 'block_selfcompletion');
return $this->content;
+
+ // If user is not complete, or has not yet self completed
} else {
$this->content->text = '';
- $this->content->footer = '<br /><a href="'.$CFG->wwwroot.'/course/togglecompletion.php?course='.$this->page->course->id.'">'.
- get_string('completecourse', 'block_selfcompletion').'</a>...';
+ $this->content->footer = '<br /><a href="'.$CFG->wwwroot.'/course/togglecompletion.php?course='.$this->page->course->id.'">';
+ $this->content->footer .= get_string('completecourse', 'block_selfcompletion').'</a>...';
}
return $this->content;
@@ -23,8 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-$string['selfcompletion'] = 'Self completion';
-$string['pluginname'] = 'Self completion';
+$string['alreadyselfcompleted'] = 'You have already marked yourself as complete in this course';
$string['completecourse'] = 'Complete course';
-$string['completionnotenabled'] = 'Course completion is not enabled';
+$string['pluginname'] = 'Self completion';
+$string['selfcompletion'] = 'Self completion';
$string['selfcompletionnotenabled'] = 'The self completion criteria has not been enabled for this course';
View
@@ -56,6 +56,9 @@
$string['completion_none'] = 'Do not indicate activity completion';
$string['completion-title-manual-n'] = 'Mark as complete';
$string['completion-title-manual-y'] = 'Mark as not complete';
+$string['completionnotenabled'] = 'Completion is not enabled';
+$string['completionnotenabledforcourse'] = 'Completion is not enabled for this course';
+$string['completionnotenabledforsite'] = 'Completion is not enabled for this site';
$string['completionusegrade'] = 'Require grade';
$string['completionusegrade_help'] = 'If enabled, the activity is considered complete when a student receives a grade. Pass and fail icons may be displayed if a pass grade for the activity has been set.';
$string['completionusegrade_desc'] = 'Student must receive a grade to complete this activity';
@@ -93,6 +96,7 @@
$string['completionstartonenrol']='Completion tracking begins on enrolment';
$string['completionstartonenrolhelp']='Begin tracking a student\'s progress in course completion after course enrolment';
$string['confirmselfcompletion']='Confirm self completion';
+$string['coursealreadycompleted']='You have already completed this course';
$string['coursecomplete']='Course complete';
$string['coursecompleted']='Course completed';
$string['coursegrade']='Course grade';
@@ -121,7 +125,8 @@
$string['markedcompleteby']='Marked complete by {$a}';
$string['markingyourselfcomplete']='Marking yourself complete';
$string['moredetails']='More details';
-$string['notenroled']='You are not enroled as a student in this course';
+$string['nocriteriaset']='No completion criteria set for this course';
+$string['notenroled']='You are not enroled in this course';
$string['notyetstarted']='Not yet started';
$string['overallcriteriaaggregation']='Overall criteria type aggregation';
$string['passinggrade']='Passing grade';
@@ -142,6 +147,7 @@
$string['unenrolment']='Unenrolment';
$string['unlockcompletiondelete']='Unlock completion options and delete user completion data';
$string['usealternateselector']='Use the alternate course selector';
+$string['usernotenroled']='User is not enroled in this course';
$string['viewcoursereport']='View course report';
$string['viewingactivity']='Viewing the {$a}';
$string['xdays']='{$a} days';

0 comments on commit 90061a6

Please sign in to comment.