MDL-26190 completion blocks: Completion blocks shouldn't ever be blank
authorAaron Barnes <aaronb@catalyst.net.nz>
Thu, 17 Mar 2011 02:04:33 +0000 (15:04 +1300)
committerAaron Barnes <aaronb@catalyst.net.nz>
Wed, 4 May 2011 00:55:26 +0000 (12:55 +1200)
blocks/completionstatus/block_completionstatus.php
blocks/completionstatus/details.php
blocks/completionstatus/lang/en/block_completionstatus.php
blocks/selfcompletion/block_selfcompletion.php
blocks/selfcompletion/lang/en/block_selfcompletion.php
lang/en/completion.php

index 0d7d104..2f84a3c 100644 (file)
@@ -47,19 +47,34 @@ class block_completionstatus extends block_base {
         // 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;
         }
 
index 625dee8..5d4db9b 100644 (file)
@@ -60,14 +60,11 @@ $can_view = false;
 // 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 @@ if (!$can_view) {
 }
 
 
+// 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);
+    }
 }
 
 
index 9a8f6b6..a24ec57 100644 (file)
@@ -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';
index a5a7da9..9954a39 100644 (file)
@@ -40,36 +40,44 @@ class block_selfcompletion extends block_base {
     }
 
     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 @@ class block_selfcompletion extends block_base {
             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;
index 45775d8..03cf0dc 100644 (file)
@@ -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';
index 00b6a9d..66fc44d 100644 (file)
@@ -56,6 +56,9 @@ $string['completion_manual'] = 'Students can manually mark the activity as compl
 $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['completionsettingslocked']='Completion settings locked';
 $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['markcomplete']='Mark complete';
 $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['unenrolingfromcourse']='Unenroling from course';
 $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';