Updated the HEAD build version to 20090528
[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
43b44d5e 11 $name = strip_tags(format_string($label->intro,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
43b44d5e 87 if ($label = $DB->get_record('label', array('id'=>$coursemodule->instance), 'id, name, intro, introformat')) {
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();
43b44d5e 94 // no filtering hre because this info is cached and filtered later
95 $info->extra = urlencode(format_module_intro('label', $label, $coursemodule->id, false));
96 $info->name = urlencode($label->name);
dd97c328 97 return $info;
98 } else {
99 return null;
100 }
8dddba42 101}
102
f3221af9 103function label_get_view_actions() {
104 return array();
105}
106
107function label_get_post_actions() {
108 return array();
109}
110
89bfeee0 111function label_get_types() {
112 $types = array();
113
114 $type = new object();
115 $type->modclass = MOD_CLASS_RESOURCE;
116 $type->type = "label";
117 $type->typestr = get_string('resourcetypelabel', 'resource');
118 $types[] = $type;
119
120 return $types;
121}
0b5a80a1 122
123/**
124 * This function is used by the reset_course_userdata function in moodlelib.
125 * @param $data the data submitted from the reset course.
126 * @return array status array
127 */
128function label_reset_userdata($data) {
129 return array();
130}
131
f432bebf 132/**
133 * Returns all other caps used in module
134 */
135function lable_get_extra_capabilities() {
136 return array('moodle/site:accessallgroups');
137}
138
42f103be 139/**
140 * @param string $feature FEATURE_xx constant for requested feature
141 * @return mixed True if module supports feature, null if doesn't know
142 */
143function label_supports($feature) {
144 switch($feature) {
145 case FEATURE_IDNUMBER: return false;
146 case FEATURE_GROUPS: return false;
147 case FEATURE_GROUPINGS: return false;
148 case FEATURE_GROUPMEMBERSONLY: return true;
43b44d5e 149 case FEATURE_MOD_INTRO: return true;
42f103be 150 case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
151 case FEATURE_GRADE_HAS_GRADE: return false;
152 case FEATURE_GRADE_OUTCOMES: return false;
153
154 default: return null;
155 }
156}
157
2c5c3e62 158?>