Changeset 635 for trunk/admin/include
- Timestamp:
- Dec 5, 2004, 10:28:40 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r633 r635 442 442 443 443 /** 444 * updates calculated informations about a category: date_last and444 * updates calculated informations about a set of categories : date_last and 445 445 * nb_images. It also verifies that the representative picture is really 446 * linked to the category. Recursive.446 * linked to the category. Optionnaly recursive. 447 447 * 448 448 * @param mixed category id 449 * @param boolean recursive 449 450 * @returns void 450 451 */ 451 function update_category($id = 'all') 452 { 452 function update_category($ids = 'all', $recursive = false) 453 { 454 // retrieving all categories to update 453 455 $cat_ids = array(); 454 456 457 $query = ' 458 SELECT id 459 FROM '.CATEGORIES_TABLE; 460 if (is_array($ids)) 461 { 462 if ($recursive) 463 { 464 foreach ($ids as $num => $id) 465 { 466 if ($num == 0) 467 { 468 $query.= ' 469 WHERE '; 470 } 471 else 472 { 473 $query.= ' 474 OR '; 475 } 476 $query.= 'uppercats REGEXP \'(^|,)'.$id.'(,|$)\''; 477 } 478 } 479 else 480 { 481 $query.= ' 482 WHERE id IN ('.implode(',', $ids).')'; 483 } 484 } 485 $query.= ' 486 ;'; 487 $result = pwg_query( $query ); 488 while ( $row = mysql_fetch_array( $result ) ) 489 { 490 array_push($cat_ids, $row['id']); 491 } 492 $cat_ids = array_unique($cat_ids); 493 494 if (count($cat_ids) == 0) 495 { 496 return false; 497 } 498 499 // calculate informations about categories retrieved 455 500 $query = ' 456 501 SELECT category_id, 457 502 COUNT(image_id) AS nb_images, 458 503 MAX(date_available) AS date_last 459 FROM '.IMAGES_TABLE.' 460 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; 461 if (is_numeric($id)) 462 { 463 $query.= ' 464 WHERE uppercats REGEXP \'(^|,)'.$id.'(,|$)\''; 465 } 466 $query.= ' 504 FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id 505 WHERE category_id IN ('.implode(',', $cat_ids).') 467 506 GROUP BY category_id 468 ;';469 $result = pwg_query( $query);507 '; 508 $result = pwg_query($query); 470 509 $datas = array(); 471 510 while ( $row = mysql_fetch_array( $result ) ) 472 511 { 473 array_push($cat_ids, $row['category_id']);474 512 array_push($datas, array('id' => $row['category_id'], 475 513 'date_last' => $row['date_last'], … … 480 518 mass_updates(CATEGORIES_TABLE, $fields, $datas); 481 519 520 $query = ' 521 UPDATE '.CATEGORIES_TABLE.' 522 SET representative_picture_id = NULL 523 WHERE nb_images = 0 524 ;'; 525 pwg_query($query); 526 482 527 if (count($cat_ids) > 0) 483 528 { 529 $categories = array(); 484 530 // find all categories where the setted representative is not possible 485 531 $query = ' … … 494 540 while ($row = mysql_fetch_array($result)) 495 541 { 496 // set a new representative element for this category 497 $query = ' 498 SELECT image_id 499 FROM '.IMAGE_CATEGORY_TABLE.' 500 WHERE category_id = '.$row['id'].' 501 ORDER BY RAND() 502 LIMIT 0,1 503 ;'; 504 $sub_result = pwg_query($query); 505 if (mysql_num_rows($sub_result) > 0) 506 { 507 list($representative) = mysql_fetch_array($sub_result); 508 $query = ' 509 UPDATE '.CATEGORIES_TABLE.' 510 SET representative_picture_id = '.$representative.' 511 WHERE id = '.$row['id'].' 512 ;'; 513 pwg_query($query); 514 } 515 else 516 { 517 $query = ' 518 UPDATE '.CATEGORIES_TABLE.' 519 SET representative_picture_id = NULL 520 WHERE id = '.$row['id'].' 521 ;'; 522 pwg_query($query); 523 } 524 } 542 array_push($categories, $row['id']); 543 } 544 // find categories with elements and with no representant 545 $query = ' 546 SELECT id 547 FROM '.CATEGORIES_TABLE.' 548 WHERE representative_picture_id IS NULL 549 AND nb_images != 0 550 ;'; 551 $result = pwg_query($query); 552 while ($row = mysql_fetch_array($result)) 553 { 554 array_push($categories, $row['id']); 555 } 556 557 $categories = array_unique($categories); 558 set_random_representant($categories); 525 559 } 526 560 }
Note: See TracChangeset
for help on using the changeset viewer.