Ignore:
Timestamp:
Dec 5, 2004, 10:28:40 PM (19 years ago)
Author:
plg
Message:
  • on picture.php, related categories under the element are displayed in global_rank order
  • when adding a new virtual category, initializes its global_rank
  • bug fixed : in admin/cat_list, false next rank
  • in admin/cat_modify, complete directory is calculated only if category is not virtual
  • admin/picture_modify rewritten : graphically nearer to admin/cat_modify, virtual associations are back
  • update_category partially rewritten : take an array of categories in parameter, becomes optionnaly recursive, use the set_random_representant function, set a random representant for categories with elements and no representant
  • bug fixed : on a search results screen, elements belonging to more than 1 category were shown more than once
  • bug fixed : in admin/cat_modify, changing a value in a textefield and hitting enter was setting a new random representant
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r633 r635  
    442442
    443443/**
    444  * updates calculated informations about a category : date_last and
     444 * updates calculated informations about a set of categories : date_last and
    445445 * nb_images. It also verifies that the representative picture is really
    446  * linked to the category. Recursive.
     446 * linked to the category. Optionnaly recursive.
    447447 *
    448448 * @param mixed category id
     449 * @param boolean recursive
    449450 * @returns void
    450451 */
    451 function update_category($id = 'all')
    452 {
     452function update_category($ids = 'all', $recursive = false)
     453{
     454  // retrieving all categories to update
    453455  $cat_ids = array();
    454456 
     457  $query = '
     458SELECT 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
    455500  $query = '
    456501SELECT category_id,
    457502       COUNT(image_id) AS nb_images,
    458503       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).')
    467506  GROUP BY category_id
    468 ;';
    469   $result = pwg_query( $query );
     507';
     508  $result = pwg_query($query);
    470509  $datas = array();
    471510  while ( $row = mysql_fetch_array( $result ) )
    472511  {
    473     array_push($cat_ids, $row['category_id']);
    474512    array_push($datas, array('id' => $row['category_id'],
    475513                             'date_last' => $row['date_last'],
     
    480518  mass_updates(CATEGORIES_TABLE, $fields, $datas);
    481519
     520  $query = '
     521UPDATE '.CATEGORIES_TABLE.'
     522  SET representative_picture_id = NULL
     523  WHERE nb_images = 0
     524;';
     525  pwg_query($query);
     526 
    482527  if (count($cat_ids) > 0)
    483528  {
     529    $categories = array();
    484530    // find all categories where the setted representative is not possible
    485531    $query = '
     
    494540    while ($row = mysql_fetch_array($result))
    495541    {
    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 = '
     546SELECT 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);
    525559  }
    526560}
Note: See TracChangeset for help on using the changeset viewer.