From b50d224597786083b81418570a251b417aebdb10 Mon Sep 17 00:00:00 2001 From: scyrma Date: Wed, 27 Feb 2008 09:34:57 +0000 Subject: [PATCH] MDL-13691 and MDL-13404 - Merge from 1.9 --- tag/edit.php | 2 ++ tag/lib.php | 34 ++++++++++++++++++++++++---------- tag/locallib.php | 12 +++++++++++- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/tag/edit.php b/tag/edit.php index 1d3f0025cf..6e6abb9f69 100644 --- a/tag/edit.php +++ b/tag/edit.php @@ -49,6 +49,8 @@ $tagform->set_data($tag); // If new data has been sent, update the tag record if ($tagnew = $tagform->get_data()) { + tag_description_set($tag_id, stripslashes($tagnew->description), $tagnew->descriptionformat); + if (!has_capability('moodle/tag:manage', $systemcontext)) { unset($tagnew->name); unset($tagnew->rawname); diff --git a/tag/lib.php b/tag/lib.php index 6c41365bd9..d258fb63cc 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -104,6 +104,24 @@ function tag_delete_instance($record, $tagid) { } } +/** + * 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 * @@ -394,6 +412,7 @@ function tag_get_related_tags_csv($related_tags, $html=TAG_RETURN_HTML) { $tags_names[] = ''. tag_display_name($tag) .''; } } + return implode(', ', $tags_names); } @@ -594,7 +613,7 @@ function tag_add($tags, $type="default") { // 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); } @@ -783,19 +802,14 @@ function tag_get_correlated($tag_id, $limitnum=null) { 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; } diff --git a/tag/locallib.php b/tag/locallib.php index 977451e40a..80ca7743c4 100644 --- a/tag/locallib.php +++ b/tag/locallib.php @@ -105,8 +105,10 @@ function tag_print_description_box($tag_object, $return=false) { 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 = ''; @@ -122,7 +124,15 @@ function tag_print_description_box($tag_object, $return=false) { } if ($related_tags) { + $more_links = false; + if (count($related_tags) > $max_tags_displayed) { + array_pop($related_tags); + $more_links = true; + } $output .= '

'. get_string('relatedtags', 'tag') .': '. tag_get_related_tags_csv($related_tags); + if ($more_links) { + $output .= ' ...'; + } } if ($content) { -- 2.39.5