MDL-15545 "sql to fetch question states in overview report should use a JOIN instead...
[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
18 $name = "label{$label->instance}";
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')) {
dd97c328 88 $info = new object();
1ea543df 89 $info->extra = urlencode($label->content);
90 $info->name = urlencode($label->name);
dd97c328 91 return $info;
92 } else {
93 return null;
94 }
8dddba42 95}
96
f3221af9 97function label_get_view_actions() {
98 return array();
99}
100
101function label_get_post_actions() {
102 return array();
103}
104
89bfeee0 105function label_get_types() {
106 $types = array();
107
108 $type = new object();
109 $type->modclass = MOD_CLASS_RESOURCE;
110 $type->type = "label";
111 $type->typestr = get_string('resourcetypelabel', 'resource');
112 $types[] = $type;
113
114 return $types;
115}
0b5a80a1 116
117/**
118 * This function is used by the reset_course_userdata function in moodlelib.
119 * @param $data the data submitted from the reset course.
120 * @return array status array
121 */
122function label_reset_userdata($data) {
123 return array();
124}
125
2c5c3e62 126?>