From: toyomoyo Date: Tue, 28 Aug 2007 08:32:38 +0000 (+0000) Subject: MDL-11017, changed blog edit page to use modified get_item_tags() X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=474373aa9663470e7e8f50c6768edb6e16458d53;p=moodle.git MDL-11017, changed blog edit page to use modified get_item_tags() --- diff --git a/blog/edit.php b/blog/edit.php index c3ed2799ab..0ca93133e1 100755 --- a/blog/edit.php +++ b/blog/edit.php @@ -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; diff --git a/lib/dmllib.php b/lib/dmllib.php index 399d8f8e8d..e8dd30674f 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -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. * diff --git a/tag/lib.php b/tag/lib.php index b120f0b518..b08b431f4a 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -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} ";