MDL-21250 capital letters removal and greylisted string removal
[moodle.git] / mod / label / lib.php
bloba80a08d10828d7bdd47ed9e5a148ed4d1d379b9e
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Library of functions and constants for module label
21 * @package mod
22 * @subpackage label
23 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die;
29 /** LABEL_MAX_NAME_LENGTH = 50 */
30 define("LABEL_MAX_NAME_LENGTH", 50);
32 /**
33 * @uses LABEL_MAX_NAME_LENGTH
34 * @param object $label
35 * @return string
37 function get_label_name($label) {
38 $textlib = textlib_get_instance();
40 $name = strip_tags(format_string($label->intro,true));
41 if ($textlib->strlen($name) > LABEL_MAX_NAME_LENGTH) {
42 $name = $textlib->substr($name, 0, LABEL_MAX_NAME_LENGTH)."...";
45 if (empty($name)) {
46 // arbitrary name
47 $name = get_string('modulename','label');
50 return $name;
52 /**
53 * Given an object containing all the necessary data,
54 * (defined by the form in mod_form.php) this function
55 * will create a new instance and return the id number
56 * of the new instance.
58 * @global object
59 * @param object $label
60 * @return bool|int
62 function label_add_instance($label) {
63 global $DB;
65 $label->name = get_label_name($label);
66 $label->timemodified = time();
68 return $DB->insert_record("label", $label);
71 /**
72 * Given an object containing all the necessary data,
73 * (defined by the form in mod_form.php) this function
74 * will update an existing instance with new data.
76 * @global object
77 * @param object $label
78 * @return bool
80 function label_update_instance($label) {
81 global $DB;
83 $label->name = get_label_name($label);
84 $label->timemodified = time();
85 $label->id = $label->instance;
87 return $DB->update_record("label", $label);
90 /**
91 * Given an ID of an instance of this module,
92 * this function will permanently delete the instance
93 * and any data that depends on it.
95 * @global object
96 * @param int $id
97 * @return bool
99 function label_delete_instance($id) {
100 global $DB;
102 if (! $label = $DB->get_record("label", array("id"=>$id))) {
103 return false;
106 $result = true;
108 if (! $DB->delete_records("label", array("id"=>$label->id))) {
109 $result = false;
112 return $result;
116 * Returns the users with data in one resource
117 * (NONE, but must exist on EVERY mod !!)
119 * @param int $labelid
121 function label_get_participants($labelid) {
123 return false;
127 * Given a course_module object, this function returns any
128 * "extra" information that may be needed when printing
129 * this activity in a course listing.
130 * See get_array_of_activities() in course/lib.php
132 * @global object
133 * @param object $coursemodule
134 * @return object|null
136 function label_get_coursemodule_info($coursemodule) {
137 global $DB;
139 if ($label = $DB->get_record('label', array('id'=>$coursemodule->instance), 'id, name, intro, introformat')) {
140 if (empty($label->name)) {
141 // label name missing, fix it
142 $label->name = "label{$label->id}";
143 $DB->set_field('label', 'name', $label->name, array('id'=>$label->id));
145 $info = new stdClass();
146 // no filtering hre because this info is cached and filtered later
147 $info->extra = format_module_intro('label', $label, $coursemodule->id, false);
148 $info->name = $label->name;
149 return $info;
150 } else {
151 return null;
156 * @return array
158 function label_get_view_actions() {
159 return array();
163 * @return array
165 function label_get_post_actions() {
166 return array();
170 * This function is used by the reset_course_userdata function in moodlelib.
172 * @param object $data the data submitted from the reset course.
173 * @return array status array
175 function label_reset_userdata($data) {
176 return array();
180 * Returns all other caps used in module
182 * @return array
184 function lable_get_extra_capabilities() {
185 return array('moodle/site:accessallgroups');
189 * @uses FEATURE_IDNUMBER
190 * @uses FEATURE_GROUPS
191 * @uses FEATURE_GROUPINGS
192 * @uses FEATURE_GROUPMEMBERSONLY
193 * @uses FEATURE_MOD_INTRO
194 * @uses FEATURE_COMPLETION_TRACKS_VIEWS
195 * @uses FEATURE_GRADE_HAS_GRADE
196 * @uses FEATURE_GRADE_OUTCOMES
197 * @param string $feature FEATURE_xx constant for requested feature
198 * @return bool|null True if module supports feature, false if not, null if doesn't know
200 function label_supports($feature) {
201 switch($feature) {
202 case FEATURE_IDNUMBER: return false;
203 case FEATURE_GROUPS: return false;
204 case FEATURE_GROUPINGS: return false;
205 case FEATURE_GROUPMEMBERSONLY: return true;
206 case FEATURE_MOD_INTRO: return true;
207 case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
208 case FEATURE_GRADE_HAS_GRADE: return false;
209 case FEATURE_GRADE_OUTCOMES: return false;
210 case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE;
211 case FEATURE_BACKUP_MOODLE2: return true;
213 default: return null;