MDL-11017, changed blog edit page to use modified get_item_tags()

This commit is contained in:
toyomoyo 2007-08-28 08:32:38 +00:00
parent 61c6071f40
commit 474373aa96
3 changed files with 36 additions and 17 deletions

View File

@ -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;

View 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.
*

View 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}
";