Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blocks/selfcompletion/block_selfcompletion.php
Go to the documentation of this file.
00001 <?php
00002 
00004 //                                                                       //
00005 // NOTICE OF COPYRIGHT                                                   //
00006 //                                                                       //
00007 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00008 //          http://moodle.com                                            //
00009 //                                                                       //
00010 // Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
00011 //                                                                       //
00012 // This program is free software; you can redistribute it and/or modify  //
00013 // it under the terms of the GNU General Public License as published by  //
00014 // the Free Software Foundation; either version 2 of the License, or     //
00015 // (at your option) any later version.                                   //
00016 //                                                                       //
00017 // This program is distributed in the hope that it will be useful,       //
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00020 // GNU General Public License for more details:                          //
00021 //                                                                       //
00022 //          http://www.gnu.org/copyleft/gpl.html                         //
00023 //                                                                       //
00025 
00026 require_once($CFG->libdir.'/completionlib.php');
00027 
00036 class block_selfcompletion extends block_base {
00037 
00038     public function init() {
00039         $this->title   = get_string('selfcompletion', 'block_selfcompletion');
00040     }
00041 
00042     public function get_content() {
00043         global $CFG, $USER;
00044 
00045         // If content is cached
00046         if ($this->content !== NULL) {
00047           return $this->content;
00048         }
00049 
00050         // Create empty content
00051         $this->content = new stdClass;
00052 
00053         // Can edit settings?
00054         $can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
00055 
00056         // Get course completion data
00057         $info = new completion_info($this->page->course);
00058 
00059         // Don't display if completion isn't enabled!
00060         if (!completion_info::is_enabled_for_site()) {
00061             if ($can_edit) {
00062                 $this->content->text = get_string('completionnotenabledforsite', 'completion');
00063             }
00064             return $this->content;
00065 
00066         } else if (!$info->is_enabled()) {
00067             if ($can_edit) {
00068                 $this->content->text = get_string('completionnotenabledforcourse', 'completion');
00069             }
00070             return $this->content;
00071         }
00072 
00073         // Get this user's data
00074         $completion = $info->get_completion($USER->id, COMPLETION_CRITERIA_TYPE_SELF);
00075 
00076         // Check if self completion is one of this course's criteria
00077         if (empty($completion)) {
00078             if ($can_edit) {
00079                 $this->content->text = get_string('selfcompletionnotenabled', 'block_selfcompletion');
00080             }
00081             return $this->content;
00082         }
00083 
00084         // Check this user is enroled
00085         if (!$info->is_tracked_user($USER->id)) {
00086             $this->content->text = get_string('notenroled', 'completion');
00087             return $this->content;
00088         }
00089 
00090         // Is course complete?
00091         if ($info->is_course_complete($USER->id)) {
00092             $this->content->text = get_string('coursealreadycompleted', 'completion');
00093             return $this->content;
00094 
00095         // Check if the user has already marked themselves as complete
00096         } else if ($completion->is_complete()) {
00097             $this->content->text = get_string('alreadyselfcompleted', 'block_selfcompletion');
00098             return $this->content;
00099 
00100         // If user is not complete, or has not yet self completed
00101         } else {
00102             $this->content->text = '';
00103             $this->content->footer = '<br /><a href="'.$CFG->wwwroot.'/course/togglecompletion.php?course='.$this->page->course->id.'">';
00104             $this->content->footer .= get_string('completecourse', 'block_selfcompletion').'</a>...';
00105         }
00106 
00107         return $this->content;
00108     }
00109 }
 All Data Structures Namespaces Files Functions Variables Enumerations