Changeset 8272


Ignore:
Timestamp:
Dec 23, 2010, 11:41:28 PM (10 years ago)
Author:
plg
Message:

feature 2082 added: new method pwg.categories.move from the pwg.images.addSimple plugin

Location:
trunk
Files:
2 edited

Legend:

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

    r8266 r8272  
    23092309}
    23102310
     2311function ws_categories_move($params, &$service)
     2312{
     2313  global $conf, $page;
     2314 
     2315  if (!is_admin() || is_adviser() )
     2316  {
     2317    return new PwgError(401, 'Access denied');
     2318  }
     2319
     2320  if (!$service->isPost())
     2321  {
     2322    return new PwgError(405, "This method requires HTTP POST");
     2323  }
     2324
     2325  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
     2326  {
     2327    return new PwgError(403, 'Invalid security token');
     2328  }
     2329
     2330  $params['category_id'] = preg_split(
     2331    '/[\s,;\|]/',
     2332    $params['category_id'],
     2333    -1,
     2334    PREG_SPLIT_NO_EMPTY
     2335    );
     2336  $params['category_id'] = array_map('intval', $params['category_id']);
     2337
     2338  $category_ids = array();
     2339  foreach ($params['category_id'] as $category_id)
     2340  {
     2341    if ($category_id > 0)
     2342    {
     2343      array_push($category_ids, $category_id);
     2344    }
     2345  }
     2346
     2347  if (count($category_ids) == 0)
     2348  {
     2349    return new PwgError(403, 'Invalid category_id input parameter, no category to move');
     2350  }
     2351
     2352  // we can't move physical categories
     2353  $categories_in_db = array();
     2354 
     2355  $query = '
     2356SELECT
     2357    id,
     2358    name,
     2359    dir
     2360  FROM '.CATEGORIES_TABLE.'
     2361  WHERE id IN ('.implode(',', $category_ids).')
     2362;';
     2363  $result = pwg_query($query);
     2364  while ($row = pwg_db_fetch_assoc($result))
     2365  {
     2366    $categories_in_db[$row['id']] = $row;
     2367    // we break on error at first physical category detected
     2368    if (!empty($row['dir']))
     2369    {
     2370      $row['name'] = strip_tags(
     2371        trigger_event(
     2372          'render_category_name',
     2373          $row['name'],
     2374          'ws_categories_move'
     2375          )
     2376        );
     2377     
     2378      return new PwgError(
     2379        403,
     2380        sprintf(
     2381          'Category %s (%u) is not a virtual category, you cannot move it',
     2382          $row['name'],
     2383          $row['id']
     2384          )
     2385        );
     2386    }
     2387  }
     2388
     2389  if (count($categories_in_db) != count($category_ids))
     2390  {
     2391    $unknown_category_ids = array_diff($category_ids, array_keys($categories_in_db));
     2392   
     2393    return new PwgError(
     2394      403,
     2395      sprintf(
     2396        'Category %u does not exist',
     2397        $unknown_category_ids[0]
     2398        )
     2399      );
     2400  }
     2401
     2402  // does this parent exists? This check should be made in the
     2403  // move_categories function, not here
     2404  //
     2405  // 0 as parent means "move categories at gallery root"
     2406  if (!is_numeric($params['parent']))
     2407  {
     2408    return new PwgError(403, 'Invalid parent input parameter');
     2409  }
     2410 
     2411  if (0 != $params['parent']) {
     2412    $params['parent'] = intval($params['parent']);
     2413    $subcat_ids = get_subcat_ids(array($params['parent']));
     2414    if (count($subcat_ids) == 0)
     2415    {
     2416      return new PwgError(403, 'Unknown parent category id');
     2417    }
     2418  }
     2419
     2420  $page['infos'] = array();
     2421  $page['errors'] = array();
     2422  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     2423  move_categories($category_ids, $params['parent']);
     2424  invalidate_user_cache();
     2425
     2426  if (count($page['errors']) != 0)
     2427  {
     2428    return new PwgError(403, implode('; ', $page['errors']));
     2429  }
     2430}
     2431
    23112432function ws_logfile($string)
    23122433{
  • trunk/ws.php

    r8266 r8272  
    278278
    279279  $service->addMethod(
     280    'pwg.categories.move',
     281    'ws_categories_move',
     282    array(
     283      'category_id'=>array('default'=>0),
     284      'parent'=>array('default'=>0),
     285      'pwg_token' => array('default' => null),
     286      ),
     287    '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.'
     288    );
     289 
     290  $service->addMethod(
    280291    'pwg.tags.getAdminList',
    281292    'ws_tags_getAdminList',
Note: See TracChangeset for help on using the changeset viewer.