MDL-31950 - Label - Removing the deprecated label_get_participants function
[moodle.git] / mod / label / lib.php
CommitLineData
44a87f63 1<?php
2
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.
14//
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/>.
2c5c3e62 17
44a87f63 18/**
19 * Library of functions and constants for module label
20 *
9516942a
PS
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
44a87f63 25 */
2c5c3e62 26
9516942a
PS
27defined('MOODLE_INTERNAL') || die;
28
44a87f63 29/** LABEL_MAX_NAME_LENGTH = 50 */
2c5c3e62 30define("LABEL_MAX_NAME_LENGTH", 50);
31
44a87f63 32/**
33 * @uses LABEL_MAX_NAME_LENGTH
34 * @param object $label
35 * @return string
36 */
376ca347 37function get_label_name($label) {
43b44d5e 38 $name = strip_tags(format_string($label->intro,true));
f8311def
PS
39 if (textlib::strlen($name) > LABEL_MAX_NAME_LENGTH) {
40 $name = textlib::substr($name, 0, LABEL_MAX_NAME_LENGTH)."...";
376ca347 41 }
42
43 if (empty($name)) {
44 // arbitrary name
c0a578c0 45 $name = get_string('modulename','label');
376ca347 46 }
47
48 return $name;
49}
44a87f63 50/**
51 * Given an object containing all the necessary data,
52 * (defined by the form in mod_form.php) this function
53 * will create a new instance and return the id number
54 * of the new instance.
55 *
56 * @global object
57 * @param object $label
58 * @return bool|int
59 */
2c5c3e62 60function label_add_instance($label) {
c18269c7 61 global $DB;
2c5c3e62 62
376ca347 63 $label->name = get_label_name($label);
2c5c3e62 64 $label->timemodified = time();
65
c18269c7 66 return $DB->insert_record("label", $label);
2c5c3e62 67}
68
44a87f63 69/**
70 * Given an object containing all the necessary data,
71 * (defined by the form in mod_form.php) this function
72 * will update an existing instance with new data.
73 *
74 * @global object
75 * @param object $label
76 * @return bool
77 */
2c5c3e62 78function label_update_instance($label) {
c18269c7 79 global $DB;
2bf5b5d4 80
376ca347 81 $label->name = get_label_name($label);
2c5c3e62 82 $label->timemodified = time();
83 $label->id = $label->instance;
84
c18269c7 85 return $DB->update_record("label", $label);
2c5c3e62 86}
87
44a87f63 88/**
89 * Given an ID of an instance of this module,
90 * this function will permanently delete the instance
91 * and any data that depends on it.
92 *
93 * @global object
94 * @param int $id
95 * @return bool
96 */
2c5c3e62 97function label_delete_instance($id) {
c18269c7 98 global $DB;
2c5c3e62 99
c18269c7 100 if (! $label = $DB->get_record("label", array("id"=>$id))) {
2c5c3e62 101 return false;
102 }
103
104 $result = true;
105
c18269c7 106 if (! $DB->delete_records("label", array("id"=>$label->id))) {
2c5c3e62 107 $result = false;
108 }
109
110 return $result;
111}
112
f36cbf1d 113/**
114 * Given a course_module object, this function returns any
115 * "extra" information that may be needed when printing
116 * this activity in a course listing.
117 * See get_array_of_activities() in course/lib.php
44a87f63 118 *
119 * @global object
120 * @param object $coursemodule
121 * @return object|null
f36cbf1d 122 */
8dddba42 123function label_get_coursemodule_info($coursemodule) {
1b81b0a4 124 global $DB;
125
43b44d5e 126 if ($label = $DB->get_record('label', array('id'=>$coursemodule->instance), 'id, name, intro, introformat')) {
d02f1934 127 if (empty($label->name)) {
128 // label name missing, fix it
129 $label->name = "label{$label->id}";
130 $DB->set_field('label', 'name', $label->name, array('id'=>$label->id));
131 }
39790bd8 132 $info = new stdClass();
43b44d5e 133 // no filtering hre because this info is cached and filtered later
9a9012dc
PS
134 $info->extra = format_module_intro('label', $label, $coursemodule->id, false);
135 $info->name = $label->name;
dd97c328 136 return $info;
137 } else {
138 return null;
139 }
8dddba42 140}
141
44a87f63 142/**
143 * @return array
144 */
f3221af9 145function label_get_view_actions() {
146 return array();
147}
148
44a87f63 149/**
150 * @return array
151 */
f3221af9 152function label_get_post_actions() {
153 return array();
154}
155
0b5a80a1 156/**
157 * This function is used by the reset_course_userdata function in moodlelib.
86342d63 158 *
44a87f63 159 * @param object $data the data submitted from the reset course.
0b5a80a1 160 * @return array status array
161 */
162function label_reset_userdata($data) {
163 return array();
164}
165
f432bebf 166/**
167 * Returns all other caps used in module
44a87f63 168 *
169 * @return array
f432bebf 170 */
e83a6a22 171function label_get_extra_capabilities() {
f432bebf 172 return array('moodle/site:accessallgroups');
173}
174
42f103be 175/**
44a87f63 176 * @uses FEATURE_IDNUMBER
177 * @uses FEATURE_GROUPS
178 * @uses FEATURE_GROUPINGS
179 * @uses FEATURE_GROUPMEMBERSONLY
180 * @uses FEATURE_MOD_INTRO
181 * @uses FEATURE_COMPLETION_TRACKS_VIEWS
182 * @uses FEATURE_GRADE_HAS_GRADE
183 * @uses FEATURE_GRADE_OUTCOMES
42f103be 184 * @param string $feature FEATURE_xx constant for requested feature
44a87f63 185 * @return bool|null True if module supports feature, false if not, null if doesn't know
42f103be 186 */
187function label_supports($feature) {
188 switch($feature) {
189 case FEATURE_IDNUMBER: return false;
190 case FEATURE_GROUPS: return false;
191 case FEATURE_GROUPINGS: return false;
192 case FEATURE_GROUPMEMBERSONLY: return true;
43b44d5e 193 case FEATURE_MOD_INTRO: return true;
42f103be 194 case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
195 case FEATURE_GRADE_HAS_GRADE: return false;
196 case FEATURE_GRADE_OUTCOMES: return false;
31dadc6f 197 case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE;
f58a9e37 198 case FEATURE_BACKUP_MOODLE2: return true;
0d8b6a69 199 case FEATURE_NO_VIEW_LINK: return true;
42f103be 200
201 default: return null;
202 }
203}
204