diff options
-rw-r--r-- | include/ws_functions.inc.php | 56 | ||||
-rw-r--r-- | ws.php | 7 |
2 files changed, 63 insertions, 0 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index 4440b15ac..6b64f15ce 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -436,6 +436,62 @@ SELECT id, name, permalink, uppercats, global_rank, ); } +/** + * returns the list of categories as you can see them in administration (web + * service method). + * + * Only admin can run this method and permissions are not taken into + * account. + */ +function ws_categories_getAdminList($params, &$service) +{ + if (!is_admin()) + { + return new PwgError(401, 'Access denied'); + } + + $query = ' +SELECT + category_id, + COUNT(*) AS counter + FROM '.IMAGE_CATEGORY_TABLE.' + GROUP BY category_id +;'; + $nb_images_of = simple_hash_from_query($query, 'category_id', 'counter'); + + $query = ' +SELECT + id, + name, + uppercats, + global_rank + FROM '.CATEGORIES_TABLE.' +;'; + $result = pwg_query($query); + $cats = array(); + + while ($row = mysql_fetch_assoc($result)) + { + $id = $row['id']; + $row['nb_images'] = isset($nb_images_of[$id]) ? $nb_images_of[$id] : 0; + array_push($cats, $row); + } + + usort($cats, 'global_rank_compare'); + return array( + 'categories' => new PwgNamedArray( + $cats, + 'category', + array( + 'id', + 'nb_images', + 'name', + 'uppercats', + 'global_rank', + ) + ) + ); +} /** * returns detailed information for an element (web service method) @@ -186,6 +186,13 @@ function ws_addDefaultMethods( $arr ) ), 'POST method only' ); + + $service->addMethod( + 'pwg.categories.getAdminList', + 'ws_categories_getAdminList', + array(), + 'administration method only' + ); } add_event_handler('ws_add_methods', 'ws_addDefaultMethods'); |