diff options
| author | wjames5 <will@tekimaki.com> | 2007-03-16 05:21:14 +0000 |
|---|---|---|
| committer | wjames5 <will@tekimaki.com> | 2007-03-16 05:21:14 +0000 |
| commit | 73e6096cece721c6ba5ac1184cc8890d2ca45849 (patch) | |
| tree | 67591b638598e338b93afe8ef0fccba9a35de960 | |
| parent | bd115235c1ead62e0fb5168c1848c192751ef85d (diff) | |
| download | tags-73e6096cece721c6ba5ac1184cc8890d2ca45849.tar.gz tags-73e6096cece721c6ba5ac1184cc8890d2ca45849.tar.bz2 tags-73e6096cece721c6ba5ac1184cc8890d2ca45849.zip | |
removes duplicate records in content list
| -rwxr-xr-x | LibertyTag.php | 45 | ||||
| -rw-r--r-- | templates/list_content.tpl | 1 |
2 files changed, 43 insertions, 3 deletions
diff --git a/LibertyTag.php b/LibertyTag.php index e6d3832..f62f701 100755 --- a/LibertyTag.php +++ b/LibertyTag.php @@ -325,11 +325,52 @@ class LibertyTag extends LibertyBase { return $cant; } + /** + * This function gets all content by matching to any tag passed in a group of tags, eliminates dupe records + **/ function getContentList(&$pParamHash){ global $gBitSystem, $gBitSmarty; $_REQUEST['output'] = 'raw'; include_once( LIBERTY_PKG_PATH.'list_content.php' ); - $gBitSmarty->assign_by_ref('listcontent', $contentList["data"]); + $distinctdata = $this->array_distinct( $contentList["data"], 'content_id' ); + $distinctdata = array_merge($distinctdata); + $gBitSmarty->assign_by_ref('contentList', $distinctdata); + } + + + /** + * Used by getContentList to strip out duplicate records in a list + **/ + function array_distinct ($array, $group_keys, $sum_keys = NULL, $count_key = NULL){ + if (!is_array ($group_keys)) $group_keys = array ($group_keys); + if (!is_array ($sum_keys)) $sum_keys = array ($sum_keys); + + $existing_sub_keys = array (); + $output = array (); + + foreach ($array as $key => $sub_array){ + $puffer = NULL; + #group keys + foreach ($group_keys as $group_key){ + $puffer .= $sub_array[$group_key]; + } + $puffer = serialize ($puffer); + if (!in_array ($puffer, $existing_sub_keys)){ + $existing_sub_keys[$key] = $puffer; + $output[$key] = $sub_array; + } + else{ + $puffer = array_search ($puffer, $existing_sub_keys); + #sum keys + foreach ($sum_keys as $sum_key){ + if (is_string ($sum_key)) $output[$puffer][$sum_key] += $sub_array[$sum_key]; + } + #count grouped keys + if (!array_key_exists ($count_key, $output[$puffer])) $output[$puffer][$count_key] = 1; + if (is_string ($count_key)) $output[$puffer][$count_key]++; + } + } + return $output; } } @@ -357,7 +398,7 @@ function tags_content_list_sql( &$pObject, $pParamHash = NULL ) { $ret = array(); if (isset($pParamHash['tags'])){ - $ret['select_sql'] = " , tgc.`tag_id`, tgc.`tagger_id`, tgc.`tagged_on`"; + $ret['select_sql'] = ", tgc.`tag_id`, tgc.`tagger_id`, tgc.`tagged_on`"; $ret['join_sql'] = " INNER JOIN `".BIT_DB_PREFIX."tags_content_map` tgc ON ( lc.`content_id`=tgc.`content_id` ) INNER JOIN `".BIT_DB_PREFIX."tags` tg ON ( tg.`tag_id`=tgc.`tag_id` )"; diff --git a/templates/list_content.tpl b/templates/list_content.tpl index 7e22f16..bf225c6 100644 --- a/templates/list_content.tpl +++ b/templates/list_content.tpl @@ -13,7 +13,6 @@ {forminput} <input type="text" name="tags" value="{$listInfo.tags}" /> <input type="submit" value="{tr}Search{/tr}" name="search_objects" /> - {formhelp note="Search again by tags."} {/forminput} </div> {/form} |
