| | 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 | */ |
| | 446 | function ws_categories_getAdminList($params, &$service) |
| | 447 | { |
| | 448 | if (!is_admin()) |
| | 449 | { |
| | 450 | return new PwgError(401, 'Access denied'); |
| | 451 | } |
| | 452 | |
| | 453 | $query = ' |
| | 454 | SELECT |
| | 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 = ' |
| | 463 | SELECT |
| | 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 | } |