]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11017, changed blog edit page to use modified get_item_tags()
authortoyomoyo <toyomoyo>
Tue, 28 Aug 2007 08:32:38 +0000 (08:32 +0000)
committertoyomoyo <toyomoyo>
Tue, 28 Aug 2007 08:32:38 +0000 (08:32 +0000)
blog/edit.php
lib/dmllib.php
tag/lib.php

index c3ed2799abb5c0a87ba87a488cd9f0f85b6e9d68..0ca93133e1101079ee1d0161d4be4d3818d0582b 100755 (executable)
@@ -119,25 +119,13 @@ switch ($action) {
         $post->action       = $action;
         $strformheading = get_string('updateentrywithid', 'blog');
 
-        if ($ptags = get_records_sql_menu("SELECT t.id, t.name FROM
-                                     {$CFG->prefix}tag t,
-                                     {$CFG->prefix}tag_instance ti
-                                     WHERE t.id = ti.tagid
-                                     AND t.tagtype = 'default'
-                                     AND ti.itemid = {$post->id}")) {
-
+        if ($ptags = records_to_menu(get_item_tags('blog', $post->id, 'ti.ordering ASC', 'id,rawname', '', '', 'default'), 'id','rawname')) {           
             $post->ptags = implode(', ', $ptags);
         } else {
-            //$idsql = " AND bti.entryid = 0";
-            //was used but seems redundant.
             $post->ptags = '';
         }
-        if ($otags = get_records_sql_menu("SELECT t.id, t.name FROM
-                                     {$CFG->prefix}tag t,
-                                     {$CFG->prefix}tag_instance ti
-                                     WHERE t.id = ti.tagid
-                                     AND t.tagtype = 'official'
-                                     AND ti.itemid = {$post->id}")){
+        
+        if ($otags = records_to_menu(get_item_tags('blog', $post->id, 'ti.ordering ASC', 'id,rawname', '', '', 'official'), 'id','rawname')) {
             $post->otags = array_keys($otags);
         }
     break;
index 399d8f8e8dd9dd379e54cfb5e40c8e5d37ccc4de..e8dd30674f231fbd63b0b00e9b6e932010a9040d 100644 (file)
@@ -927,7 +927,7 @@ function get_records_sql($sql, $limitfrom='', $limitnum='') {
  */
 function recordset_to_menu($rs) {
     global $CFG;
-
+    $menu = array();
     if ($rs && $rs->RecordCount() > 0) {
         $keys = array_keys($rs->fields);
         $key0=$keys[0];
@@ -948,6 +948,30 @@ function recordset_to_menu($rs) {
     }
 }
 
+/**
+ * Utility function 
+ * Similar to recordset_to_menu 
+ *
+ * field1, field2 is needed because the order from get_records_sql is not reliable
+ * @param records - records from get_records_sql() or get_records()
+ * @param field1 - field to be used as menu index
+ * @param field2 - feild to be used as coresponding menu value
+ * @return mixed an associative array, or false if an error occured or the RecordSet was empty.
+ */
+function records_to_menu($records, $field1, $field2) {
+
+    $menu = array();
+    foreach ($records as $record) {
+        $menu[$record->$field1] = $record->$field2;
+    }
+
+    if (!empty($menu)) {
+        return $menu;
+    } else {
+        return false; 
+    }
+}
+
 /**
  * Get the first two columns from a number of records as an associative array.
  *
index b120f0b518dfa0edac674560baa08d34b77d613b..b08b431f4a8945593243216100271f17525a56e9 100644 (file)
@@ -520,7 +520,7 @@ function untag_an_item($item_type, $item_id, $tag_names_or_ids_csv='') {
  * @return mixed an array of objects, or false if no records were found or an error occured.
  */
 
-function get_item_tags($item_type, $item_id, $sort='ti.ordering ASC', $fields=DEFAULT_TAG_TABLE_FIELDS, $limitfrom='', $limitnum='') {
+function get_item_tags($item_type, $item_id, $sort='ti.ordering ASC', $fields=DEFAULT_TAG_TABLE_FIELDS, $limitfrom='', $limitnum='', $tagtype='') {
 
     global $CFG;
 
@@ -531,6 +531,12 @@ function get_item_tags($item_type, $item_id, $sort='ti.ordering ASC', $fields=DE
         $sort = ' ORDER BY '. $sort;
     }
 
+    if ($tagtype) {
+        $tagwhere = " AND tg.tagtype = '$tagtype' "; 
+    } else {
+        $tagwhere = ''; 
+    }
+
     $query = "
         SELECT
             {$fields}
@@ -543,6 +549,7 @@ function get_item_tags($item_type, $item_id, $sort='ti.ordering ASC', $fields=DE
         WHERE 
             ti.itemtype = '{$item_type}' AND
             ti.itemid = '{$item_id}'
+            $tagwhere
         {$sort}
             ";