Changeset 25658 for trunk/include/functions_tag.inc.php
- Timestamp:
- Nov 23, 2013, 11:57:15 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_tag.inc.php
r25018 r25658 22 22 // +-----------------------------------------------------------------------+ 23 23 24 25 /** returns the number of available tags for the connected user */ 24 /** 25 * @package functions\tag 26 */ 27 28 29 /** 30 * Returns the number of available tags for the connected user. 31 * 32 * @return int 33 */ 26 34 function get_nb_available_tags() 27 35 { … … 39 47 40 48 /** 41 * Tags available. Each return tag is represented as an array with its id, 42 * its name, its weight (count), its url name. Tags are not sorted. 43 * 44 * The returned list can be a subset of all existing tags due to 45 * permissions, only if a list of forbidden categories is provided 46 * 47 * @param array forbidden categories 48 * @return array 49 * Returns all available tags for the connected user (not sorted). 50 * The returned list can be a subset of all existing tags due to permissions, 51 * also tags with no images are not returned. 52 * 53 * @return array [id, name, counter, url_name] 49 54 */ 50 55 function get_available_tags() … … 54 59 SELECT tag_id, COUNT(DISTINCT(it.image_id)) AS counter 55 60 FROM '.IMAGE_CATEGORY_TABLE.' ic 56 INNER JOIN '.IMAGE_TAG_TABLE.' it ON ic.image_id=it.image_id'.get_sql_condition_FandF 57 ( 58 array 59 ( 60 'forbidden_categories' => 'category_id', 61 'visible_categories' => 'category_id', 62 'visible_images' => 'ic.image_id' 63 ), 64 ' 65 WHERE' 61 INNER JOIN '.IMAGE_TAG_TABLE.' it 62 ON ic.image_id=it.image_id 63 '.get_sql_condition_FandF( 64 array( 65 'forbidden_categories' => 'category_id', 66 'visible_categories' => 'category_id', 67 'visible_images' => 'ic.image_id' 68 ), 69 ' WHERE ' 66 70 ).' 67 GROUP BY tag_id'; 71 GROUP BY tag_id 72 ;'; 68 73 $tag_counters = simple_hash_from_query($query, 'tag_id', 'counter'); 69 74 … … 77 82 FROM '.TAGS_TABLE; 78 83 $result = pwg_query($query); 84 79 85 $tags = array(); 80 86 while ($row = pwg_db_fetch_assoc($result)) … … 92 98 93 99 /** 94 * All tags, even tagsassociated to no image.95 * 96 * @return array 100 * Returns all tags even associated to no image. 101 * 102 * @return array [id, name, url_name] 97 103 */ 98 104 function get_all_tags() … … 120 126 * 121 127 * The level of each tag depends on the average count of tags. This 122 * calc ylation method avoid having very different levels for tags having128 * calculation method avoid having very different levels for tags having 123 129 * nearly the same count when set are small. 124 130 * 125 * @param array tags126 * @return array 131 * @param array $tags at least [id, counter] 132 * @return array [..., level] 127 133 */ 128 134 function add_level_to_tags($tags) … … 174 180 175 181 /** 176 * return the list of image ids corresponding to given tags. AND & OR mode177 * supported.178 * 179 * @param array tagids182 * Return the list of image ids corresponding to given tags. 183 * AND & OR mode supported. 184 * 185 * @param int[] $tag_ids 180 186 * @param string mode 181 * @param string extra_images_where_sql - optionally apply a sql where filter to retrieved images 182 * @param string order_by - optionally overwrite default photo order 187 * @param string $extra_images_where_sql - optionally apply a sql where filter to retrieved images 188 * @param string $order_by - optionally overwrite default photo order 189 * @param bool $user_permissions 183 190 * @return array 184 191 */ … … 191 198 } 192 199 193 $query = 'SELECT id 200 $query = ' 201 SELECT id 194 202 FROM '.IMAGES_TABLE.' i '; 195 203 … … 230 238 231 239 /** 232 * return a list of tags corresponding to given items.233 * 234 * @param arrayitems235 * @param arraymax_tags236 * @param arrayexcluded_tag_ids237 * @return array 238 */ 239 function get_common_tags($items, $max_tags, $excluded_tag_ids= null)240 * Return a list of tags corresponding to given items. 241 * 242 * @param int[] $items 243 * @param int $max_tags 244 * @param int[] $excluded_tag_ids 245 * @return array [id, name, counter, url_name] 246 */ 247 function get_common_tags($items, $max_tags, $excluded_tag_ids=array()) 240 248 { 241 249 if (empty($items)) … … 257 265 ORDER BY '; 258 266 if ($max_tags>0) 259 { 267 { // TODO : why ORDER field is in the if ? 260 268 $query .= 'counter DESC 261 269 LIMIT '.$max_tags; … … 278 286 279 287 /** 280 * return a list of tags corresponding to any of ids, url_names, names281 * 282 * @param arrayids283 * @param arrayurl_names284 * @param arraynames285 * @return array 286 */ 287 function find_tags($ids , $url_names=array(), $names=array() )288 * Return a list of tags corresponding to any of ids, url_names or names. 289 * 290 * @param int[] $ids 291 * @param string[] $url_names 292 * @param string[] $names 293 * @return array [id, name, url_name] 294 */ 295 function find_tags($ids=array(), $url_names=array(), $names=array() ) 288 296 { 289 297 $where_clauses = array(); 290 if ( !empty($ids))298 if (!empty($ids)) 291 299 { 292 300 $where_clauses[] = 'id IN ('.implode(',', $ids).')'; 293 301 } 294 if ( !empty($url_names))302 if (!empty($url_names)) 295 303 { 296 304 $where_clauses[] = 297 'url_name IN ('. 298 implode( 299 ',', 300 array_map( 301 create_function('$s', 'return "\'".$s."\'";'), 302 $url_names 303 ) 304 ) 305 .')'; 306 } 307 if ( !empty($names) ) 305 'url_name IN (\''. implode('\', \'', $url_names) .'\')'; 306 } 307 if (!empty($names)) 308 308 { 309 309 $where_clauses[] = 310 'name IN ('. 311 implode( 312 ',', 313 array_map( 314 create_function('$s', 'return "\'".$s."\'";'), 315 $names 316 ) 317 ) 318 .')'; 310 'name IN (\''. implode('\', \'', $names) .'\')'; 319 311 } 320 312 if (empty($where_clauses)) … … 337 329 return $tags; 338 330 } 331 339 332 ?>
Note: See TracChangeset
for help on using the changeset viewer.