Changeset 28063 for extensions/SmartAlbums/include/functions.inc.php
- Timestamp:
- Apr 3, 2014, 8:03:58 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/SmartAlbums/include/functions.inc.php
r27266 r28063 277 277 case 'album': 278 278 { 279 $filter['values'] = explode(',', $filter['value']); 280 $filter['recursive'] = array_shift($filter['values']) == "true"; 281 $filter['value'] = implode(',', $filter['values']); 282 279 283 switch ($filter['cond']) 280 284 { … … 282 286 case 'all': 283 287 { 284 $albums_arr = explode(',', $filter['value']); 285 foreach($albums_arr as $value) 286 { 288 foreach ($filter['values'] as $value) 289 { 290 if ($filter['recursive']) 291 { 292 $value = get_subcat_ids_query(array($value)); 293 } 287 294 $sub_query = ' 288 295 SELECT image_id 289 296 FROM '.IMAGE_CATEGORY_TABLE.' 290 WHERE category_id = '.$value.'297 WHERE category_id IN('.$value.') 291 298 '; 292 299 $where[] = 'i.id IN ('.$sub_query.')'; … … 298 305 case 'one': 299 306 { 307 if ($filter['recursive']) 308 { 309 $value = get_subcat_ids_query($filter['values']); 310 } 311 else 312 { 313 $value = $filter['value']; 314 } 300 315 $sub_query = ' 301 316 SELECT image_id 302 317 FROM '.IMAGE_CATEGORY_TABLE.' 303 WHERE category_id IN('.$ filter['value'].')318 WHERE category_id IN('.$value.') 304 319 '; 305 320 $where[] = 'i.id IN ('.$sub_query.')'; … … 310 325 case 'none': 311 326 { 327 if ($filter['recursive']) 328 { 329 $value = get_subcat_ids_query($filter['values']); 330 } 331 else 332 { 333 $value = $filter['value']; 334 } 312 335 $sub_query = ' 313 336 SELECT image_id 314 337 FROM '.IMAGE_CATEGORY_TABLE.' 315 WHERE category_id IN('.$ filter['value'].')338 WHERE category_id IN('.$value.') 316 339 '; 317 340 $where[] = 'i.id NOT IN ('.$sub_query.')'; … … 322 345 case 'only': 323 346 { 347 if ($filter['recursive']) 348 { 349 $value = get_subcat_ids_query($filter['values']); 350 } 351 else 352 { 353 $value = $filter['value']; 354 } 324 355 $sub_query = ' 325 356 SELECT image_id 326 357 FROM '.IMAGE_CATEGORY_TABLE.' 327 WHERE category_id NOT IN('.$ filter['value'].')358 WHERE category_id NOT IN('.$value.') 328 359 '; 329 360 $where[] = 'i.id NOT IN ('.$sub_query.')'; 330 361 331 $albums_arr = explode(',', $filter['value']); 332 foreach($albums_arr as $value) 333 { 362 foreach ($filter['values'] as $value) 363 { 364 if ($filter['recursive']) 365 { 366 $value = get_subcat_ids_query(array($value)); 367 } 334 368 $sub_query = ' 335 369 SELECT image_id … … 544 578 else 545 579 { 580 array_unshift($filter['value'], boolean_to_string(isset($filter['recursive']))); 546 581 $filter['value'] = implode(',', $filter['value']); 547 582 } … … 651 686 } 652 687 } 688 689 /** 690 * Returns SQL query returning all subcategory identifiers of given category ids 691 * 692 * @param int[] $ids 693 * @return int[] 694 */ 695 function get_subcat_ids_query($ids) 696 { 697 $query = ' 698 SELECT DISTINCT(id) 699 FROM '.CATEGORIES_TABLE.' 700 WHERE '; 701 foreach ($ids as $num => $category_id) 702 { 703 if ($num > 0) 704 { 705 $query.= ' 706 OR '; 707 } 708 $query.= 'uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.$category_id.'(,|$)\''; 709 } 710 return $query; 711 }
Note: See TracChangeset
for help on using the changeset viewer.