aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions_tag.inc.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2006-08-15 02:06:06 +0000
committerrvelices <rv-github@modusoptimus.com>2006-08-15 02:06:06 +0000
commit48c6d7e8a4d5b44a6c5c6fa919267d098ed28ee7 (patch)
tree3db23f90be4b39dbe3f25aef0df3c56774106fca /include/functions_tag.inc.php
parentbc1f5319b151c22cd0bed853fc940617e700a29f (diff)
feature 519: quick search (first version)
git-svn-id: http://piwigo.org/svn/trunk@1537 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/functions_tag.inc.php')
-rw-r--r--include/functions_tag.inc.php43
1 files changed, 43 insertions, 0 deletions
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