2004-09-12 16:24:41 +00:00
|
|
|
<?php // $Id$
|
2003-09-14 12:30:09 +00:00
|
|
|
|
|
|
|
/// Library of functions and constants for module label
|
|
|
|
|
|
|
|
|
|
|
|
define("LABEL_MAX_NAME_LENGTH", 50);
|
|
|
|
|
2008-06-18 15:31:47 +00:00
|
|
|
function get_label_name($label) {
|
|
|
|
$textlib = textlib_get_instance();
|
|
|
|
|
2008-06-24 21:57:39 +00:00
|
|
|
$name = strip_tags(format_string($label->content,true));
|
2008-07-03 23:01:32 +00:00
|
|
|
if ($textlib->strlen($name) > LABEL_MAX_NAME_LENGTH) {
|
|
|
|
$name = $textlib->substr($name, 0, LABEL_MAX_NAME_LENGTH)."...";
|
2008-06-18 15:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($name)) {
|
|
|
|
// arbitrary name
|
2008-07-08 09:39:18 +00:00
|
|
|
$name = get_string('modulename','label');
|
2008-06-18 15:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
2003-09-14 12:30:09 +00:00
|
|
|
function label_add_instance($label) {
|
2008-06-01 21:36:11 +00:00
|
|
|
global $DB;
|
2003-09-14 12:30:09 +00:00
|
|
|
/// Given an object containing all the necessary data,
|
2008-06-01 19:09:13 +00:00
|
|
|
/// (defined by the form in mod_form.php) this function
|
2003-09-14 12:30:09 +00:00
|
|
|
/// will create a new instance and return the id number
|
|
|
|
/// of the new instance.
|
|
|
|
|
2008-06-18 15:31:47 +00:00
|
|
|
$label->name = get_label_name($label);
|
2003-09-14 12:30:09 +00:00
|
|
|
$label->timemodified = time();
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
return $DB->insert_record("label", $label);
|
2003-09-14 12:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function label_update_instance($label) {
|
2008-06-01 21:36:11 +00:00
|
|
|
global $DB;
|
2003-09-14 12:30:09 +00:00
|
|
|
/// Given an object containing all the necessary data,
|
2008-06-01 19:09:13 +00:00
|
|
|
/// (defined by the form in mod_form.php) this function
|
2003-09-14 12:30:09 +00:00
|
|
|
/// will update an existing instance with new data.
|
2005-06-03 12:22:54 +00:00
|
|
|
|
2008-06-18 15:31:47 +00:00
|
|
|
$label->name = get_label_name($label);
|
2003-09-14 12:30:09 +00:00
|
|
|
$label->timemodified = time();
|
|
|
|
$label->id = $label->instance;
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
return $DB->update_record("label", $label);
|
2003-09-14 12:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function label_delete_instance($id) {
|
2008-06-01 21:36:11 +00:00
|
|
|
global $DB;
|
2003-09-14 12:30:09 +00:00
|
|
|
/// Given an ID of an instance of this module,
|
|
|
|
/// this function will permanently delete the instance
|
|
|
|
/// and any data that depends on it.
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if (! $label = $DB->get_record("label", array("id"=>$id))) {
|
2003-09-14 12:30:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = true;
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if (! $DB->delete_records("label", array("id"=>$label->id))) {
|
2003-09-14 12:30:09 +00:00
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2003-09-14 15:47:36 +00:00
|
|
|
function label_get_participants($labelid) {
|
|
|
|
//Returns the users with data in one resource
|
2003-11-21 14:03:06 +00:00
|
|
|
//(NONE, but must exist on EVERY mod !!)
|
2003-09-14 15:47:36 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-02-01 07:48:26 +00:00
|
|
|
/**
|
|
|
|
* Given a course_module object, this function returns any
|
|
|
|
* "extra" information that may be needed when printing
|
|
|
|
* this activity in a course listing.
|
|
|
|
* See get_array_of_activities() in course/lib.php
|
|
|
|
*/
|
2003-10-22 13:14:56 +00:00
|
|
|
function label_get_coursemodule_info($coursemodule) {
|
2008-06-03 23:44:16 +00:00
|
|
|
global $DB;
|
|
|
|
|
|
|
|
if ($label = $DB->get_record('label', array('id'=>$coursemodule->instance), 'id, content, name')) {
|
2008-07-05 09:37:30 +00:00
|
|
|
if (empty($label->name)) {
|
|
|
|
// label name missing, fix it
|
|
|
|
$label->name = "label{$label->id}";
|
|
|
|
$DB->set_field('label', 'name', $label->name, array('id'=>$label->id));
|
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
$info = new object();
|
2008-02-01 08:15:38 +00:00
|
|
|
$info->extra = urlencode($label->content);
|
|
|
|
$info->name = urlencode($label->name);
|
2008-01-24 20:33:50 +00:00
|
|
|
return $info;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2003-10-22 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
2005-09-01 04:14:31 +00:00
|
|
|
function label_get_view_actions() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
function label_get_post_actions() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
function label_get_types() {
|
|
|
|
$types = array();
|
|
|
|
|
|
|
|
$type = new object();
|
|
|
|
$type->modclass = MOD_CLASS_RESOURCE;
|
|
|
|
$type->type = "label";
|
|
|
|
$type->typestr = get_string('resourcetypelabel', 'resource');
|
|
|
|
$types[] = $type;
|
|
|
|
|
|
|
|
return $types;
|
|
|
|
}
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used by the reset_course_userdata function in moodlelib.
|
|
|
|
* @param $data the data submitted from the reset course.
|
|
|
|
* @return array status array
|
|
|
|
*/
|
|
|
|
function label_reset_userdata($data) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2003-09-14 12:30:09 +00:00
|
|
|
?>
|