|
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 00027 defined('MOODLE_INTERNAL') || die; 00028 00030 define("LABEL_MAX_NAME_LENGTH", 50); 00031 00037 function get_label_name($label) { 00038 $textlib = textlib_get_instance(); 00039 00040 $name = strip_tags(format_string($label->intro,true)); 00041 if ($textlib->strlen($name) > LABEL_MAX_NAME_LENGTH) { 00042 $name = $textlib->substr($name, 0, LABEL_MAX_NAME_LENGTH)."..."; 00043 } 00044 00045 if (empty($name)) { 00046 // arbitrary name 00047 $name = get_string('modulename','label'); 00048 } 00049 00050 return $name; 00051 } 00062 function label_add_instance($label) { 00063 global $DB; 00064 00065 $label->name = get_label_name($label); 00066 $label->timemodified = time(); 00067 00068 return $DB->insert_record("label", $label); 00069 } 00070 00080 function label_update_instance($label) { 00081 global $DB; 00082 00083 $label->name = get_label_name($label); 00084 $label->timemodified = time(); 00085 $label->id = $label->instance; 00086 00087 return $DB->update_record("label", $label); 00088 } 00089 00099 function label_delete_instance($id) { 00100 global $DB; 00101 00102 if (! $label = $DB->get_record("label", array("id"=>$id))) { 00103 return false; 00104 } 00105 00106 $result = true; 00107 00108 if (! $DB->delete_records("label", array("id"=>$label->id))) { 00109 $result = false; 00110 } 00111 00112 return $result; 00113 } 00114 00123 function label_get_participants($labelid) { 00124 00125 return false; 00126 } 00127 00138 function label_get_coursemodule_info($coursemodule) { 00139 global $DB; 00140 00141 if ($label = $DB->get_record('label', array('id'=>$coursemodule->instance), 'id, name, intro, introformat')) { 00142 if (empty($label->name)) { 00143 // label name missing, fix it 00144 $label->name = "label{$label->id}"; 00145 $DB->set_field('label', 'name', $label->name, array('id'=>$label->id)); 00146 } 00147 $info = new stdClass(); 00148 // no filtering hre because this info is cached and filtered later 00149 $info->extra = format_module_intro('label', $label, $coursemodule->id, false); 00150 $info->name = $label->name; 00151 return $info; 00152 } else { 00153 return null; 00154 } 00155 } 00156 00160 function label_get_view_actions() { 00161 return array(); 00162 } 00163 00167 function label_get_post_actions() { 00168 return array(); 00169 } 00170 00177 function label_reset_userdata($data) { 00178 return array(); 00179 } 00180 00186 function label_get_extra_capabilities() { 00187 return array('moodle/site:accessallgroups'); 00188 } 00189 00202 function label_supports($feature) { 00203 switch($feature) { 00204 case FEATURE_IDNUMBER: return false; 00205 case FEATURE_GROUPS: return false; 00206 case FEATURE_GROUPINGS: return false; 00207 case FEATURE_GROUPMEMBERSONLY: return true; 00208 case FEATURE_MOD_INTRO: return true; 00209 case FEATURE_COMPLETION_TRACKS_VIEWS: return false; 00210 case FEATURE_GRADE_HAS_GRADE: return false; 00211 case FEATURE_GRADE_OUTCOMES: return false; 00212 case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE; 00213 case FEATURE_BACKUP_MOODLE2: return true; 00214 case FEATURE_NO_VIEW_LINK: return true; 00215 00216 default: return null; 00217 } 00218 } 00219