Changeset 2563

Show
Ignore:
Timestamp:
09/21/08 22:42:17 (5 years ago)
Author:
plg
Message:

new: webservice method pwg.categories.getAdminList was added so that pLoader
can see the list of categories as you can see in the administration
interface : not filtered by individual permissions.

Location:
trunk
Files:
2 modified

Legend:

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

    r2553 r2563  
    437437} 
    438438 
     439/** 
     440 * returns the list of categories as you can see them in administration (web 
     441 * service method). 
     442 * 
     443 * Only admin can run this method and permissions are not taken into 
     444 * account. 
     445 */ 
     446function ws_categories_getAdminList($params, &$service) 
     447{ 
     448  if (!is_admin()) 
     449  { 
     450    return new PwgError(401, 'Access denied'); 
     451  } 
     452 
     453  $query = ' 
     454SELECT 
     455    category_id, 
     456    COUNT(*) AS counter 
     457  FROM '.IMAGE_CATEGORY_TABLE.' 
     458  GROUP BY category_id 
     459;'; 
     460  $nb_images_of = simple_hash_from_query($query, 'category_id', 'counter'); 
     461 
     462  $query = ' 
     463SELECT 
     464    id, 
     465    name, 
     466    uppercats, 
     467    global_rank 
     468  FROM '.CATEGORIES_TABLE.' 
     469;'; 
     470  $result = pwg_query($query); 
     471  $cats = array(); 
     472 
     473  while ($row = mysql_fetch_assoc($result)) 
     474  { 
     475    $id = $row['id']; 
     476    $row['nb_images'] = isset($nb_images_of[$id]) ? $nb_images_of[$id] : 0; 
     477    array_push($cats, $row); 
     478  }    
     479   
     480  usort($cats, 'global_rank_compare'); 
     481  return array( 
     482    'categories' => new PwgNamedArray( 
     483      $cats, 
     484      'category', 
     485      array( 
     486        'id', 
     487        'nb_images', 
     488        'name', 
     489        'uppercats', 
     490        'global_rank', 
     491        ) 
     492      ) 
     493    ); 
     494} 
    439495 
    440496/** 
  • trunk/ws.php

    r2520 r2563  
    187187    'POST method only' 
    188188    ); 
     189 
     190  $service->addMethod( 
     191    'pwg.categories.getAdminList', 
     192    'ws_categories_getAdminList', 
     193    array(), 
     194    'administration method only' 
     195    ); 
    189196} 
    190197