MDL-18910 moving modedit features to modname_supports()
[moodle.git] / mod / label / lib.php
CommitLineData
41905731 1<?php // $Id$
2c5c3e62 2
3/// Library of functions and constants for module label
4
5
6define("LABEL_MAX_NAME_LENGTH", 50);
7
376ca347 8function get_label_name($label) {
9 $textlib = textlib_get_instance();
10
57eb939e 11 $name = strip_tags(format_string($label->content,true));
a38f1292 12 if ($textlib->strlen($name) > LABEL_MAX_NAME_LENGTH) {
13 $name = $textlib->substr($name, 0, LABEL_MAX_NAME_LENGTH)."...";
376ca347 14 }
15
16 if (empty($name)) {
17 // arbitrary name
c0a578c0 18 $name = get_string('modulename','label');
376ca347 19 }
20
21 return $name;
22}
23
2c5c3e62 24function label_add_instance($label) {
c18269c7 25 global $DB;
2c5c3e62 26/// Given an object containing all the necessary data,
7cac0c4b 27/// (defined by the form in mod_form.php) this function
2c5c3e62 28/// will create a new instance and return the id number
29/// of the new instance.
30
376ca347 31 $label->name = get_label_name($label);
2c5c3e62 32 $label->timemodified = time();
33
c18269c7 34 return $DB->insert_record("label", $label);
2c5c3e62 35}
36
37
38function label_update_instance($label) {
c18269c7 39 global $DB;
2c5c3e62 40/// Given an object containing all the necessary data,
7cac0c4b 41/// (defined by the form in mod_form.php) this function
2c5c3e62 42/// will update an existing instance with new data.
2bf5b5d4 43
376ca347 44 $label->name = get_label_name($label);
2c5c3e62 45 $label->timemodified = time();
46 $label->id = $label->instance;
47
c18269c7 48 return $DB->update_record("label", $label);
2c5c3e62 49}
50
51
52function label_delete_instance($id) {
c18269c7 53 global $DB;
2c5c3e62 54/// Given an ID of an instance of this module,
55/// this function will permanently delete the instance
56/// and any data that depends on it.
57
c18269c7 58 if (! $label = $DB->get_record("label", array("id"=>$id))) {
2c5c3e62 59 return false;
60 }
61
62 $result = true;
63
c18269c7 64 if (! $DB->delete_records("label", array("id"=>$label->id))) {
2c5c3e62 65 $result = false;
66 }
67
68 return $result;
69}
70
2b9f0625 71function label_get_participants($labelid) {
72//Returns the users with data in one resource
2185622e 73//(NONE, but must exist on EVERY mod !!)
2b9f0625 74
75 return false;
76}
77
f36cbf1d 78/**
79 * Given a course_module object, this function returns any
80 * "extra" information that may be needed when printing
81 * this activity in a course listing.
82 * See get_array_of_activities() in course/lib.php
83 */
8dddba42 84function label_get_coursemodule_info($coursemodule) {
1b81b0a4 85 global $DB;
86
87 if ($label = $DB->get_record('label', array('id'=>$coursemodule->instance), 'id, content, name')) {
d02f1934 88 if (empty($label->name)) {
89 // label name missing, fix it
90 $label->name = "label{$label->id}";
91 $DB->set_field('label', 'name', $label->name, array('id'=>$label->id));
92 }
dd97c328 93 $info = new object();
1ea543df 94 $info->extra = urlencode($label->content);
95 $info->name = urlencode($label->name);
dd97c328 96 return $info;
97 } else {
98 return null;
99 }
8dddba42 100}
101
f3221af9 102function label_get_view_actions() {
103 return array();
104}
105
106function label_get_post_actions() {
107 return array();
108}
109
89bfeee0 110function label_get_types() {
111 $types = array();
112
113 $type = new object();
114 $type->modclass = MOD_CLASS_RESOURCE;
115 $type->type = "label";
116 $type->typestr = get_string('resourcetypelabel', 'resource');
117 $types[] = $type;
118
119 return $types;
120}
0b5a80a1 121
122/**
123 * This function is used by the reset_course_userdata function in moodlelib.
124 * @param $data the data submitted from the reset course.
125 * @return array status array
126 */
127function label_reset_userdata($data) {
128 return array();
129}
130
f432bebf 131/**
132 * Returns all other caps used in module
133 */
134function lable_get_extra_capabilities() {
135 return array('moodle/site:accessallgroups');
136}
137
42f103be 138/**
139 * @param string $feature FEATURE_xx constant for requested feature
140 * @return mixed True if module supports feature, null if doesn't know
141 */
142function label_supports($feature) {
143 switch($feature) {
144 case FEATURE_IDNUMBER: return false;
145 case FEATURE_GROUPS: return false;
146 case FEATURE_GROUPINGS: return false;
147 case FEATURE_GROUPMEMBERSONLY: return true;
148 case FEATURE_MODEDIT_INTRO_EDITOR: return false;
149 case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
150 case FEATURE_GRADE_HAS_GRADE: return false;
151 case FEATURE_GRADE_OUTCOMES: return false;
152
153 default: return null;
154 }
155}
156
2c5c3e62 157?>