|
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 00018 00027 require_once($CFG->libdir.'/completion/data_object.php'); 00028 00029 00033 class completion_completion extends data_object { 00034 00039 public $table = 'course_completions'; 00040 00045 public $required_fields = array('id', 'userid', 'course', 'deleted', 'timenotified', 00046 'timeenrolled', 'timestarted', 'timecompleted', 'reaggregate'); 00047 00053 public $userid; 00054 00060 public $course; 00061 00067 public $deleted; 00068 00075 public $timenotified; 00076 00083 public $timeenrolled; 00084 00091 public $timestarted; 00092 00099 public $timecompleted; 00100 00106 public $reaggregate; 00107 00108 00116 public static function fetch($params) { 00117 $params['deleted'] = null; 00118 return self::fetch_helper('course_completions', __CLASS__, $params); 00119 } 00120 00126 public function is_complete() { 00127 return (bool) $this->timecompleted; 00128 } 00129 00139 public function mark_enrolled($timeenrolled = null) { 00140 00141 if ($this->timeenrolled === null) { 00142 00143 if ($timeenrolled === null) { 00144 $timeenrolled = time(); 00145 } 00146 00147 $this->timeenrolled = $timeenrolled; 00148 } 00149 00150 $this->_save(); 00151 } 00152 00163 public function mark_inprogress($timestarted = null) { 00164 00165 $timenow = time(); 00166 00167 // Set reaggregate flag 00168 $this->reaggregate = $timenow; 00169 00170 if (!$this->timestarted) { 00171 00172 if (!$timestarted) { 00173 $timestarted = $timenow; 00174 } 00175 00176 $this->timestarted = $timestarted; 00177 } 00178 00179 $this->_save(); 00180 } 00181 00192 public function mark_complete($timecomplete = null) { 00193 00194 // Never change a completion time 00195 if ($this->timecompleted) { 00196 return; 00197 } 00198 00199 // Use current time if nothing supplied 00200 if (!$timecomplete) { 00201 $timecomplete = time(); 00202 } 00203 00204 // Set time complete 00205 $this->timecompleted = $timecomplete; 00206 00207 // Save record 00208 $this->_save(); 00209 } 00210 00218 private function _save() { 00219 00220 global $DB; 00221 00222 if ($this->timeenrolled === null) { 00223 $this->timeenrolled = 0; 00224 } 00225 00226 // Save record 00227 if ($this->id) { 00228 $this->update(); 00229 } else { 00230 // Make sure reaggregate field is not null 00231 if (!$this->reaggregate) { 00232 $this->reaggregate = 0; 00233 } 00234 00235 // Make sure timestarted is not null 00236 if (!$this->timestarted) { 00237 $this->timestarted = 0; 00238 } 00239 00240 $this->insert(); 00241 } 00242 } 00243 }