Changeset 11746


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

merge r11745 from branch 2.2 to trunk

feature 2376 added: new method pwg.categories.setRepresentative

Location:
trunk
Files:
2 edited

Legend:

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

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

    r11372 r11746  
    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.