3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * Library of functions and constants for module 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);
33 * @uses LABEL_MAX_NAME_LENGTH
34 * @param object $label
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
)."...";
47 $name = get_string('modulename','label');
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.
59 * @param object $label
62 function label_add_instance($label) {
65 $label->name
= get_label_name($label);
66 $label->timemodified
= time();
68 return $DB->insert_record("label", $label);
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.
77 * @param object $label
80 function label_update_instance($label) {
83 $label->name
= get_label_name($label);
84 $label->timemodified
= time();
85 $label->id
= $label->instance
;
87 return $DB->update_record("label", $label);
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.
99 function label_delete_instance($id) {
102 if (! $label = $DB->get_record("label", array("id"=>$id))) {
108 if (! $DB->delete_records("label", array("id"=>$label->id
))) {
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) {
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
133 * @param object $coursemodule
134 * @return object|null
136 function label_get_coursemodule_info($coursemodule) {
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
;
158 function label_get_view_actions() {
165 function label_get_post_actions() {
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) {
180 * Returns all other caps used in module
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) {
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;