Changeset 23551 for extensions/UserCollections/include/ws_functions.inc.php
- Timestamp:
- Jun 26, 2013, 12:09:21 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/UserCollections/include/ws_functions.inc.php
r23361 r23551 12 12 array( 13 13 'name' => array(), 14 'comment' => array('default' => null), 14 15 'user_id' => array('default' => null, 'info'=>'Admin parameter, default is current user'), 15 'active' => array('default' => 0),16 16 'public' => array('default' => 0), 17 17 ), … … 32 32 'ws_collections_getList', 33 33 array( 34 'col_id' => array('default' => null),35 34 'user_id' => array('default' => null, 'info'=>'Admin parameter, default is current user'), 36 35 'name' => array('default' => null), 37 36 'public' => array('default' => null), 38 'active' => array('default' => null), 39 ), 40 'Retrive a list of collections.' 37 'per_page' => array('default'=>100, 'maxValue'=>ceil($conf['ws_max_images_per_page']/10)), 38 'page' => array('default'=>0), 39 'order' => array('default'=>'username ASC, name ASC'), 40 ), 41 'Returns a list of collections.' 41 42 ); 42 43 … … 81 82 'default'=>array('id','name','url','path'), 82 83 'flags'=>WS_PARAM_FORCE_ARRAY, 83 'info'=>'Available options are: id, file, name, url, path'84 'info'=>'Available options are: id,file,name,url,path,date_creation,collection_add_date,filesize,width,height' 84 85 ), 85 86 ), 86 87 'Returns a serialized version of the collection in CSV.<br>The return type is plain/text whatever you select as response format.' 88 ); 89 90 $service->addMethod( 91 'pwg.collections.getInfo', 92 'ws_collections_getInfo', 93 array( 94 'col_id' => array('info'=>'The current user must be admin or owner of the collection'), 95 ), 96 'Returns basic info about a collection.' 87 97 ); 88 98 } … … 135 145 } 136 146 137 // check active 138 if ($params['active'] != 0 and $params['active'] != 1) 139 { 140 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid "active" value, 0 or 1.'); 141 } 142 143 $UserCollection = new UserCollection('new', array(), $params['name'], $params['active'], $params['public'], $params['user_id']); 144 145 $infos = array_change_key_case($UserCollection->getCollectionInfo(), CASE_LOWER); 146 147 return $infos; 147 $UserCollection = new UserCollection('new', $params['name'], $params['comment'], $params['public'], $params['user_id']); 148 149 return array_change_key_case($UserCollection->getCollectionInfo(), CASE_LOWER); 148 150 } 149 151 … … 233 235 } 234 236 235 // check collection id236 if ( !empty($params['col_id']) and !preg_match('#^[0-9]+$#', $params['col_id']) )237 {238 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id');239 }240 241 237 // check public 242 238 if ( !empty($params['public']) and $params['public'] != 0 and $params['public'] != 1 ) … … 245 241 } 246 242 247 // check active248 if ( !empty($params['active']) and $params['active'] != 0 and $params['active'] != 1 )249 {250 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid "active" value, 0 or 1.');251 }252 253 243 // search 254 244 $where_clauses = array('1=1'); 255 if (!empty($params['col_id']))256 {257 $where_clauses[] = 'c.id = '.$params['col_id'];258 }259 245 if (!empty($params['user_id'])) 260 246 { … … 265 251 $where_clauses[] = 'public = '.$params['public']; 266 252 } 267 if (!empty($params['active']))268 {269 $where_clauses[] = 'active = '.$params['active'];270 }271 253 if (!empty($params['name'])) 272 254 { 273 255 $where_clauses[] = 'name LIKE("%'.pwg_db_real_escape_string($params['name']).'%")'; 274 256 } 257 258 $order_by = !empty($params['order']) ? $params['order'] : 'username ASC, name ASC'; 275 259 276 260 $query = ' … … 283 267 WHERE 284 268 '.implode("\n AND ", $where_clauses).' 285 ORDER BY username ASC, name ASC 269 ORDER BY '.$order_by.' 270 LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']).' 286 271 ;'; 287 272 $sets = hash_from_query($query, 'id'); 288 273 289 $ ret= array();274 $data = array(); 290 275 foreach ($sets as $row) 291 276 { 292 $ ret[] = array(277 $data[] = array( 293 278 'id' => $row['id'], 294 279 'name' => $row['name'], 280 'comment' => $row['comment'], 295 281 'nb_images' => $row['nb_images'], 296 'active' => (bool)$row['active'],297 282 'public' => (bool)$row['public'], 298 283 'date_creation' => $row['date_creation'], … … 303 288 ); 304 289 } 290 291 return array( 292 'paging' => new PwgNamedStruct(array( 293 'page' => $params['page'], 294 'per_page' => $params['per_page'], 295 'count' => count($data) 296 )), 297 'collections' => new PwgNamedArray( 298 $data, 299 'collection' 300 ) 301 ); 305 302 306 303 return $ret; … … 413 410 WHERE 414 411 '. implode("\n AND ", $where_clauses).' 415 GROUP BY i.id 416 '.$order_by.' 417 LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']); 418 419 $result = pwg_query($query); 420 while ($row = pwg_db_fetch_assoc($result)) 421 { 422 $image = array(); 423 foreach (array('id', 'width', 'height', 'hit') as $k) 412 GROUP BY i.id 413 '.$order_by.' 414 LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']).' 415 ;'; 416 417 $result = pwg_query($query); 418 while ($row = pwg_db_fetch_assoc($result)) 424 419 { 425 if (isset($row[$k])) 420 $image = array(); 421 foreach (array('id', 'width', 'height', 'hit') as $k) 426 422 { 427 $image[$k] = (int)$row[$k]; 423 if (isset($row[$k])) 424 { 425 $image[$k] = (int)$row[$k]; 426 } 428 427 } 428 foreach (array('file', 'name', 'comment', 'date_creation', 'date_available') as $k) 429 { 430 $image[$k] = $row[$k]; 431 } 432 $image = array_merge($image, ws_std_get_urls($row)); 433 434 array_push($images, $image); 429 435 } 430 foreach (array('file', 'name', 'comment', 'date_creation', 'date_available') as $k)431 {432 $image[$k] = $row[$k];433 }434 $image = array_merge($image, ws_std_get_urls($row));435 436 array_push($images, $image);437 436 } 438 } 439 440 return array('images' => array( 441 WS_XML_ATTRIBUTES => array( 442 'page' => $params['page'], 443 'per_page' => $params['per_page'], 444 'count' => count($images) 445 ), 446 WS_XML_CONTENT => new PwgNamedArray( 447 $images, 448 'image', 449 ws_std_get_image_xml_attributes() 450 ), 451 )); 437 438 return array( 439 'paging' => new PwgNamedStruct(array( 440 'page' => $params['page'], 441 'per_page' => $params['per_page'], 442 'count' => count($images) 443 )), 444 'images' => new PwgNamedArray( 445 $images, 446 'image', 447 ws_std_get_image_xml_attributes() 448 ) 449 ); 452 450 } 453 451 catch (Exception $e) … … 491 489 } 492 490 } 491 492 /** 493 * get info about a collection 494 */ 495 function ws_collections_getInfo($params, &$service) 496 { 497 global $conf, $user; 498 499 // check status 500 if (is_a_guest()) 501 { 502 return new PwgError(403, 'Forbidden'); 503 } 504 505 // check collection id 506 if (!preg_match('#^[0-9]+$#', $params['col_id'])) 507 { 508 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 509 } 510 511 try { 512 $UserCollection = new UserCollection($params['col_id']); 513 514 return array_change_key_case($UserCollection->getCollectionInfo(), CASE_LOWER); 515 } 516 catch (Exception $e) 517 { 518 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid collection id'); 519 } 520 } 521 493 522 ?>
Note: See TracChangeset
for help on using the changeset viewer.