Changeset 2553

Show
Ignore:
Timestamp:
09/20/08 00:59:41 (5 years ago)
Author:
plg
Message:

improvement: instead of sending the images_max_rank of each category in
pwg.categories.getList so that you can correctly set the rank in
pwg.images.add, the rank is calculated automatically in pwg.images.add so
that the image is added at the end of the category.

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/include/ws_functions.inc.php

    r2548 r2553  
    365365  global $user,$conf; 
    366366 
    367   $query = ' 
    368 SELECT 
    369     category_id, 
    370     MAX(rank) AS max_rank 
    371   FROM '.IMAGE_CATEGORY_TABLE.' 
    372   WHERE rank IS NOT NULL 
    373   GROUP BY category_id 
    374 ;'; 
    375   $max_image_rank_of = simple_hash_from_query( 
    376     $query, 
    377     'category_id', 
    378     'max_rank' 
    379     ); 
    380  
    381367  $where = array(); 
    382368 
     
    429415    { 
    430416      $row[$key] = (int)$row[$key]; 
    431     } 
    432  
    433     if (isset($max_image_rank_of[ $row['id'] ])) 
    434     { 
    435       $row['images_max_rank'] = $max_image_rank_of[ $row['id'] ]; 
    436417    } 
    437418     
     
    451432        'date_last', 
    452433        'max_date_last', 
    453         'images_max_rank', 
    454434        ) 
    455435      ) 
     
    863843  // $fh_log = fopen('/tmp/php.log', 'w'); 
    864844  // fwrite($fh_log, time()."\n"); 
     845  // fwrite($fh_log, 'input rank :'.$params['rank']."\n"); 
    865846  // fwrite($fh_log, 'input:  '.$params['file_sum']."\n"); 
    866847  // fwrite($fh_log, 'input:  '.$params['thumbnail_sum']."\n"); 
     
    959940    'category_id' => $params['category_id'], 
    960941    'image_id' => $image_id, 
    961     'rank' => $params['rank'], 
    962     ); 
     942    ); 
     943 
     944  if ('auto' == $params['rank']) 
     945  { 
     946    $query = ' 
     947SELECT 
     948    MAX(rank) AS max_rank 
     949  FROM '.IMAGE_CATEGORY_TABLE.' 
     950  WHERE rank IS NOT NULL 
     951    AND category_id = '.$params['category_id'].' 
     952;'; 
     953    $row = mysql_fetch_assoc(pwg_query($query)); 
     954    $insert['rank'] = isset($row['max_rank']) ? $row['max_rank']+1 : 1; 
     955  } 
     956  else if (is_numeric($params['rank'])) 
     957  { 
     958    $insert['rank'] = (int)$params['rank']; 
     959  } 
     960   
    963961  mass_inserts( 
    964962    IMAGE_CATEGORY_TABLE, 
  • trunk/tools/piwigo_remote.pl

    r2520 r2553  
    1111GetOptions( 
    1212    \%opt, 
    13     qw/action=s file=s thumbnail=s category_id=i name=s rank=i/ 
     13    qw/action=s file=s thumbnail=s category_id=i name=s rank=s/ 
    1414); 
    1515 
     
    6262        category_id => $opt{category_id}, 
    6363        name => $opt{name}, 
    64         rank => defined($opt{rank}) ? $opt{rank} : 1, 
     64        rank => defined($opt{rank}) ? $opt{rank} : 'auto', 
    6565    }; 
    6666