Changeset 17981 for branches/2.4
- Timestamp:
- Sep 18, 2012, 1:45:51 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.4/admin/include/functions.php
r17766 r17981 1489 1489 * Associate a list of images to a list of categories. 1490 1490 * 1491 * The function will not duplicate links 1491 * The function will not duplicate links and will preserve ranks 1492 1492 * 1493 1493 * @param array images … … 1502 1502 return false; 1503 1503 } 1504 1505 $query = ' 1506 DELETE 1504 1505 // get existing associations 1506 $query = ' 1507 SELECT 1508 image_id, 1509 category_id 1507 1510 FROM '.IMAGE_CATEGORY_TABLE.' 1508 1511 WHERE image_id IN ('.implode(',', $images).') 1509 1512 AND category_id IN ('.implode(',', $categories).') 1510 1513 ;'; 1511 pwg_query($query); 1512 1514 $result = pwg_query($query); 1515 1516 $existing = array(); 1517 while ($row = pwg_db_fetch_assoc($result)) 1518 { 1519 $existing[ $row['category_id'] ][] = $row['image_id']; 1520 } 1521 1522 // get max rank of each categories 1513 1523 $query = ' 1514 1524 SELECT … … 1527 1537 ); 1528 1538 1539 // associate only not already associated images 1529 1540 $inserts = array(); 1530 1541 foreach ($categories as $category_id) … … 1534 1545 $current_rank_of[$category_id] = 0; 1535 1546 } 1547 if (!isset($existing[$category_id])) 1548 { 1549 $existing[$category_id] = array(); 1550 } 1536 1551 1537 1552 foreach ($images as $image_id) 1538 1553 { 1539 $rank = ++$current_rank_of[$category_id]; 1540 1541 array_push( 1542 $inserts, 1543 array( 1544 'image_id' => $image_id, 1545 'category_id' => $category_id, 1546 'rank' => $rank, 1547 ) 1548 ); 1549 } 1550 } 1551 1552 mass_inserts( 1553 IMAGE_CATEGORY_TABLE, 1554 array_keys($inserts[0]), 1555 $inserts 1556 ); 1557 1558 update_category($categories); 1559 } 1560 1561 /** 1562 * Disssociate images from all categories except their storage category and 1554 if (!in_array($image_id, $existing[$category_id])) 1555 { 1556 $rank = ++$current_rank_of[$category_id]; 1557 1558 array_push( 1559 $inserts, 1560 array( 1561 'image_id' => $image_id, 1562 'category_id' => $category_id, 1563 'rank' => $rank, 1564 ) 1565 ); 1566 } 1567 } 1568 } 1569 1570 if (count($inserts)) 1571 { 1572 mass_inserts( 1573 IMAGE_CATEGORY_TABLE, 1574 array_keys($inserts[0]), 1575 $inserts 1576 ); 1577 1578 update_category($categories); 1579 } 1580 } 1581 1582 /** 1583 * Dissociate images from all old categories except their storage category and 1563 1584 * associate to new categories. 1585 * 1586 * This function will preserve ranks 1564 1587 * 1565 1588 * @param array images … … 1574 1597 } 1575 1598 1576 // let's first break links with all albums but their "storage album"1599 // let's first break links with all old albums but their "storage album" 1577 1600 $query = ' 1578 1601 DELETE '.IMAGE_CATEGORY_TABLE.'.* … … 1580 1603 JOIN '.IMAGES_TABLE.' ON image_id=id 1581 1604 WHERE id IN ('.implode(',', $images).') 1605 '.((is_array($categories) and count($categories)>0) ? 'AND category_id NOT IN ('.implode(',', $categories).')' : null).' 1582 1606 AND (storage_category_id IS NULL OR storage_category_id != category_id) 1583 1607 ;';
Note: See TracChangeset
for help on using the changeset viewer.