MDL-14905 Added more unit tests, plus stubs for all methods to be tested. Also fixed...
[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
8function label_add_instance($label) {
c18269c7 9 global $DB;
2c5c3e62 10/// Given an object containing all the necessary data,
7cac0c4b 11/// (defined by the form in mod_form.php) this function
2c5c3e62 12/// will create a new instance and return the id number
13/// of the new instance.
a8f5a8a2 14 $textlib = textlib_get_instance();
2c5c3e62 15
c18269c7 16 $label->name = strip_tags(format_string($label->content));
810944af 17 if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) {
18 $label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."...";
2c5c3e62 19 }
20 $label->timemodified = time();
21
c18269c7 22 return $DB->insert_record("label", $label);
2c5c3e62 23}
24
25
26function label_update_instance($label) {
c18269c7 27 global $DB;
2c5c3e62 28/// Given an object containing all the necessary data,
7cac0c4b 29/// (defined by the form in mod_form.php) this function
2c5c3e62 30/// will update an existing instance with new data.
a8f5a8a2 31 $textlib = textlib_get_instance();
2bf5b5d4 32
c18269c7 33 $label->name = strip_tags(format_string($label->content));
810944af 34 if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) {
35 $label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."...";
2c5c3e62 36 }
37 $label->timemodified = time();
38 $label->id = $label->instance;
39
c18269c7 40 return $DB->update_record("label", $label);
2c5c3e62 41}
42
43
44function label_delete_instance($id) {
c18269c7 45 global $DB;
2c5c3e62 46/// Given an ID of an instance of this module,
47/// this function will permanently delete the instance
48/// and any data that depends on it.
49
c18269c7 50 if (! $label = $DB->get_record("label", array("id"=>$id))) {
2c5c3e62 51 return false;
52 }
53
54 $result = true;
55
c18269c7 56 if (! $DB->delete_records("label", array("id"=>$label->id))) {
2c5c3e62 57 $result = false;
58 }
59
60 return $result;
61}
62
2b9f0625 63function label_get_participants($labelid) {
64//Returns the users with data in one resource
2185622e 65//(NONE, but must exist on EVERY mod !!)
2b9f0625 66
67 return false;
68}
69
f36cbf1d 70/**
71 * Given a course_module object, this function returns any
72 * "extra" information that may be needed when printing
73 * this activity in a course listing.
74 * See get_array_of_activities() in course/lib.php
75 */
8dddba42 76function label_get_coursemodule_info($coursemodule) {
1b81b0a4 77 global $DB;
78
79 if ($label = $DB->get_record('label', array('id'=>$coursemodule->instance), 'id, content, name')) {
dd97c328 80 $info = new object();
1ea543df 81 $info->extra = urlencode($label->content);
82 $info->name = urlencode($label->name);
dd97c328 83 return $info;
84 } else {
85 return null;
86 }
8dddba42 87}
88
f3221af9 89function label_get_view_actions() {
90 return array();
91}
92
93function label_get_post_actions() {
94 return array();
95}
96
89bfeee0 97function label_get_types() {
98 $types = array();
99
100 $type = new object();
101 $type->modclass = MOD_CLASS_RESOURCE;
102 $type->type = "label";
103 $type->typestr = get_string('resourcetypelabel', 'resource');
104 $types[] = $type;
105
106 return $types;
107}
0b5a80a1 108
109/**
110 * This function is used by the reset_course_userdata function in moodlelib.
111 * @param $data the data submitted from the reset course.
112 * @return array status array
113 */
114function label_reset_userdata($data) {
115 return array();
116}
117
2c5c3e62 118?>