Hello/Hi/Greetings,
When searching or getting images, a order can be selected (id, name, date_available, hit, etc.). But there is no way to obtain in this way the *most*recent* images, as the sql query does not include ASC/DESC statements.
I worked around that in PiwigoPress to ship in order=date_available%20DESC which fortunately translated into the correct sql query.
But it would be nice if the API provides a ascending/descending switch.
I include a tentative patch for this feature (why can other files then images not be uploaded?)
Piwigo version: 2.7.4
diff -urN piwigo/include/ws_functions/pwg.categories.php piwigo-gallery/include/ws_functions/pwg.categories.php
--- piwigo/include/ws_functions/pwg.categories.php 2014-06-02 09:55:46.000000000 +0900
+++ piwigo-gallery/include/ws_functions/pwg.categories.php 2015-08-24 09:38:05.241055642 +0900
@@ -93,6 +93,11 @@
}
$order_by = empty($order_by) ? $conf['order_by'] : 'ORDER BY '.$order_by;
+ if ($params['descending'])
+ {
+ $order_by .= ' DESC';
+ }
+
$query = '
SELECT i.*, GROUP_CONCAT(category_id) AS cat_ids
FROM '. IMAGES_TABLE .' i
@@ -841,4 +846,4 @@
}
}
diff -urN piwigo/include/ws_functions/pwg.images.php piwigo-gallery/include/ws_functions/pwg.images.php
--- piwigo/include/ws_functions/pwg.images.php 2014-11-06 10:17:46.000000000 +0900
+++ piwigo-gallery/include/ws_functions/pwg.images.php 2015-08-24 09:41:36.254724023 +0900
@@ -633,6 +633,10 @@
{
global $conf;
$conf['order_by'] = 'ORDER BY '.$order_by;
+ if ($params['descending'])
+ {
+ $conf['order_by'] .= ' DESC';
+ }
$super_order_by = true; // quick_search_result might be faster
}
@@ -1728,4 +1732,4 @@
return $ret;
}
diff -urN piwigo/ws.php piwigo-gallery/ws.php
--- piwigo/ws.php 2014-08-23 12:40:42.000000000 +0900
+++ piwigo-gallery/ws.php 2015-08-24 09:35:25.260758519 +0900
@@ -171,6 +171,9 @@
'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
'order' => array('default'=>null,
'info'=>'id, file, name, hit, rating_score, date_creation, date_available, random'),
+ 'descending' => array('default'=>false,
+ 'info'=>'sort in descending instead of ascending order',
+ 'type'=>WS_TYPE_BOOL),
), $f_params),
'Returns elements for the corresponding categories.
<br><b>cat_id</b> can be empty if <b>recursive</b> is true.
@@ -270,6 +273,9 @@
'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
'order' => array('default'=>null,
'info'=>'id, file, name, hit, rating_score, date_creation, date_available, random'),
+ 'descending' => array('default'=>false,
+ 'info'=>'sort in descending instead of ascending order',
+ 'type'=>WS_TYPE_BOOL),
), $f_params),
'Returns elements for the corresponding query search.',
$ws_functions_root . 'pwg.images.php'
@@ -371,6 +377,9 @@
'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
'order' => array('default'=>null,
'info'=>'id, file, name, hit, rating_score, date_creation, date_available, random'),
+ 'descending' => array('default'=>false,
+ 'info'=>'sort in descending instead of ascending order',
+ 'type'=>WS_TYPE_BOOL),
), $f_params),
'Returns elements for the corresponding tags. Fill at least tag_id, tag_url_name or tag_name.',
$ws_functions_root . 'pwg.tags.php'
@@ -991,4 +1000,4 @@
);
}
Offline