- Timestamp:
- May 31, 2011, 10:25:40 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_category.inc.php
r8802 r11155 534 534 return $image_id; 535 535 } 536 537 /** 538 * create a tree from a flat list of categories, no recursivity for high speed 539 */ 540 function categories_flatlist_to_tree($categories) 541 { 542 $tree = array(); 543 $key_of_cat = array(); 544 545 foreach ($categories as $key => &$node) 546 { 547 $key_of_cat[$node['id']] = $key; 548 549 if (!isset($node['id_uppercat'])) 550 { 551 $tree[$key] = &$node; 552 } 553 else 554 { 555 if (!isset($categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'])) 556 { 557 $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'] = array(); 558 } 559 560 $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'][$key] = &$node; 561 } 562 } 563 564 return $tree; 565 } 536 566 ?> -
trunk/include/ws_functions.inc.php
r11118 r11155 433 433 global $user,$conf; 434 434 435 if ($params['tree_output']) 436 { 437 if (!isset($_GET['format']) or !in_array($_GET['format'], array('php', 'json'))) 438 { 439 // the algorithm used to build a tree from a flat list of categories 440 // keeps original array keys, which is not compatible with 441 // PwgNamedArray. 442 // 443 // PwgNamedArray is useful to define which data is an attribute and 444 // which is an element in the XML output. The "hierarchy" output is 445 // only compatible with json/php output. 446 447 return new PwgError(405, "The tree_output option is only compatible with json/php output formats"); 448 } 449 } 450 435 451 $where = array('1=1'); 436 452 $join_type = 'INNER'; … … 472 488 473 489 $query = ' 474 SELECT id, name, permalink, uppercats, global_rank, 490 SELECT id, name, permalink, uppercats, global_rank, id_uppercat, 475 491 comment, 476 492 nb_images, count_images AS total_nb_images, … … 515 531 } 516 532 usort($cats, 'global_rank_compare'); 517 return array( 518 'categories' => new PwgNamedArray( 519 $cats, 520 'category', 521 array( 522 'id', 523 'url', 524 'nb_images', 525 'total_nb_images', 526 'nb_categories', 527 'date_last', 528 'max_date_last', 533 534 if ($params['tree_output']) 535 { 536 return categories_flatlist_to_tree($cats); 537 } 538 else 539 { 540 return array( 541 'categories' => new PwgNamedArray( 542 $cats, 543 'category', 544 array( 545 'id', 546 'url', 547 'nb_images', 548 'total_nb_images', 549 'nb_categories', 550 'date_last', 551 'max_date_last', 552 ) 529 553 ) 530 ) 531 );554 ); 555 } 532 556 } 533 557 -
trunk/ws.php
r10686 r11155 82 82 'recursive' => array('default'=>false), 83 83 'public' => array('default'=>false), 84 ), 85 'retrieves a list of categories' ); 84 'tree_output' => array('default'=>false), 85 ), 86 'retrieves a list of categories (tree_output option only compatible with json/php output format' ); 86 87 87 88 $service->addMethod('pwg.images.addComment', 'ws_images_addComment',
Note: See TracChangeset
for help on using the changeset viewer.