From 48c6d7e8a4d5b44a6c5c6fa919267d098ed28ee7 Mon Sep 17 00:00:00 2001 From: rvelices Date: Tue, 15 Aug 2006 02:06:06 +0000 Subject: feature 519: quick search (first version) git-svn-id: http://piwigo.org/svn/trunk@1537 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions_tag.inc.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'include/functions_tag.inc.php') diff --git a/include/functions_tag.inc.php b/include/functions_tag.inc.php index 046eb6bb1..b330041ca 100644 --- a/include/functions_tag.inc.php +++ b/include/functions_tag.inc.php @@ -221,4 +221,47 @@ SELECT DISTINCT image_id } } } + +/** + * return a list of tags corresponding to given items. + * + * @param array items + * @param array max_tags + * @param array excluded_tag_ids + * @return array + */ +function get_common_tags($items, $max_tags, $excluded_tag_ids=null) +{ + if (empty($items)) + { + return array(); + } + $query = ' +SELECT tag_id, name, url_name, count(*) counter + FROM '.IMAGE_TAG_TABLE.' + INNER JOIN '.TAGS_TABLE.' ON tag_id = id + WHERE image_id IN ('.implode(',', $items).')'; + if (!empty($excluded_tag_ids)) + { + $query.=' + AND tag_id NOT IN ('.implode(',', $excluded_tag_ids).')'; + } + $query .=' + GROUP BY tag_id + ORDER BY counter DESC'; + if ($max_tags>0) + { + $query .= ' + LIMIT 0,'.$max_tags; + } + + $result = pwg_query($query); + $tags = array(); + while($row = mysql_fetch_array($result)) + { + array_push($tags, $row); + } + usort($tags, 'name_compare'); + return $tags; +} ?> \ No newline at end of file -- cgit v1.2.3