|
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 require_once($CFG->libdir.'/completion/data_object.php'); 00027 00028 00032 class completion_criteria_completion extends data_object { 00033 00038 public $table = 'course_completion_crit_compl'; 00039 00044 public $required_fields = array('id', 'userid', 'course', 'criteriaid', 'gradefinal', 'rpl', 'deleted', 'unenroled', 'timecompleted'); 00045 00051 public $userid; 00052 00058 public $course; 00059 00065 public $criteriaid; 00066 00072 public $gradefinal; 00073 00079 public $rpl; 00080 00086 public $deleted; 00087 00093 public $unenroled; 00094 00101 public $timecompleted; 00102 00108 private $_criteria; 00109 00117 public static function fetch($params) { 00118 $params['deleted'] = null; 00119 return self::fetch_helper('course_completion_crit_compl', __CLASS__, $params); 00120 } 00121 00129 public static function fetch_all($params) {} 00130 00136 public function is_complete() { 00137 return (bool) $this->timecompleted; 00138 } 00139 00147 public function mark_complete() { 00148 // Create record 00149 $this->timecompleted = time(); 00150 00151 // Save record 00152 if ($this->id) { 00153 $this->update(); 00154 } else { 00155 $this->insert(); 00156 } 00157 00158 // Mark course completion record as started (if not already) 00159 $cc = array( 00160 'course' => $this->course, 00161 'userid' => $this->userid 00162 ); 00163 $ccompletion = new completion_completion($cc); 00164 $ccompletion->mark_inprogress($this->timecompleted); 00165 } 00166 00173 public function attach_criteria(completion_criteria $criteria) { 00174 $this->_criteria = $criteria; 00175 } 00176 00183 public function get_criteria() { 00184 00185 if (!$this->_criteria) 00186 { 00187 global $DB; 00188 00189 $params = array( 00190 'id' => $this->criteriaid 00191 ); 00192 00193 $record = $DB->get_record('course_completion_criteria', $params); 00194 00195 $this->attach_criteria(completion_criteria::factory($record)); 00196 } 00197 00198 return $this->_criteria; 00199 } 00200 00207 public function get_status() { 00208 return $this->_criteria->get_status($this); 00209 } 00210 }