Updated the 19 build version to 20101023
[moodle.git] / mod / label / lib.php
blobdd00c6d61697c677c87607064034bb8bcbfb0800
1 <?php // $Id$
3 /// Library of functions and constants for module label
6 define("LABEL_MAX_NAME_LENGTH", 50);
8 function get_label_name($label) {
9 $textlib = textlib_get_instance();
11 $name = addslashes(strip_tags(format_string(stripslashes($label->content),true)));
12 if ($textlib->strlen($name) > LABEL_MAX_NAME_LENGTH) {
13 $name = $textlib->substr($name, 0, LABEL_MAX_NAME_LENGTH)."...";
16 if (empty($name)) {
17 // arbitrary name
18 $name = get_string('modulename','label');
21 return $name;
24 function label_add_instance($label) {
25 /// Given an object containing all the necessary data,
26 /// (defined by the form in mod.html) this function
27 /// will create a new instance and return the id number
28 /// of the new instance.
30 $label->name = get_label_name($label);
31 $label->timemodified = time();
33 return insert_record("label", $label);
37 function label_update_instance($label) {
38 /// Given an object containing all the necessary data,
39 /// (defined by the form in mod.html) this function
40 /// will update an existing instance with new data.
42 $label->name = get_label_name($label);
43 $label->timemodified = time();
44 $label->id = $label->instance;
46 return update_record("label", $label);
50 function label_delete_instance($id) {
51 /// Given an ID of an instance of this module,
52 /// this function will permanently delete the instance
53 /// and any data that depends on it.
55 if (! $label = get_record("label", "id", "$id")) {
56 return false;
59 $result = true;
61 if (! delete_records("label", "id", "$label->id")) {
62 $result = false;
65 return $result;
68 function label_get_participants($labelid) {
69 //Returns the users with data in one resource
70 //(NONE, but must exist on EVERY mod !!)
72 return false;
75 /**
76 * Given a course_module object, this function returns any
77 * "extra" information that may be needed when printing
78 * this activity in a course listing.
79 * See get_array_of_activities() in course/lib.php
81 function label_get_coursemodule_info($coursemodule) {
82 if ($label = get_record('label', 'id', $coursemodule->instance, '', '', '', '', 'id, content, name')) {
83 if (empty($label->name)) {
84 // label name missing, fix it
85 $label->name = "label{$label->id}";
86 set_field('label', 'name', $label->name, 'id', $label->id);
88 $info = new object();
89 $info->extra = urlencode($label->content);
90 $info->name = urlencode($label->name);
91 return $info;
92 } else {
93 return null;
97 function label_get_view_actions() {
98 return array();
101 function label_get_post_actions() {
102 return array();
105 function label_get_types() {
106 $types = array();
108 $type = new object();
109 $type->modclass = MOD_CLASS_RESOURCE;
110 $type->type = "label";
111 $type->typestr = get_string('resourcetypelabel', 'resource');
112 $types[] = $type;
114 return $types;
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
122 function label_reset_userdata($data) {
123 return array();
127 * Returns all other caps used in module
129 function label_get_extra_capabilities() {
130 return array('moodle/site:accessallgroups');