]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13691 and MDL-13404 - Merge from 1.9
authorscyrma <scyrma>
Wed, 27 Feb 2008 09:34:57 +0000 (09:34 +0000)
committerscyrma <scyrma>
Wed, 27 Feb 2008 09:34:57 +0000 (09:34 +0000)
tag/edit.php
tag/lib.php
tag/locallib.php

index 1d3f0025cfd12cf9c9261dedee2ec44f4ab448e9..6e6abb9f6971d7fcc9601137c5fa5ed5d23e94c5 100644 (file)
@@ -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);
index 6c41365bd9c0911796bcd2dd4456b75568e55e3c..d258fb63cc8efbbfdabc9e9770b77742b467b7ef 100644 (file)
@@ -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[] = '<a href="'. $CFG->wwwroot .'/tag/index.php?tag='. rawurlencode($tag->name) .'">'. tag_display_name($tag) .'</a>';
         }
     }
+
     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;
 }
 
index 977451e40a6cb1eb8cb191737df60211382db614..80ca7743c42637e4794398fa97c16df0b7ddfe38 100644 (file)
@@ -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 .= '<br /><br /><strong>'. get_string('relatedtags', 'tag') .': </strong>'. tag_get_related_tags_csv($related_tags);
+        if ($more_links) {
+            $output .= ' ...';
+        }
     }
 
     if ($content) {