Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/completion/completion_criteria_course.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00029 class completion_criteria_course extends completion_criteria {
00030 
00035     public $criteriatype = COMPLETION_CRITERIA_TYPE_COURSE;
00036 
00044     public static function fetch($params) {
00045         $params['criteriatype'] = COMPLETION_CRITERIA_TYPE_COURSE;
00046         return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
00047     }
00048 
00056     public function config_form_display(&$mform, $data = null) {
00057         global $CFG;
00058 
00059         $link = "<a href=\"{$CFG->wwwroot}/course/view.php?id={$data->id}\">".s($data->fullname).'</a>';
00060         $mform->addElement('checkbox', 'criteria_course['.$data->id.']', $link);
00061 
00062         if ($this->id) {
00063             $mform->setDefault('criteria_course['.$data->id.']', 1);
00064         }
00065     }
00066 
00073     public function update_config(&$data) {
00074 
00075         if (!empty($data->criteria_course) && is_array($data->criteria_course)) {
00076 
00077             $this->course = $data->id;
00078 
00079             foreach ($data->criteria_course as $course) {
00080 
00081                 $this->courseinstance = $course;
00082                 $this->id = NULL;
00083                 $this->insert();
00084             }
00085         }
00086     }
00087 
00095     public function review($completion, $mark = true) {
00096         global $DB;
00097 
00098         $course = $DB->get_record('course', array('id' => $this->courseinstance));
00099         $info = new completion_info($course);
00100 
00101         // If the course is complete
00102         if ($info->is_course_complete($completion->userid)) {
00103 
00104             if ($mark) {
00105                 $completion->mark_complete();
00106             }
00107 
00108             return true;
00109         }
00110 
00111         return false;
00112     }
00113 
00119     public function get_title() {
00120         return get_string('prerequisitescompleted', 'completion');
00121     }
00122 
00128     public function get_title_detailed() {
00129         global $DB;
00130 
00131         $prereq = $DB->get_record('course', array('id' => $this->courseinstance));
00132         $coursecontext = get_context_instance(CONTEXT_COURSE, $prereq->id, MUST_EXIST);
00133         $fullname = format_string($prereq->fullname, true, array('context' => $coursecontext));
00134         return shorten_text(urldecode($fullname));
00135     }
00136 
00142     public function get_type_title() {
00143         return get_string('prerequisites', 'completion');
00144     }
00145 
00151     public function cron() {
00152 
00153         global $DB;
00154 
00155         // Get all users who meet this criteria
00156         $sql = "
00157             SELECT DISTINCT
00158                 c.id AS course,
00159                 cr.id AS criteriaid,
00160                 ra.userid AS userid,
00161                 cc.timecompleted AS timecompleted
00162             FROM
00163                 {course_completion_criteria} cr
00164             INNER JOIN
00165                 {course} c
00166              ON cr.course = c.id
00167             INNER JOIN
00168                 {context} con
00169              ON con.instanceid = c.id
00170             INNER JOIN
00171                 {role_assignments} ra
00172               ON ra.contextid = con.id
00173             INNER JOIN
00174                 {course_completions} cc
00175              ON cc.course = cr.courseinstance
00176             AND cc.userid = ra.userid
00177             LEFT JOIN
00178                 {course_completion_crit_compl} ccc
00179              ON ccc.criteriaid = cr.id
00180             AND ccc.userid = ra.userid
00181             WHERE
00182                 cr.criteriatype = ".COMPLETION_CRITERIA_TYPE_COURSE."
00183             AND con.contextlevel = ".CONTEXT_COURSE."
00184             AND c.enablecompletion = 1
00185             AND ccc.id IS NULL
00186             AND cc.timecompleted IS NOT NULL
00187         ";
00188 
00189         // Loop through completions, and mark as complete
00190         $rs = $DB->get_recordset_sql($sql);
00191         foreach ($rs as $record) {
00192             $completion = new completion_criteria_completion((array)$record);
00193             $completion->mark_complete($record->timecompleted);
00194         }
00195         $rs->close();
00196     }
00197 
00204     public function get_details($completion) {
00205         global $CFG, $DB;
00206 
00207         // Get completion info
00208         $course = new stdClass();
00209         $course->id = $completion->course;
00210         $info = new completion_info($course);
00211 
00212         $prereq = $DB->get_record('course', array('id' => $this->courseinstance));
00213         $coursecontext = get_context_instance(CONTEXT_COURSE, $prereq->id, MUST_EXIST);
00214         $fullname = format_string($prereq->fullname, true, array('context' => $coursecontext));
00215 
00216         $prereq_info = new completion_info($prereq);
00217 
00218         $details = array();
00219         $details['type'] = $this->get_title();
00220         $details['criteria'] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$this->courseinstance.'">'.s($fullname).'</a>';
00221         $details['requirement'] = get_string('coursecompleted', 'completion');
00222         $details['status'] = '<a href="'.$CFG->wwwroot.'/blocks/completionstatus/details.php?course='.$this->courseinstance.'">'.get_string('seedetails', 'completion').'</a>';
00223 
00224         return $details;
00225     }
00226 }
 All Data Structures Namespaces Files Functions Variables Enumerations