Changeset 11745 for branches


Ignore:
Timestamp:
Jul 14, 2011, 11:43:51 PM (13 years ago)
Author:
plg
Message:

feature 2376 added: new method pwg.categories.setRepresentative

Location:
branches/2.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/include/ws_functions.inc.php

    r11371 r11745  
    24652465}
    24662466
     2467function ws_categories_setRepresentative($params, &$service)
     2468{
     2469  global $conf;
     2470 
     2471  if (!is_admin())
     2472  {
     2473    return new PwgError(401, 'Access denied');
     2474  }
     2475
     2476  if (!$service->isPost())
     2477  {
     2478    return new PwgError(405, "This method requires HTTP POST");
     2479  }
     2480
     2481  // category_id
     2482  // image_id
     2483
     2484  $params['category_id'] = (int)$params['category_id'];
     2485  if ($params['category_id'] <= 0)
     2486  {
     2487    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
     2488  }
     2489
     2490  // does the category really exist?
     2491  $query='
     2492SELECT
     2493    *
     2494  FROM '.CATEGORIES_TABLE.'
     2495  WHERE id = '.$params['category_id'].'
     2496;';
     2497  $row = pwg_db_fetch_assoc(pwg_query($query));
     2498  if ($row == null)
     2499  {
     2500    return new PwgError(404, "category_id not found");
     2501  }
     2502
     2503  $params['image_id'] = (int)$params['image_id'];
     2504  if ($params['image_id'] <= 0)
     2505  {
     2506    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
     2507  }
     2508 
     2509  // does the image really exist?
     2510  $query='
     2511SELECT
     2512    *
     2513  FROM '.IMAGES_TABLE.'
     2514  WHERE id = '.$params['image_id'].'
     2515;';
     2516
     2517  $row = pwg_db_fetch_assoc(pwg_query($query));
     2518  if ($row == null)
     2519  {
     2520    return new PwgError(404, "image_id not found");
     2521  }
     2522
     2523  // apply change
     2524  $query = '
     2525UPDATE '.CATEGORIES_TABLE.'
     2526  SET representative_picture_id = '.$params['image_id'].'
     2527  WHERE id = '.$params['category_id'].'
     2528;';
     2529  pwg_query($query);
     2530
     2531  $query = '
     2532UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
     2533  SET user_representative_picture_id = NULL
     2534  WHERE cat_id = '.$params['category_id'].'
     2535;';
     2536  pwg_query($query);
     2537}
     2538
    24672539function ws_categories_delete($params, &$service)
    24682540{
  • branches/2.2/ws.php

    r11371 r11745  
    303303    'Move categories. You can give several category_ids, comma separated. Set parent as 0 to move to gallery root. Only virtual categories can be moved.'
    304304    );
    305  
     305
     306  $service->addMethod(
     307    'pwg.categories.setRepresentative',
     308    'ws_categories_setRepresentative',
     309    array(
     310      'category_id'=>array('default'=>0),
     311      'image_id'=>array('default'=>0),
     312      ),
     313    'Set the representative photo for an album. The photo doesn\'t have to belong to the album. POST method only. Administration method only.'
     314    );
     315
    306316  $service->addMethod(
    307317    'pwg.tags.getAdminList',
Note: See TracChangeset for help on using the changeset viewer.