|
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_role extends completion_criteria { 00027 00032 public $criteriatype = COMPLETION_CRITERIA_TYPE_ROLE; 00033 00041 public static function fetch($params) { 00042 $params['criteriatype'] = COMPLETION_CRITERIA_TYPE_ROLE; 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_role['.$data->id.']', $data->name); 00056 00057 if ($this->id) { 00058 $mform->setDefault('criteria_role['.$data->id.']', 1); 00059 } 00060 } 00061 00068 public function update_config(&$data) { 00069 00070 if (!empty($data->criteria_role) && is_array($data->criteria_role)) { 00071 00072 $this->course = $data->id; 00073 00074 foreach (array_keys($data->criteria_role) as $role) { 00075 00076 $this->role = $role; 00077 $this->id = NULL; 00078 $this->insert(); 00079 } 00080 } 00081 } 00082 00089 public function complete($completion) { 00090 $this->review($completion, true, true); 00091 } 00092 00100 public function review($completion, $mark = true, $is_complete = false) { 00101 // If we are marking this as complete 00102 if ($is_complete && $mark) 00103 { 00104 $completion->completedself = 1; 00105 $completion->mark_complete(); 00106 00107 return true; 00108 } 00109 00110 return $completion->is_complete(); 00111 } 00112 00118 public function get_title() { 00119 global $DB; 00120 $role = $DB->get_field('role', 'name', array('id' => $this->role)); 00121 return $role; 00122 } 00123 00129 public function get_title_detailed() { 00130 global $DB; 00131 return $DB->get_field('role', 'name', array('id' => $this->role)); 00132 } 00133 00139 public function get_type_title() { 00140 return get_string('approval', 'completion'); 00141 } 00142 00149 public function get_details($completion) { 00150 $details = array(); 00151 $details['type'] = get_string('manualcompletionby', 'completion'); 00152 $details['criteria'] = $this->get_title(); 00153 $details['requirement'] = get_string('markedcompleteby', 'completion', $details['criteria']); 00154 $details['status'] = ''; 00155 00156 return $details; 00157 } 00158 }