Changeset 2722
- Timestamp:
- Oct 11, 2008, 10:37:54 PM (16 years ago)
- Location:
- branches/2.0
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0/include/ws_functions.inc.php
r2683 r2722 1065 1065 1066 1066 // let's add links between the image and the categories 1067 //1068 // $params['categories'] should look like 123,12;456,auto;789 which means:1069 //1070 // 1. associate with category 123 on rank 121071 // 2. associate with category 456 on automatic rank1072 // 3. associate with category 789 on automatic rank1073 1067 if (isset($params['categories'])) 1074 1068 { 1075 $cat_ids = array(); 1076 $rank_on_category = array(); 1077 $search_current_ranks = false; 1078 1079 $tokens = explode(';', $params['categories']); 1080 foreach ($tokens as $token) 1081 { 1082 list($cat_id, $rank) = explode(',', $token); 1083 1084 array_push($cat_ids, $cat_id); 1085 1086 if (!isset($rank)) 1087 { 1088 $rank = 'auto'; 1089 } 1090 $rank_on_category[$cat_id] = $rank; 1091 1092 if ($rank == 'auto') 1093 { 1094 $search_current_ranks = true; 1095 } 1096 } 1097 1098 $cat_ids = array_unique($cat_ids); 1099 1100 if (count($cat_ids) > 0) 1101 { 1102 if ($search_current_ranks) 1103 { 1104 $query = ' 1105 SELECT 1106 category_id, 1107 MAX(rank) AS max_rank 1108 FROM '.IMAGE_CATEGORY_TABLE.' 1109 WHERE rank IS NOT NULL 1110 AND category_id IN ('.implode(',', $cat_ids).') 1111 GROUP BY category_id 1112 ;'; 1113 $current_rank_of = simple_hash_from_query( 1114 $query, 1115 'category_id', 1116 'max_rank' 1117 ); 1118 1119 foreach ($cat_ids as $cat_id) 1120 { 1121 if ('auto' == $rank_on_category[$cat_id]) 1122 { 1123 $rank_on_category[$cat_id] = $current_rank_of[$cat_id] + 1; 1124 } 1125 } 1126 } 1127 1128 $inserts = array(); 1129 1130 foreach ($cat_ids as $cat_id) 1131 { 1132 array_push( 1133 $inserts, 1134 array( 1135 'image_id' => $image_id, 1136 'category_id' => $cat_id, 1137 'rank' => $rank_on_category[$cat_id], 1138 ) 1139 ); 1140 } 1141 1142 mass_inserts( 1143 IMAGE_CATEGORY_TABLE, 1144 array_keys($inserts[0]), 1145 $inserts 1146 ); 1147 1148 update_category($cat_ids); 1149 } 1069 ws_add_image_category_relations($image_id, $params['categories']); 1150 1070 } 1151 1071 … … 1497 1417 return $result; 1498 1418 } 1419 1420 function ws_images_setInfo($params, &$service) 1421 { 1422 global $conf; 1423 if (!is_admin() || is_adviser() ) 1424 { 1425 return new PwgError(401, 'Access denied'); 1426 } 1427 1428 // name 1429 // category_id 1430 // file_content 1431 // file_sum 1432 // thumbnail_content 1433 // thumbnail_sum 1434 1435 $params['image_id'] = (int)$params['image_id']; 1436 if ($params['image_id'] <= 0) 1437 { 1438 return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id"); 1439 } 1440 1441 $query=' 1442 SELECT * 1443 FROM '.IMAGES_TABLE.' 1444 WHERE id = '.$params['image_id'].' 1445 ;'; 1446 1447 $image_row = mysql_fetch_assoc(pwg_query($query)); 1448 if ($image_row == null) 1449 { 1450 return new PwgError(404, "image_id not found"); 1451 } 1452 1453 // database registration 1454 $update = array( 1455 'id' => $params['image_id'], 1456 ); 1457 1458 $info_columns = array( 1459 'name', 1460 'author', 1461 'comment', 1462 'level', 1463 'date_creation', 1464 ); 1465 1466 $perform_update = false; 1467 foreach ($info_columns as $key) 1468 { 1469 if (isset($params[$key])) 1470 { 1471 $perform_update = true; 1472 $update[$key] = $params[$key]; 1473 } 1474 } 1475 1476 if ($perform_update) 1477 { 1478 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 1479 mass_updates( 1480 IMAGES_TABLE, 1481 array( 1482 'primary' => array('id'), 1483 'update' => array_diff(array_keys($update), array('id')) 1484 ), 1485 array($update) 1486 ); 1487 } 1488 1489 if (isset($params['categories'])) 1490 { 1491 ws_add_image_category_relations( 1492 $params['image_id'], 1493 $params['categories'] 1494 ); 1495 } 1496 1497 // and now, let's create tag associations 1498 if (isset($params['tag_ids'])) 1499 { 1500 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 1501 add_tags( 1502 explode(',', $params['tag_ids']), 1503 array($params['image_id']) 1504 ); 1505 } 1506 1507 invalidate_user_cache(); 1508 } 1509 1510 function ws_add_image_category_relations($image_id, $categories_string) 1511 { 1512 // let's add links between the image and the categories 1513 // 1514 // $params['categories'] should look like 123,12;456,auto;789 which means: 1515 // 1516 // 1. associate with category 123 on rank 12 1517 // 2. associate with category 456 on automatic rank 1518 // 3. associate with category 789 on automatic rank 1519 $cat_ids = array(); 1520 $rank_on_category = array(); 1521 $search_current_ranks = false; 1522 1523 $tokens = explode(';', $categories_string); 1524 foreach ($tokens as $token) 1525 { 1526 list($cat_id, $rank) = explode(',', $token); 1527 1528 array_push($cat_ids, $cat_id); 1529 1530 if (!isset($rank)) 1531 { 1532 $rank = 'auto'; 1533 } 1534 $rank_on_category[$cat_id] = $rank; 1535 1536 if ($rank == 'auto') 1537 { 1538 $search_current_ranks = true; 1539 } 1540 } 1541 1542 $cat_ids = array_unique($cat_ids); 1543 1544 if (count($cat_ids) > 0) 1545 { 1546 if ($search_current_ranks) 1547 { 1548 $query = ' 1549 SELECT 1550 category_id, 1551 MAX(rank) AS max_rank 1552 FROM '.IMAGE_CATEGORY_TABLE.' 1553 WHERE rank IS NOT NULL 1554 AND category_id IN ('.implode(',', $cat_ids).') 1555 GROUP BY category_id 1556 ;'; 1557 $current_rank_of = simple_hash_from_query( 1558 $query, 1559 'category_id', 1560 'max_rank' 1561 ); 1562 1563 foreach ($cat_ids as $cat_id) 1564 { 1565 if ('auto' == $rank_on_category[$cat_id]) 1566 { 1567 $rank_on_category[$cat_id] = $current_rank_of[$cat_id] + 1; 1568 } 1569 } 1570 } 1571 1572 $inserts = array(); 1573 1574 foreach ($cat_ids as $cat_id) 1575 { 1576 array_push( 1577 $inserts, 1578 array( 1579 'image_id' => $image_id, 1580 'category_id' => $cat_id, 1581 'rank' => $rank_on_category[$cat_id], 1582 ) 1583 ); 1584 } 1585 1586 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 1587 mass_inserts( 1588 IMAGE_CATEGORY_TABLE, 1589 array_keys($inserts[0]), 1590 $inserts 1591 ); 1592 1593 update_category($cat_ids); 1594 } 1595 } 1499 1596 ?> -
branches/2.0/tools/piwigo_remote.pl
r2683 r2722 19 19 20 20 my %conf; 21 $conf{base_url} = 'http://localhost/~pierrick/piwigo/ trunk';21 $conf{base_url} = 'http://localhost/~pierrick/piwigo/2.0'; 22 22 $conf{response_format} = 'json'; 23 23 $conf{username} = 'pierrick'; … … 193 193 } 194 194 195 if ($opt{action} eq 'pwg.images.setInfo') { 196 $form = { 197 method => $opt{action}, 198 }; 199 200 foreach my $key (keys %{ $opt{define} }) { 201 $form->{$key} = $opt{define}{$key}; 202 } 203 204 my $response = $ua->post( 205 $conf{base_url}.'/ws.php?format=json', 206 $form 207 ); 208 209 use Data::Dumper; 210 # print Dumper(from_json($response->content)->{result}); 211 print Dumper($response); 212 } 213 195 214 $query = pwg_ws_get_query( 196 215 method => 'pwg.session.logout' -
branches/2.0/ws.php
r2683 r2722 239 239 'check existence of a photo list' 240 240 ); 241 242 $service->addMethod( 243 'pwg.images.setInfo', 244 'ws_images_setInfo', 245 array( 246 'image_id' => array(), 247 248 'name' => array('default' => null), 249 'author' => array('default' => null), 250 'date_creation' => array('default' => null), 251 'comment' => array('default' => null), 252 'categories' => array('default' => null), 253 'tag_ids' => array('default' => null), 254 'level' => array( 255 'default' => 0, 256 'maxValue' => $conf['available_permission_levels'] 257 ), 258 ), 259 'POST method only. Admin only 260 <br/><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.' 261 ); 241 262 } 242 263
Note: See TracChangeset
for help on using the changeset viewer.