Changeset 1121


Ignore:
Timestamp:
Apr 5, 2006, 12:29:35 AM (18 years ago)
Author:
plg
Message:

feature deleted: code for categories link was too complicated for such a
simple fature. Replaced by static association. Links are not persistent
anymore.

modification removed: #image_category.is_storage replaced by
#images.storage_category_id as in branche 1.5..

Location:
trunk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/cat_modify.php

    r1082 r1121  
    115115   
    116116    // Link the new category to the current category
    117     $query = '
    118 INSERT
    119   INTO '.CATEGORIES_LINK_TABLE.'
    120   (source, destination)
    121   VALUES
    122   ('.$_GET['cat_id'].', '.$output_create['id'].')
    123 ;';
    124     pwg_query($query);
    125 
    126     check_links(array($output_create['id']));
    127     update_category(array($output_create['id']));
    128   }
    129 }
    130 else if (isset($_POST['destination_trueify'])
    131          and isset($_POST['destination_false'])
    132          and count($_POST['destination_false']))
    133 {
    134   $datas = array();
    135  
    136   foreach ($_POST['destination_false'] as $category_id)
    137   {
     117    associate_categories_to_categories(
     118      array($_GET['cat_id']),
     119      array($output_create['id'])
     120      );
     121
     122    // information
    138123    array_push(
    139       $datas,
    140       array(
    141         'source'      => $_GET['cat_id'],
    142         'destination' => $category_id,
     124      $page['infos'],
     125      sprintf(
     126        l10n('Category elements associated to the following categories: %s'),
     127        '<ul><li>'
     128        .get_cat_display_name_from_id($output_create['id'])
     129        .'</li></ul>'
    143130        )
    144131      );
    145132  }
    146  
    147   mass_inserts(
    148     CATEGORIES_LINK_TABLE,
    149     array('source', 'destination'),
    150     $datas
    151     );
    152 
    153   check_links($_POST['destination_false']);
    154   update_category(
    155     $_POST['destination_false'],
    156     true                          // recursive update
    157     );
    158 }
    159 else if (isset($_POST['destination_falsify'])
    160          and isset($_POST['destination_true'])
    161          and count($_POST['destination_true']))
    162 {
    163   foreach ($_POST['destination_true'] as $destination)
    164   {
    165     delete_sources($destination, array($_GET['cat_id']));
    166   }
    167 
    168   update_category(
    169     $_POST['destination_true'],
    170     true                          // recursive update
    171     );
    172 }
    173 else if (isset($_POST['source_trueify'])
    174          and isset($_POST['source_false'])
    175          and count($_POST['source_false']))
    176 {
    177   $datas = array();
    178  
    179   foreach ($_POST['source_false'] as $category_id)
     133}
     134else if (isset($_POST['submitDestinations'])
     135         and isset($_POST['destinations'])
     136         and count($_POST['destinations']) > 0)
     137{
     138  associate_categories_to_categories(
     139    array($_GET['cat_id']),
     140    $_POST['destinations']
     141    );
     142
     143  $category_names = array();
     144  foreach ($_POST['destinations'] as $category_id)
    180145  {
    181146    array_push(
    182       $datas,
    183       array(
    184         'source'      => $category_id,
    185         'destination' => $_GET['cat_id'],
    186         )
    187       );
    188   }
    189  
    190   mass_inserts(
    191     CATEGORIES_LINK_TABLE,
    192     array('source', 'destination'),
    193     $datas
    194     );
    195 
    196   check_links(array($_GET['cat_id']));
    197   update_category(
    198     array($_GET['cat_id']),
    199     true                          // recursive update
    200     );
    201 }
    202 else if (isset($_POST['source_falsify'])
    203          and isset($_POST['source_true'])
    204          and count($_POST['source_true']))
    205 {
    206   delete_sources($_GET['cat_id'], $_POST['source_true']);
    207  
    208   update_category(
    209     array($_GET['cat_id']),
    210     true                          // recursive update
    211     );
    212 }
    213 
     147      $category_names,
     148      get_cat_display_name_from_id($category_id)
     149      );
     150  }
     151
     152  array_push(
     153    $page['infos'],
     154    sprintf(
     155      l10n('Category elements associated to the following categories: %s'),
     156      '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>'
     157      )
     158    );
     159}
    214160
    215161$query = '
     
    382328}
    383329
    384 if (!$category['is_virtual']) //!empty($category['dir']))
     330if (!$category['is_virtual'])
    385331{
    386332  $template->assign_block_vars(
     
    470416// destination categories
    471417$query = '
    472 SELECT DISTINCT id, name, uppercats, global_rank
     418SELECT id,name,uppercats,global_rank
    473419  FROM '.CATEGORIES_TABLE.'
    474     INNER JOIN '.CATEGORIES_LINK_TABLE.' ON destination = id
    475   WHERE source = '.$_GET['cat_id'].'
    476 ;';
    477 display_select_cat_wrapper($query, array(), 'destination_option_true');
    478 
    479 // non destination categories
    480 $destinations = array_merge(
    481   array($_GET['cat_id']),
    482   array_from_query($query, 'id')
     420  WHERE id != '.$category['id'].'
     421;';
     422
     423display_select_cat_wrapper(
     424  $query,
     425  array(),
     426  'category_option_destination'
    483427  );
    484428
    485 $query = '
    486 SELECT DISTINCT id, name, uppercats, global_rank
    487   FROM '.CATEGORIES_TABLE.'
    488   WHERE id NOT IN ('.implode(',', $destinations).')
    489 ;';
    490 display_select_cat_wrapper($query, array(), 'destination_option_false');
    491 
    492 // source categories
    493 $query = '
    494 SELECT DISTINCT id, name, uppercats, global_rank
    495   FROM '.CATEGORIES_TABLE.'
    496     INNER JOIN '.CATEGORIES_LINK_TABLE.' ON source = id
    497   WHERE destination = '.$_GET['cat_id'].'
    498 ;';
    499 display_select_cat_wrapper($query, array(), 'source_option_true');
    500 
    501 // non source categories
    502 $sources = array_merge(
    503   array($_GET['cat_id']),
    504   array_from_query($query, 'id')
    505   );
    506 
    507 $query = '
    508 SELECT DISTINCT id, name, uppercats, global_rank
    509   FROM '.CATEGORIES_TABLE.'
    510   WHERE id NOT IN ('.implode(',', $sources).')
    511 ;';
    512 display_select_cat_wrapper($query, array(), 'source_option_false');
    513429
    514430//----------------------------------------------------------- sending html code
  • trunk/admin/element_set_global.php

    r1120 r1121  
    9696  if ($_POST['associate'] != 0 and count($collection) > 0)
    9797  {
    98     $datas = array();
    99 
     98    associate_images_to_categories(
     99      $collection,
     100      array($_POST['associate'])
     101      );
     102  }
     103
     104  if ($_POST['dissociate'] != 0 and count($collection) > 0)
     105  {
     106    // physical links must not be broken, so we must first retrieve image_id
     107    // which create virtual links with the category to "dissociate from".
    100108    $query = '
    101 SELECT image_id
     109SELECT id
    102110  FROM '.IMAGE_CATEGORY_TABLE.'
    103   WHERE category_id = '.$_POST['associate'].'
    104 ;';
    105     $associated = array_from_query($query, 'image_id');
    106 
    107     $associable = array_diff($collection, $associated);
    108 
    109     if (count($associable) != 0)
    110     {
    111       foreach ($associable as $item)
    112       {
    113         array_push(
    114           $datas,
    115           array(
    116             'category_id' => $_POST['associate'],
    117             'image_id' => $item
    118             )
    119           );
    120       }
    121 
    122       mass_inserts(
    123         IMAGE_CATEGORY_TABLE,
    124         array('image_id', 'category_id'),
    125         $datas
    126         );
    127 
    128       check_links();
    129       update_category(array($_POST['associate']));
    130     }
    131   }
    132 
    133   if ($_POST['dissociate'] != 0 and count($collection) > 0)
    134   {
    135     // First, we must identify which elements in the collection are really
    136     // virtually associated with the category
    137     $query = '
    138 SELECT image_id
    139   FROM '.IMAGE_CATEGORY_TABLE.'
     111    INNER JOIN '.IMAGES_TABLE.' ON image_id = id
    140112  WHERE category_id = '.$_POST['dissociate'].'
    141     AND image_id IN ('.implode(',', $collection).')
    142     AND is_storage = \'false\'
    143 ;';
    144     $associated_images = array_from_query($query, 'image_id');
    145 
    146     // If the same element is associated to a source and its destinations,
    147     // dissociating the element with the source implies dissociating the
    148     // element fwith the destination.
    149     $destinations_of = get_destinations($_POST['dissociate']);
    150 
    151     $associated_categories = array_merge(
    152       array($_POST['dissociate']),
    153       $destinations_of[ $_POST['dissociate'] ]
    154       );
    155 
    156     // Eventually, deletion of associations
     113    AND id IN ('.implode(',', $collection).')
     114    AND category_id != storage_category_id
     115;';
     116    $dissociables = array_from_query($query, 'id');
     117
    157118    $query = '
    158119DELETE
    159120  FROM '.IMAGE_CATEGORY_TABLE.'
    160   WHERE category_id IN ('.implode(',', $associated_categories).'
    161     AND image_id IN ('.implode(',', $associated_images).')
     121  WHERE category_id = '.$_POST['dissociate'].'
     122    AND image_id IN ('.implode(',', $dissociables).')
    162123';
    163124    pwg_query($query);
    164 
    165     // check source/destination links. If category C has for sources A and
    166     // B, if picture 1 was associated to A and B, the previous code lines
    167     // have deleted the link between C and 1, while it should be kept due to
    168     // B. Who said "complicated"?
    169     check_links();
    170 
    171     update_category($associated_categories);
     125   
     126    update_category($_POST['dissociate']);
    172127  }
    173128
     
    319274    AND ic.category_id = c.id
    320275    AND ic.image_id = i.id
    321     AND ic.is_storage = \'false\'
     276    AND ic.category_id != i.storage_category_id
    322277;';
    323278  display_select_cat_wrapper($query, array(), $blockname, true);
  • trunk/admin/include/functions.php

    r1119 r1121  
    153153  // destruction of all the related elements
    154154  $query = '
    155 SELECT image_id
    156   FROM '.IMAGE_CATEGORY_TABLE.'
    157   WHERE is_storage = \'true\'
    158     AND category_id IN ('.
    159     wordwrap(
    160       implode(', ', $ids),
    161       80,
    162       "\n"
    163       ).
    164     ')
     155SELECT id
     156  FROM '.IMAGES_TABLE.'
     157  WHERE storage_category_id IN (
     158'.wordwrap(implode(', ', $ids), 80, "\n").')
    165159;';
    166160  $result = pwg_query($query);
     
    168162  while ($row = mysql_fetch_array($result))
    169163  {
    170     array_push($element_ids, $row['image_id']);
     164    array_push($element_ids, $row['id']);
    171165  }
    172166  delete_elements($element_ids);
     
    194188;';
    195189  pwg_query($query);
    196 
    197   // source/destination links deletion
    198   $query = '
    199 SELECT destination, source
    200   FROM '.CATEGORIES_LINK_TABLE.'
    201   WHERE source IN ('.implode(',', $ids).')
    202     OR destination IN ('.implode(',', $ids).')
    203 ;';
    204   $result = pwg_query($query);
    205 
    206   $sources_of = array();
    207 
    208   while ($row = mysql_fetch_array($result))
    209   {
    210     if (!isset($sources_of[ $row['destination'] ]))
    211     {
    212       $sources_of[ $row['destination'] ] = array();
    213     }
    214 
    215     array_push(
    216       $sources_of[ $row['destination'] ],
    217       $row['source']
    218       );
    219   }
    220 
    221   foreach ($sources_of as $destination => $sources)
    222   {
    223     delete_sources($destination, $sources);
    224   }
    225 
    226   update_category();
    227190
    228191  // destruction of the category
     
    442405       COUNT(image_id) AS nb_images,
    443406       MAX(date_available) AS date_last
    444   FROM '.IMAGES_TABLE.'
    445     INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
     407  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
    446408  WHERE category_id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").')
    447409  GROUP BY category_id
     
    450412  $datas = array();
    451413  $query_ids = array();
    452   while ($row = mysql_fetch_array($result))
     414  while ( $row = mysql_fetch_array( $result ) )
    453415  {
    454416    array_push($query_ids, $row['category_id']);
     
    467429  foreach (array_diff($cat_ids, $query_ids) as $id)
    468430  {
    469     array_push(
    470       $datas,
    471       array(
    472         'id'        => $id,
    473         'nb_images' => 0,
    474         )
    475       );
    476   }
    477 
    478   mass_updates(
    479     CATEGORIES_TABLE,
    480     array(
    481       'primary' => array('id'),
    482       'update'  => array('date_last', 'nb_images')
    483       ),
    484     $datas
    485     );
     431    array_push($datas, array('id' => $id, 'nb_images' => 0));
     432  }
     433
     434  $fields = array('primary' => array('id'),
     435                  'update'  => array('date_last', 'nb_images'));
     436  mass_updates(CATEGORIES_TABLE, $fields, $datas);
    486437
    487438  // representative pictures
     
    13581309function update_path()
    13591310{
    1360   $images_of = array();
    1361 
    1362   $query = '
    1363 SELECT category_id, image_id
    1364   FROM '.IMAGE_CATEGORY_TABLE.'
    1365   WHERE is_storage = \'true\'
    1366 ;';
    1367   $result = pwg_query($query);
    1368   while ($row = mysql_fetch_array($result))
    1369   {
    1370     if (!isset($images_of[ $row['category_id'] ]))
    1371     {
    1372       $images_of[ $row['category_id'] ] = array();
    1373     }
    1374 
    1375     array_push(
    1376       $images_of[ $row['category_id'] ],
    1377       $row['image_id']
    1378       );
    1379   }
    1380 
    1381   $fulldirs = get_fulldirs(
    1382     array_keys($images_of)
    1383     );
    1384 
    1385   foreach ($images_of as $cat_id => $image_ids)
     1311  $query = '
     1312SELECT DISTINCT(storage_category_id)
     1313  FROM '.IMAGES_TABLE.'
     1314;';
     1315  $cat_ids = array_from_query($query, 'storage_category_id');
     1316  $fulldirs = get_fulldirs($cat_ids);
     1317
     1318  foreach ($cat_ids as $cat_id)
    13861319  {
    13871320    $query = '
    13881321UPDATE '.IMAGES_TABLE.'
    13891322  SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file)
    1390   WHERE id IN ('.
    1391       wordwrap(
    1392         implode(', ', $image_ids),
    1393         80,
    1394         "\n").
    1395       ')
     1323  WHERE storage_category_id = '.$cat_id.'
    13961324;';
    13971325    pwg_query($query);
     
    16141542
    16151543/**
    1616  * Returns all destinations of a list of source categories. This function
    1617  * solves transitivity.
    1618  *
    1619  * @param mixed array of category ids, empty for all categories
    1620  */
    1621 function get_destinations($categories = 'all')
    1622 {
    1623   $query = '
    1624 SELECT source, destination
    1625   FROM '.CATEGORIES_LINK_TABLE.'
    1626 ';
    1627   $result = pwg_query($query);
    1628 
    1629   $destinations_of = array();
    1630 
    1631   while ($row = mysql_fetch_array($result))
    1632   {
    1633     if (!isset($destinations_of[ $row['source'] ]))
    1634     {
    1635       $destinations_of[ $row['source'] ] = array();
    1636     }
    1637 
    1638     array_push(
    1639       $destinations_of[ $row['source'] ],
    1640       $row['destination']
    1641       );
    1642   }
    1643 
    1644   // transitivity resolution: if " => " means "source of", if A=>B=>C
    1645   // implies A=>B and A=>C. So A has 2 destinations: B and C.
    1646   do
    1647   {
    1648     // let's suppose we only need a single turn
    1649     $need_new_turn = false;
    1650 
    1651     foreach ($destinations_of as $source => $destinations)
    1652     {
    1653       foreach ($destinations as $destination)
    1654       {
    1655         // does the current destination has destinations itself?
    1656         if (isset($destinations_of[$destination]))
    1657         {
    1658           // are there destinations of current destination not already among
    1659           // destinations of the current source? (advise: take a piece of
    1660           // paper and draw a schema). The source itself must not be counted
    1661           // as a destination, thus avoiding cyclic links.
    1662           $missing_destinations = array_diff(
    1663             $destinations_of[$destination],
    1664             $destinations,
    1665             array($source) // no cyclic link
    1666             );
    1667 
    1668           if (count($missing_destinations) > 0)
    1669           {
    1670             $destinations_of[$source] = array_unique(
    1671               array_merge(
    1672                 $destinations,
    1673                 $missing_destinations
    1674                 )
    1675               );
    1676 
    1677             // a category has a least one new destination, we have to check
    1678             // one more time that it doesn't generate more destinations
    1679             $need_new_turn = true;
    1680           }
    1681         }
    1682       }
    1683     }
    1684   } while ($need_new_turn);
    1685 
    1686   if (is_array($categories))
    1687   {
    1688     $filtered_destinations_of = array();
    1689 
    1690     // Even if there is no destinations for the requested categories, we
    1691     // return empty arrays
    1692     foreach ($categories as $category)
    1693     {
    1694       $filtered_destinations_of[$category] = array();
    1695     }
    1696 
    1697     foreach ($destinations_of as $source => $destinations)
    1698     {
    1699       if (in_array($source, $categories))
    1700       {
    1701         $filtered_destinations_of[$source] = $destinations;
    1702       }
    1703     }
    1704 
    1705     return $filtered_destinations_of;
    1706   }
    1707   else
    1708   {
    1709     return $destinations_of;
    1710   }
    1711 }
    1712 
    1713 /**
    1714  * Returns all sources of a list of destination categories. This function
    1715  * solves transitivity.
    1716  *
    1717  * @param mixed array of category ids, empty for all categories
    1718  */
    1719 function get_sources($categories = 'all')
    1720 {
    1721   $destinations_of = get_destinations();
    1722 
    1723   $sources_of = array();
    1724 
    1725   foreach ($destinations_of as $source => $destinations)
    1726   {
    1727     foreach ($destinations as $destination)
    1728     {
    1729       if (!isset($sources_of[$destination]))
    1730       {
    1731         $sources_of[$destination] = array();
    1732       }
    1733 
    1734       array_push($sources_of[$destination], $source);
    1735     }
    1736   }
    1737 
    1738   // eventually, filter
    1739   if (is_array($categories))
    1740   {
    1741     $filtered_sources_of = array();
    1742 
    1743     // Even if there is no sources for the requested categories, we return
    1744     // empty arrays
    1745     foreach ($categories as $category)
    1746     {
    1747       $filtered_sources_of[$category] = array();
    1748     }
    1749 
    1750     foreach ($sources_of as $destination => $sources)
    1751     {
    1752       if (in_array($destination, $categories))
    1753       {
    1754         $filtered_sources_of[$destination] = $sources;
    1755       }
    1756     }
    1757 
    1758     return $filtered_sources_of;
    1759   }
    1760   else
    1761   {
    1762     return $sources_of;
    1763   }
    1764 }
    1765 
    1766 /**
    1767  * Checks categories links are respected for a given list of destinations.
    1768  *
    1769  * Checking categories links means that each destination must be associated
    1770  * to the images of its sources.
    1771  *
    1772  * @param mixed source category ids
    1773  */
    1774 function check_links($destinations = 'all')
    1775 {
    1776   $sources_of = get_sources($destinations);
    1777 
    1778   if (empty($sources_of))
    1779   {
    1780     return true;
    1781   }
    1782 
    1783   // we need to search images of all sources and destinations
    1784   $images_of = array();
    1785 
    1786   foreach ($sources_of as $destination => $sources)
    1787   {
    1788     $images_of[$destination] = array();
    1789 
    1790     foreach ($sources as $source)
    1791     {
    1792       $images_of[$source] = array();
    1793     }
    1794   }
    1795 
    1796   $query = '
    1797 SELECT image_id, category_id
    1798   FROM '.IMAGE_CATEGORY_TABLE.'
    1799   WHERE category_id IN ('.
    1800     implode(',', array_keys($images_of)).
    1801     ')
    1802 ;';
    1803   $result = pwg_query($query);
    1804 
    1805   while ($row = mysql_fetch_array($result))
    1806   {
    1807     array_push(
    1808       $images_of[ $row['category_id'] ],
    1809       $row['image_id']
    1810       );
    1811   }
    1812 
    1813   $inserts = array();
    1814 
    1815   foreach ($sources_of as $destination => $sources)
    1816   {
    1817     // merge all images from the sources of this destination
    1818     $sources_images = array();
    1819 
    1820     foreach ($sources as $source)
    1821     {
    1822       $sources_images = array_merge(
    1823         $sources_images,
    1824         $images_of[$source]
    1825         );
    1826     }
    1827 
    1828     $sources_images = array_unique($sources_images);
    1829 
    1830     // are there images among the sources that are not linked to the
    1831     // destination?
    1832     $missing_images = array_diff(
    1833       $sources_images,
    1834       $images_of[$destination]
    1835       );
    1836 
    1837     // if we find missing images (missing links in reality), we prepare the
    1838     // final mass_inserts
    1839     if (count($missing_images) > 0)
    1840     {
    1841       foreach ($missing_images as $missing_image)
    1842       {
    1843         array_push(
    1844           $inserts,
    1845           array(
    1846             'category_id' => $destination,
    1847             'image_id'    => $missing_image,
    1848             )
    1849           );
    1850       }
    1851     }
    1852   }
    1853 
    1854   if (count($inserts) > 0)
    1855   {
    1856     mass_inserts(
    1857       IMAGE_CATEGORY_TABLE,
    1858       array_keys($inserts[0]),
    1859       $inserts
    1860       );
    1861   }
    1862 }
    1863 
    1864 /**
    1865  * Based on categories links, delete image_category links on destinations.
    1866  *
    1867  * The rule is the following: if an image belong to the category and to the
    1868  * source, we suppose it comes from the source. If the source/destination
    1869  * link is broken, we delete the image/category link if the only origin of
    1870  * the link was the broken categories link.
    1871  *
    1872  * Example: "=>" means "source of". Between brackets the associated images.
    1873  *
    1874  * A (1,2,9) => \
    1875  *               |=> C (1,2,3,4,5,9) => D (1,2,3,4,5,6,9)
    1876  * B (3,4,9) => /
    1877  *
    1878  * In category C, we suppose (1,2) come from A, (3,4) from B, 9 from A or B
    1879  * and 5 was manually added. In category D, 6 was added manually.
    1880  *
    1881  * If we break A=>C, C and D loose (1,2) but not 9 because it can come from
    1882  * B. If we break C=>D, D loose (3,4,5,9) but not 6 because it was
    1883  * associated manually to 9.
    1884  *
    1885  * Warning: only virtual links can be removed, physical links are protected.
    1886  *
    1887  * @param int destination
    1888  * @param array sources
    1889  */
    1890 function delete_sources($destination, $sources)
    1891 {
    1892   // if no sources to unlink, we stop with OK status
    1893   if (count($sources) == 0)
    1894   {
    1895     return true;
    1896   }
    1897 
    1898   $query = '
    1899 DELETE
    1900   FROM '.CATEGORIES_LINK_TABLE.'
    1901   WHERE destination = '.$destination.'
    1902     AND source IN ('.implode(',', $sources).')
    1903 ;';
    1904   pwg_query($query);
    1905 
    1906   // The strategy is the following:
    1907   //
    1908   // * first we brutally delete the image/category associations on
    1909   // destinations categories for all images belonging to sources.
    1910   //
    1911   // * then we check_links on destinations to rebuild missing image/category
    1912   // associations.
    1913 
    1914   // what are the images associated to the sources to unlink
    1915   $query = '
    1916 SELECT image_id
    1917   FROM '.IMAGE_CATEGORY_TABLE.'
    1918   WHERE category_id IN ('.
    1919     implode(',', $sources).
    1920     ')
    1921 ;';
    1922   $sources_images = array_unique(
    1923     array_from_query($query, 'image_id')
    1924     );
    1925 
    1926   if (count($sources_images) == 0)
    1927   {
    1928     return true;
    1929   }
    1930 
    1931   // retrieve all direct and indirect destinations of the current
    1932   // destination
    1933   $destinations_of = get_destinations(array($destination));
    1934 
    1935   $destinations = array_merge(
    1936     array($destination),
    1937     $destinations_of[$destination]
    1938     );
    1939 
    1940   // unlink sources images from destinations
    1941   $query = '
    1942 DELETE
    1943   FROM '.IMAGE_CATEGORY_TABLE.'
    1944   WHERE category_id IN ('.implode(',', $destinations).')
    1945     AND image_id IN ('.implode(',', $sources_images).')
    1946     AND is_storage = \'false\'
    1947 ;';
    1948   pwg_query($query);
    1949 
    1950   // if the representative thumbnail of destinations was a picture from
    1951   // $sources_images, we request a new random representant
    1952   $query = '
    1953 SELECT id, representative_picture_id
    1954   FROM '.CATEGORIES_TABLE.'
    1955   WHERE id IN ('.implode(',', $destinations).')
    1956 ;';
    1957   $result = pwg_query($query);
    1958 
    1959   $request_random = array();
    1960 
    1961   while ($row = mysql_fetch_array($result))
    1962   {
    1963     if (isset($row['representative_picture_id']))
    1964     {
    1965       if (in_array($row['representative_picture_id'], $sources_images))
    1966       {
    1967         array_push($request_random, $row['id']);
    1968       }
    1969     }
    1970   }
    1971 
    1972   set_random_representant($request_random);
    1973 
    1974   // eventually, we check_links to rebuild missing associations
    1975   check_links($destinations);
    1976 
    1977   return true;
    1978 }
    1979 
    1980 /**
    19811544 * create a virtual category
    19821545 *
     
    23001863
    23011864}
     1865
     1866/**
     1867 * Associate a list of images to a list of categories.
     1868 *
     1869 * The function will not duplicate links
     1870 *
     1871 * @param array images
     1872 * @param array categories
     1873 * @return void
     1874 */
     1875function associate_images_to_categories($images, $categories)
     1876{
     1877  if (count($images) == 0
     1878      or count($categories) == 0)
     1879  {
     1880    return false;
     1881  }
     1882
     1883  $query = '
     1884DELETE
     1885  FROM '.IMAGE_CATEGORY_TABLE.'
     1886  WHERE image_id IN ('.implode(',', $images).')
     1887    AND category_id IN ('.implode(',', $categories).')
     1888;';
     1889  pwg_query($query);
     1890
     1891  $inserts = array();
     1892  foreach ($categories as $category_id)
     1893  {
     1894    foreach ($images as $image_id)
     1895    {
     1896      array_push(
     1897        $inserts,
     1898        array(
     1899          'image_id' => $image_id,
     1900          'category_id' => $category_id,
     1901          )
     1902        );
     1903    }
     1904  }
     1905 
     1906  mass_inserts(
     1907    IMAGE_CATEGORY_TABLE,
     1908    array_keys($inserts[0]),
     1909    $inserts
     1910    );
     1911
     1912  update_category($categories);
     1913}
     1914
     1915/**
     1916 * Associate images associated to a list of source categories to a list of
     1917 * destination categories.
     1918 *
     1919 * @param array sources
     1920 * @param array destinations
     1921 * @return void
     1922 */
     1923function associate_categories_to_categories($sources, $destinations)
     1924{
     1925  if (count($sources) == 0)
     1926  {
     1927    return false;
     1928  }
     1929
     1930  $query = '
     1931SELECT image_id
     1932  FROM '.IMAGE_CATEGORY_TABLE.'
     1933  WHERE category_id IN ('.implode(',', $sources).')
     1934;';
     1935  $images = array_from_query($query, 'image_id');
     1936
     1937  associate_images_to_categories($images, $destinations);
     1938}
    23021939?>
  • trunk/admin/include/functions_metadata.php

    r1119 r1121  
    247247SELECT id, path
    248248  FROM '.IMAGES_TABLE.'
    249     INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
    250   WHERE is_storage = \'true\'
    251     AND category_id IN ('.implode(',', $cat_ids).')';
     249  WHERE storage_category_id IN ('.implode(',', $cat_ids).')';
    252250  if ($only_new)
    253251  {
  • trunk/admin/maintenance.php

    r1111 r1121  
    4848  case 'categories' :
    4949  {
    50     check_links();
    5150    update_uppercats();
    5251    update_category('all');
  • trunk/admin/picture_modify.php

    r1119 r1121  
    122122    and count($_POST['cat_dissociated']) > 0)
    123123{
    124   $datas = array();
    125 
    126   foreach ($_POST['cat_dissociated'] as $category_id)
    127   {
    128     array_push(
    129       $datas,
    130       array(
    131         'image_id' => $_GET['image_id'],
    132         'category_id' => $category_id
    133         )
    134       );
    135   }
    136 
    137   mass_inserts(
    138     IMAGE_CATEGORY_TABLE,
    139     array('image_id', 'category_id'),
    140     $datas
     124  associate_images_to_categories(
     125    array($_GET['image_id']),
     126    $_POST['cat_dissociated']
    141127    );
    142 
    143   check_links();
    144   update_category($_POST['cat_dissociated']);
    145128}
    146129// dissociate the element from categories (but not from its storage category)
     
    149132    and count($_POST['cat_associated']) > 0)
    150133{
    151   $associated_categories = $_POST['cat_associated'];
    152 
    153   // If the same element is associated to a source and its destinations,
    154   // dissociating the element with the source implies dissociating the
    155   // element fwith the destination.
    156   $destinations_of = get_destinations($_POST['cat_associated']);
    157   foreach ($destinations_of as $source => $destinations)
    158   {
    159     $associated_categories = array_merge(
    160       $associated_categories,
    161       $destinations
    162       );
    163   }
    164 
    165134  $query = '
    166135DELETE FROM '.IMAGE_CATEGORY_TABLE.'
    167136  WHERE image_id = '.$_GET['image_id'].'
    168     AND category_id IN ('.implode(',', $associated_categories).')
    169     AND is_storage = \'false\'
     137    AND category_id IN ('.implode(',', $_POST['cat_associated']).')
    170138';
    171139  pwg_query($query);
    172 
    173   check_links();
     140 
    174141  update_category($_POST['cat_associated']);
    175142}
     
    202169SELECT *
    203170  FROM '.IMAGES_TABLE.'
    204     INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
    205171  WHERE id = '.$_GET['image_id'].'
    206     AND is_storage = \'true\'
    207172;';
    208173$row = mysql_fetch_array(pwg_query($query));
    209174
    210 $storage_category_id = $row['category_id'];
     175$storage_category_id = $row['storage_category_id'];
    211176$image_file = $row['file'];
    212177
     
    397362    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
    398363  WHERE image_id = '.$_GET['image_id'].'
    399     AND is_storage = \'false\'
     364    AND id != '.$storage_category_id.'
    400365;';
    401366display_select_cat_wrapper($query, array(), 'associated_option');
  • trunk/admin/rating.php

    r1090 r1121  
    183183       i.tn_ext,
    184184       i.average_rate,
     185       i.storage_category_id,
    185186       MAX(r.date)          AS recently_rated,
    186187       COUNT(r.rate)        AS nb_rates,
    187188       SUM(r.rate)          AS sum_rates,
    188        ROUND(STD(r.rate),2) AS std_rates,
    189        ic.category_id       AS storage_category_id
     189       ROUND(STD(r.rate),2) AS std_rates
    190190  FROM '.RATE_TABLE.' AS r
    191191    LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id
    192     INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
    193192  WHERE 1 = 1 ' . $display_filter . '
    194     AND ic.is_storage = \'true\'
    195193  GROUP BY r.element_id
    196194  ORDER BY ' . $available_order_by[$order_by_index][1] .'
  • trunk/admin/site_update.php

    r1119 r1121  
    369369SELECT id, path
    370370  FROM '.IMAGES_TABLE.'
    371     INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
    372   WHERE is_storage = \'true\'
    373     AND category_id IN ('.
    374       wordwrap(
     371  WHERE storage_category_id IN ('
     372      .wordwrap(
    375373        implode(', ', $cat_ids),
    376374        80,
    377375        "\n"
    378         ).
    379       ')
     376        ).')
    380377;';
    381378    $result = pwg_query($query);
     
    459456            : null,
    460457          'path'           => $path,
     458          'storage_category_id' => $db_fulldirs[$dirname],
    461459          );
    462460
     
    470468          array(
    471469            'image_id'    => $insert{'id'},
    472             'category_id' => $db_fulldirs[$dirname],
    473             'is_storage'  => 'true',
     470            'category_id' => $insert['storage_category_id'],
    474471            )
    475472          );
     
    509506          ? $fs[$path]['representative_ext']
    510507          : null,
     508        'storage_category_id' => $db_fulldirs[$dirname],
    511509        );
    512510
     
    520518        array(
    521519          'image_id'    => $insert{'id'},
    522           'category_id' => $db_fulldirs[$dirname],
    523           'is_storage'  => 'true',
     520          'category_id' => $insert['storage_category_id'],
    524521          )
    525522        );
     
    553550        IMAGE_CATEGORY_TABLE,
    554551        array(
    555           'image_id','category_id', 'is_storage',
     552          'image_id','category_id',
    556553          ),
    557554        $insert_links
     
    610607SELECT id
    611608  FROM '.IMAGES_TABLE.'
    612     INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
    613   WHERE is_storage = \'true\'
    614     AND category_id = '.$row['storage_category_id'].'
     609  WHERE storage_category_id = '.$row['storage_category_id'].'
    615610    AND file = \''.$row['file'].'\'
    616611;';
     
    659654  if (!$simulate)
    660655  {
    661     $start = get_moment();
    662     check_links('all');
    663     echo '<!-- check_links(all) : ';
    664     echo get_elapsed_time($start,get_moment());
    665     echo ' -->'."\n";
    666656    $start = get_moment();
    667657    update_category('all');
  • trunk/include/constants.php

    r1119 r1121  
    7070define('SEARCH_TABLE', $prefixeTable.'search');
    7171define('USER_MAIL_NOTIFICATION_TABLE', $prefixeTable.'user_mail_notification');
    72 define('CATEGORIES_LINK_TABLE', $prefixeTable.'categories_link');
    7372define('TAGS_TABLE', $prefixeTable.'tags');
    7473define('IMAGE_TAG_TABLE', $prefixeTable.'image_tag');
  • trunk/install/phpwebgallery_structure.sql

    r1119 r1121  
    4343
    4444--
    45 -- Table structure for table `phpwebgallery_categories_link`
    46 --
    47 
    48 DROP TABLE IF EXISTS `phpwebgallery_categories_link`;
    49 CREATE TABLE `phpwebgallery_categories_link` (
    50   `source` smallint(5) unsigned NOT NULL default '0',
    51   `destination` smallint(5) unsigned NOT NULL default '0',
    52   PRIMARY KEY  (`source`,`destination`)
    53 ) TYPE=MyISAM;
    54 
    55 --
    5645-- Table structure for table `phpwebgallery_comments`
    5746--
     
    139128  `image_id` mediumint(8) unsigned NOT NULL default '0',
    140129  `category_id` smallint(5) unsigned NOT NULL default '0',
    141   `is_storage` enum('true','false') default 'false',
    142130  PRIMARY KEY  (`image_id`,`category_id`),
    143131  KEY `image_category_i1` (`image_id`),
     
    179167  `has_high` enum('true') default NULL,
    180168  `path` varchar(255) NOT NULL default '',
     169  `storage_category_id` smallint(5) unsigned default NULL,
    181170  PRIMARY KEY  (`id`),
    182171  KEY `images_i2` (`date_available`),
  • trunk/language/en_UK.iso-8859-1/admin.lang.php

    r1120 r1121  
    5555$lang['Categories manual order was saved'] = 'Categories manual order was saved';
    5656$lang['Categories ordered alphanumerically'] = 'Categories ordered alphanumerically';
     57$lang['Category elements associated to the following categories: %s'] = 'Category elements associated to the following categories: %s';
    5758$lang['Check for upgrade failed for unknown reasons.'] = 'Check for upgrade failed for unknown reasons.';
    5859$lang['Check for upgrade'] = 'Check for upgrade';
     
    9192$lang['Interface theme'] = 'Interface theme';
    9293$lang['Language'] = 'Language';
     94$lang['Link all category elements to a new category'] = 'Link all category elements to a new category';
     95$lang['Link all category elements to some existing categories'] = 'Link all category elements to some existing categories';
    9396$lang['Linked categories'] = 'Linked categories';
    9497$lang['Lock gallery'] = 'Lock gallery';
     
    165168$lang['Virtual categories movement'] = 'Virtual categories movement';
    166169$lang['Virtual categories to move'] = 'Virtual categories to move';
     170$lang['Virtual category name'] = 'Virtual category name';
    167171$lang['Webmaster cannot be deleted'] = 'Webmaster cannot be deleted';
    168172$lang['Yes'] = 'Yes';
  • trunk/language/fr_FR.iso-8859-1/admin.lang.php

    r1119 r1121  
    5656$lang['Categories manual order was saved'] = 'L\'ordre manuel des catégories a été sauvegardé';
    5757$lang['Categories ordered alphanumerically'] = 'Catégories ordonnées alphabético-numériquement';
     58$lang['Category elements associated to the following categories: %s'] = 'Les éléments de la catégorie ont été associés aux catégories suivantes : %s';
    5859$lang['Check for upgrade failed for unknown reasons.'] = 'La vérification de la dernière version sur le serveur a échouée pour une raison inconnue.';
    5960$lang['Check for upgrade'] = 'Dernière version ?';
     
    9293$lang['Interface theme'] = 'Theme de l\'interface';
    9394$lang['Language'] = 'Langue';
     95$lang['Link all category elements to a new category'] = 'Associer tous les éléments de la catégorie à une nouvelle catégorie';
     96$lang['Link all category elements to some existing categories'] = 'Associer tous les éléments de la catégorie à des catégories existantes';
    9497$lang['Linked categories'] = 'Catégories associées';
    9598$lang['Lock gallery'] = 'Verrouiller la galerie';
     
    166169$lang['Virtual categories movement'] = 'Déplacement de catégories virtuelles';
    167170$lang['Virtual categories to move'] = 'Catégories virtuelles à déplacer';
     171$lang['Virtual category name'] = 'Nom de la catégorie virtuelle';
    168172$lang['Webmaster cannot be deleted'] = 'Le webmestre ne peut pas être supprimé';
    169173$lang['Yes'] = 'Oui';
  • trunk/template/yoga/admin/cat_modify.tpl

    r1085 r1121  
    141141 
    142142<fieldset>
    143   <legend>{lang:Create a destination category}</legend>
     143  <legend>{lang:Link all category elements to a new category}</legend>
    144144
    145145  <table>
    146146    <tr>
    147       <td>{lang:virtual category name}</td>
     147      <td>{lang:Virtual category name}</td>
    148148      <td><input type="text" name="virtual_name"></td>
    149149    </tr>
    150150
    151151    <tr>
    152       <td>{lang:parent category}</td>
     152      <td>{lang:Parent category}</td>
    153153      <td>
    154154        <select class="categoryList" name="parent">
     
    161161  </table>
    162162
    163   <p style="text-align:center;">
     163  <p>
    164164    <input type="submit" value="{lang:Submit}" name="submitAdd" {TAG_INPUT_ENABLED}/>
    165165    <input type="reset" value="{lang:Reset}" name="reset" />
     
    169169
    170170<fieldset>
    171   <legend>{lang:Source/destination links}</legend>
     171  <legend>{lang:Link all category elements to some existing categories}</legend>
    172172
    173   <table class="doubleSelect">
     173  <table>
    174174    <tr>
     175      <td>{lang:Categories}</td>
    175176      <td>
    176         <h3>{lang:Destination categories}</h3>
    177         <select class="categoryList" name="destination_true[]" multiple="multiple" size="30">
    178           <!-- BEGIN destination_option_true -->
    179           <option {destination_option_true.SELECTED} value="{destination_option_true.VALUE}">{destination_option_true.OPTION}</option>
    180           <!-- END destination_option_true -->
     177        <select class="categoryList" name="destinations[]" multiple="multiple" size="5">
     178          <!-- BEGIN category_option_destination -->
     179          <option {category_option_destination.SELECTED} value="{category_option_destination.VALUE}">{category_option_destination.OPTION}</option>
     180          <!-- END category_option_destination -->
    181181        </select>
    182         <p><input type="submit" value="&raquo;" name="destination_falsify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>
    183       </td>
    184 
    185       <td>
    186         <h3>{lang:Non destination categories}</h3>
    187         <select class="categoryList" name="destination_false[]" multiple="multiple" size="30">
    188           <!-- BEGIN destination_option_false -->
    189           <option {destination_option_false.SELECTED} value="{destination_option_false.VALUE}">{destination_option_false.OPTION}</option>
    190           <!-- END destination_option_false -->
    191         </select>
    192         <p><input type="submit" value="&laquo;" name="destination_trueify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>
    193182      </td>
    194183    </tr>
    195184  </table>
    196185
    197   <table class="doubleSelect">
    198     <tr>
    199       <td>
    200         <h3>{lang:Source categories}</h3>
    201         <select class="categoryList" name="source_true[]" multiple="multiple" size="30">
    202           <!-- BEGIN source_option_true -->
    203           <option {source_option_true.SELECTED} value="{source_option_true.VALUE}">{source_option_true.OPTION}</option>
    204           <!-- END source_option_true -->
    205         </select>
    206         <p><input type="submit" value="&raquo;" name="source_falsify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>
    207       </td>
     186  <p>
     187    <input type="submit" value="{lang:Submit}" name="submitDestinations" {TAG_INPUT_ENABLED}/>
     188    <input type="reset" value="{lang:Reset}" name="reset" />
     189  </p> 
    208190
    209       <td>
    210         <h3>{lang:Non source categories}</h3>
    211         <select class="categoryList" name="source_false[]" multiple="multiple" size="30">
    212           <!-- BEGIN source_option_false -->
    213           <option {source_option_false.SELECTED} value="{source_option_false.VALUE}">{source_option_false.OPTION}</option>
    214           <!-- END source_option_false -->
    215         </select>
    216         <p><input type="submit" value="&laquo;" name="source_trueify" style="font-size:15px;" {TAG_INPUT_ENABLED}/></p>
    217       </td>
    218     </tr>
    219   </table>
    220  
    221191</fieldset>
     192
    222193</form>
Note: See TracChangeset for help on using the changeset viewer.