Changeset 17668


Ignore:
Timestamp:
Aug 30, 2012, 2:52:40 PM (8 years ago)
Author:
plg
Message:

bug 2733 fixed: when creating a sub-album in a private album with
pwg.categories.add, it is automatically private too.

Location:
branches/2.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2.4/admin/include/functions.php

    r17295 r17668  
    11971197 * @return array with ('info' and 'id') or ('error') key
    11981198 */
    1199 function create_virtual_category($category_name, $parent_id=null)
     1199function create_virtual_category($category_name, $parent_id=null, $options=array())
    12001200{
    12011201  global $conf, $user;
     
    12061206    return array('error' => l10n('The name of an album must not be empty'));
    12071207  }
    1208 
    1209   $parent_id = !empty($parent_id) ? $parent_id : 'NULL';
    1210 
     1208   
    12111209  $insert = array(
    12121210    'name' => $category_name,
    12131211    'rank' => 0,
    1214     'commentable' => boolean_to_string($conf['newcat_default_commentable']),
     1212    'global_rank' => 0,
    12151213    );
    12161214
    1217   if ($parent_id != 'NULL')
     1215  // is the album commentable?
     1216  if (isset($options['commentable']) and is_bool($options['commentable']))
     1217  {
     1218    $insert['commentable'] = $options['commentable'];
     1219  }
     1220  else
     1221  {
     1222    $insert['commentable'] = $conf['newcat_default_commentable'];
     1223  }
     1224  $insert['commentable'] = boolean_to_string($insert['commentable']);
     1225
     1226  // is the album temporarily locked? (only visible by administrators,
     1227  // whatever permissions) (may be overwritten if parent album is not
     1228  // visible)
     1229  if (isset($options['visible']) and is_bool($options['visible']))
     1230  {
     1231    $insert['visible'] = $options['visible'];
     1232  }
     1233  else
     1234  {
     1235    $insert['visible'] = $conf['newcat_default_visible'];
     1236  }
     1237  $insert['visible'] = boolean_to_string($insert['visible']);
     1238
     1239  // is the album private? (may be overwritten if parent album is private)
     1240  if (isset($options['status']) and 'private' == $options['status'])
     1241  {
     1242    $insert['status'] = 'private';
     1243  }
     1244  else
     1245  {
     1246    $insert['status'] = $conf['newcat_default_status'];
     1247  }
     1248
     1249  // any description for this album?
     1250  if (isset($options['comment']))
     1251  {
     1252    $insert['comment'] = strip_tags($options['comment']);
     1253  }
     1254
     1255  if (!empty($parent_id) and is_numeric($parent_id))
    12181256  {
    12191257    $query = '
     
    12341272      $insert['visible'] = 'false';
    12351273    }
    1236     else
    1237     {
    1238       $insert['visible'] = boolean_to_string($conf['newcat_default_visible']);
    1239     }
    12401274
    12411275    // at creation, must a category be public or private ? Warning : if the
     
    12461280      $insert['status'] = 'private';
    12471281    }
    1248     else
    1249     {
    1250       $insert['status'] = $conf['newcat_default_status'];
    1251     }
     1282
     1283    $uppercats_prefix = $parent['uppercats'].',';
    12521284  }
    12531285  else
    12541286  {
    1255     $insert['visible'] = boolean_to_string($conf['newcat_default_visible']);
    1256     $insert['status'] = $conf['newcat_default_status'];
    1257     $insert['global_rank'] = $insert['rank'];
     1287    $uppercats_prefix = '';
    12581288  }
    12591289
    12601290  // we have then to add the virtual category
    1261   mass_inserts(
     1291  single_insert(CATEGORIES_TABLE, $insert);
     1292  $inserted_id = pwg_db_insert_id(CATEGORIES_TABLE);
     1293
     1294  single_update(
    12621295    CATEGORIES_TABLE,
    1263     array(
    1264       'site_id', 'name', 'id_uppercat', 'rank', 'commentable',
    1265       'visible', 'status', 'global_rank',
    1266       ),
    1267     array($insert)
     1296    array('uppercats' => $uppercats_prefix.$inserted_id),
     1297    array('id' => $inserted_id)
    12681298    );
    1269 
    1270   $inserted_id = pwg_db_insert_id(CATEGORIES_TABLE);
    1271 
    1272   $query = '
    1273 UPDATE
    1274   '.CATEGORIES_TABLE.'
    1275   SET uppercats = \''.
    1276     (isset($parent) ? $parent{'uppercats'}.',' : '').
    1277     $inserted_id.
    1278     '\'
    1279   WHERE id = '.$inserted_id.'
    1280 ;';
    1281   pwg_query($query);
    12821299
    12831300  update_global_rank();
  • branches/2.4/include/ws_functions.inc.php

    r17470 r17668  
    23032303  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    23042304
     2305  $options = array();
     2306  if (!empty($params['status']) and in_array($params['status'], array('private','public')))
     2307  {
     2308    $options['status'] = $params['status'];
     2309  }
     2310 
     2311  if (!empty($params['visible']) and in_array($params['visible'], array('true','false')))
     2312  {
     2313    $options['visible'] = get_boolean($params['visible']);
     2314  }
     2315 
     2316  if (!empty($params['commentable']) and in_array($params['commentable'], array('true','false')) )
     2317  {
     2318    $options['commentable'] = get_boolean($params['commentable']);
     2319  }
     2320 
     2321  if (!empty($params['comment']))
     2322  {
     2323    $options['comment'] = $params['comment'];
     2324  }
     2325 
     2326
    23052327  $creation_output = create_virtual_category(
    23062328    $params['name'],
    2307     $params['parent']
     2329    $params['parent'],
     2330    $options
    23082331    );
    23092332
     
    23112334  {
    23122335    return new PwgError(500, $creation_output['error']);
    2313   }
    2314  
    2315   $updates = array();
    2316   if ( !empty($params['status']) and in_array($params['status'], array('private','public')) )
    2317   {
    2318     $updates['status'] = $params['status'];
    2319   }
    2320   if ( !empty($params['visible']) and in_array($params['visible'], array('true','false')) )
    2321   {
    2322     $updates['visible'] = $params['visible'];
    2323   }
    2324   if ( !empty($params['commentable']) and in_array($params['commentable'], array('true','false')) )
    2325   {
    2326     $updates['commentable'] = $params['commentable'];
    2327   }
    2328   if ( !empty($params['comment']) )
    2329   {
    2330     $updates['comment'] = strip_tags($params['comment']);
    2331   }
    2332 
    2333   if (!empty($updates))
    2334   {
    2335     single_update(
    2336       CATEGORIES_TABLE,
    2337       $updates,
    2338       array('id'=>$creation_output['id'])
    2339       );
    2340   }
    2341  
    2342   if ( isset($updates['status']) and 'private' == $updates['status'] )
    2343   {
    2344     add_permission_on_category($creation_output['id'], get_admins());
    23452336  }
    23462337
  • branches/2.4/ws.php

    r15850 r17668  
    310310      'parent' => array('default' => null),
    311311      'comment' => array('default' => null),
    312       'visible' => array('default' => boolean_to_string($conf['newcat_default_visible'])),
    313       'status' => array('default' => $conf['newcat_default_status']),
     312      'visible' => array('default' => null),
     313      'status' => array('default' => null),
    314314      'commentable' => array('default' => 'true'),
    315315      ),
Note: See TracChangeset for help on using the changeset viewer.