|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00026 class completion_criteria_date extends completion_criteria { 00027 00032 public $criteriatype = COMPLETION_CRITERIA_TYPE_DATE; 00033 00041 public static function fetch($params) { 00042 $params['criteriatype'] = COMPLETION_CRITERIA_TYPE_DATE; 00043 return self::fetch_helper('course_completion_criteria', __CLASS__, $params); 00044 } 00045 00053 public function config_form_display(&$mform, $data = null) 00054 { 00055 $mform->addElement('checkbox', 'criteria_date', get_string('enable')); 00056 $mform->addElement('date_selector', 'criteria_date_value', get_string('afterspecifieddate', 'completion')); 00057 00058 // If instance of criteria exists 00059 if ($this->id) { 00060 $mform->setDefault('criteria_date', 1); 00061 $mform->setDefault('criteria_date_value', $this->timeend); 00062 } else { 00063 $mform->setDefault('criteria_date_value', time() + 3600 * 24); 00064 } 00065 } 00066 00073 public function update_config(&$data) { 00074 00075 if (!empty($data->criteria_date)) { 00076 $this->course = $data->id; 00077 $this->timeend = $data->criteria_date_value; 00078 $this->insert(); 00079 } 00080 } 00081 00089 public function review($completion, $mark = true) 00090 { 00091 // If current time is past timeend 00092 if ($this->timeend && $this->timeend < time()) { 00093 if ($mark) { 00094 $completion->mark_complete(); 00095 } 00096 00097 return true; 00098 } 00099 00100 return false; 00101 } 00102 00108 public function get_title() { 00109 return get_string('date'); 00110 } 00111 00117 public function get_title_detailed() { 00118 return userdate($this->timeend, '%d-%h-%y'); 00119 } 00120 00126 public function get_type_title() { 00127 return get_string('date'); 00128 } 00129 00130 00137 public function get_status($completion) { 00138 return $completion->is_complete() ? get_string('yes') : userdate($this->timeend, '%d-%h-%y'); 00139 } 00140 00146 public function cron() { 00147 global $DB; 00148 00149 // Get all users who match meet this criteria 00150 $sql = ' 00151 SELECT DISTINCT 00152 c.id AS course, 00153 cr.timeend AS timeend, 00154 cr.id AS criteriaid, 00155 ra.userid AS userid 00156 FROM 00157 {course_completion_criteria} cr 00158 INNER JOIN 00159 {course} c 00160 ON cr.course = c.id 00161 INNER JOIN 00162 {context} con 00163 ON con.instanceid = c.id 00164 INNER JOIN 00165 {role_assignments} ra 00166 ON ra.contextid = con.id 00167 LEFT JOIN 00168 {course_completion_crit_compl} cc 00169 ON cc.criteriaid = cr.id 00170 AND cc.userid = ra.userid 00171 WHERE 00172 cr.criteriatype = '.COMPLETION_CRITERIA_TYPE_DATE.' 00173 AND con.contextlevel = '.CONTEXT_COURSE.' 00174 AND c.enablecompletion = 1 00175 AND cc.id IS NULL 00176 AND cr.timeend < ? 00177 '; 00178 00179 // Loop through completions, and mark as complete 00180 $rs = $DB->get_recordset_sql($sql, array(time())); 00181 foreach ($rs as $record) { 00182 $completion = new completion_criteria_completion((array)$record); 00183 $completion->mark_complete($record->timeend); 00184 } 00185 $rs->close(); 00186 } 00187 00194 public function get_details($completion) { 00195 $details = array(); 00196 $details['type'] = get_string('datepassed', 'completion'); 00197 $details['criteria'] = get_string('remainingenroleduntildate', 'completion'); 00198 $details['requirement'] = userdate($this->timeend, '%d %B %Y'); 00199 $details['status'] = ''; 00200 00201 return $details; 00202 } 00203 }