}
}
+/**
+ * Set the description of a tag
+ *
+ * @param int $tagid the id of the tag
+ * @param string $description the description
+ * @param int $descriptionformat the moodle text format of the description
+ * @return true on success, false otherwise
+ */
+function tag_description_set($tagid, $description, $descriptionformat) {
+ if ($tag = get_record('tag', 'id', $tagid, '', '', '', '', 'id')) {
+ $tag->description = addslashes($description);
+ $tag->descriptionformat = addslashes($descriptionformat);
+ $tag->timemodified = time();
+ return update_record('tag', $tag);
+ }
+ return false;
+}
+
/**
* Function that returns the name that should be displayed for a specific tag
*
$tags_names[] = '<a href="'. $CFG->wwwroot .'/tag/index.php?tag='. rawurlencode($tag->name) .'">'. tag_display_name($tag) .'</a>';
}
}
+
return implode(', ', $tags_names);
}
// capitalization : the rawname is NOT the same at the rawtag.
$tag_object->rawname = addslashes($tag);
$tag_name_lc = moodle_strtolower($tag);
- $tag_object->name = addslashes($tag_name_lc);
+ $tag_object->name = addslashes($tag_name_lc);
//var_dump($tag_object);
$tags_ids[$tag_name_lc] = insert_record('tag', $tag_object);
}
if (!$tag_correlation || empty($tag_correlation->correlatedtags)) {
return array();
}
-
+
// this is (and has to) return the same fields as the query in tag_get_tags
- if (!$result = get_records_sql("SELECT tg.id, tg.tagtype, tg.name, tg.rawname, tg.flag, ti.ordering ".
- "FROM {$CFG->prefix}tag_instance ti INNER JOIN {$CFG->prefix}tag tg ON tg.id = ti.tagid ".
- "WHERE ti.itemtype = 'tag' AND ti.itemid IN ({$tag_correlation->correlatedtags}) ".
- "ORDER BY ti.ordering ASC")) {
+ if ( !$result = get_records_sql("SELECT tg.id, tg.tagtype, tg.name, tg.rawname, tg.flag, ti.ordering ".
+ "FROM {$CFG->prefix}tag tg INNER JOIN {$CFG->prefix}tag_instance ti ON tg.id = ti.tagid ".
+ "WHERE tg.id IN ({$tag_correlation->correlatedtags})") ) {
return array();
}
- //if (!$result = get_records_select('tag', "id IN ({$tag_correlation->correlatedtags})", '', '*', 0, $limitnum)) {
- // return array();
- //}
-
return $result;
}
global $USER, $CFG;
+ $max_tags_displayed = 10; // todo: turn this into a system setting
+
$tagname = tag_display_name($tag_object);
- $related_tags = tag_get_related_tags($tag_object->id);
+ $related_tags = tag_get_related_tags($tag_object->id, TAG_RELATED_ALL, $max_tags_displayed+1); // this gets one more than we want
$content = !empty($tag_object->description) || $related_tags;
$output = '';
}
if ($related_tags) {
+ $more_links = false;
+ if (count($related_tags) > $max_tags_displayed) {
+ array_pop($related_tags);
+ $more_links = true;
+ }
$output .= '<br /><br /><strong>'. get_string('relatedtags', 'tag') .': </strong>'. tag_get_related_tags_csv($related_tags);
+ if ($more_links) {
+ $output .= ' ...';
+ }
}
if ($content) {