Changeset 807


Ignore:
Timestamp:
Aug 7, 2005, 8:02:48 PM (19 years ago)
Author:
plg
Message:
  • bug 133 corrected : Deleting user favorites is too restrictive. Instead of deleting a favorite because it belongs to at least one forbidden category, a favorite is deleted if it belongs to no authorized category (which was the expected behaviour).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_4/include/functions_user.inc.php

    r708 r807  
    234234    return;
    235235  }
    236  
    237   $query = '
    238 SELECT f.image_id
     236
     237  // retrieving images allowed : belonging to at least one authorized
     238  // category
     239  $query = '
     240SELECT DISTINCT f.image_id
    239241  FROM '.FAVORITES_TABLE.' AS f INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
    240242    ON f.image_id = ic.image_id
    241243  WHERE f.user_id = '.$user['id'].'
    242     AND ic.category_id IN ('.$user['forbidden_categories'].')
    243 ;';
    244   $result = pwg_query($query);
    245   $elements = array();
    246   while ($row = mysql_fetch_array($result))
    247   {
    248     array_push($elements, $row['image_id']);
    249   }
    250 
    251   if (count($elements) > 0)
     244    AND ic.category_id NOT IN ('.$user['forbidden_categories'].')
     245;';
     246  $result = pwg_query($query);
     247  $authorizeds = array();
     248  while ($row = mysql_fetch_array($result))
     249  {
     250    array_push($authorizeds, $row['image_id']);
     251  }
     252
     253  $query = '
     254SELECT image_id
     255  FROM '.FAVORITES_TABLE.'
     256  WHERE user_id = '.$user['id'].'
     257;';
     258  $result = pwg_query($query);
     259  $favorites = array();
     260  while ($row = mysql_fetch_array($result))
     261  {
     262    array_push($favorites, $row['image_id']);
     263  }
     264
     265  $to_deletes = array_diff($favorites, $authorizeds);
     266
     267  if (count($to_deletes) > 0)
    252268  {
    253269    $query = '
    254270DELETE FROM '.FAVORITES_TABLE.'
    255   WHERE image_id IN ('.implode(',', $elements).')
     271  WHERE image_id IN ('.implode(',', $to_deletes).')
    256272    AND user_id = '.$user['id'].'
    257273;';
Note: See TracChangeset for help on using the changeset viewer.