WS categories getImages, TotalCount #709

Closed
opened 2026-10-05 00:13:00 +02:00 by adam · 3 comments
Owner

In order to build a paginator in a client using the API of piwigo, the total count of images is required.

Here:
https://github.com/Piwigo/Piwigo/blob/c4af38fe48f4d8f0853144fd8d13bc501e27d7ef/include/ws_functions/pwg.categories.php#L160

We are getting the count of the search result, and this information is redundant because a client can count the results in the response. Ex count($result['images'])

Is it possible to include a total_count field, or change the behavior of the actual count?

In order to build a paginator in a client using the API of piwigo, the total count of images is required. Here: https://github.com/Piwigo/Piwigo/blob/c4af38fe48f4d8f0853144fd8d13bc501e27d7ef/include/ws_functions/pwg.categories.php#L160 We are getting the count of the search result, and this information is redundant because a client can count the results in the response. Ex `count($result['images'])` Is it possible to include a `total_count` field, or change the behavior of the actual `count`? <!-- github-sync-id:258818317 -->
adam closed this issue 2026-10-05 00:13:00 +02:00
Author
Owner

I have asked for this more then 1 year and a half ago: http://piwigo.org/forum/viewtopic.php?pid=163539#p163539
Is nobody reading the forum?

Hmm, finally we have total number of unique pictures. I think now we can calculate the correct pagination when getting pictures from a category in recursive mode. I didn't tested yet on galleries that have pictures in multiples categories, but I think this will be fine.

The problem with the modification you made is that you have added this parameter with the same key name like the old one that showed a total different result (the number of images on that request based on "per page" parameter). This was more a lack of a future then a bug. Now what developers will do?

option 1-we must break the compatibility with all version before 2.9.2 ? .... of course this is not possible. We cannot let old versions of piwigo in the air.
option 2-we must get for info about what version is the gallery and use an old method for 2.9.1- and a new one for 2.9.2 (better because will show the total unique pictures).
this will:
-complicate our code
-slow down the response (make a new API request to read the piwigo version using pwg.getInfos ... i think this also need authentication, so unusable for remote sites)

Idea:
Everything was such more easier if you have added this as a new parameter example "total_count". Then it was so simple to keep compatibility between old and new versions of piwigo.

example:

if (!empty($api_response['result']['total_count'] )) { //check if array key exist (for 2.9.2+)
    //use the new method for counting (this is better because we have the total number of unique pictures
}
else { //(for piwigo 2.9.1-)
    //use old method for counting. example https://github.com/eliz82/piwigo2img/blob/master/piwigo2img.php#L262-L273
}
I have asked for this more then 1 year and a half ago: http://piwigo.org/forum/viewtopic.php?pid=163539#p163539 Is nobody reading the forum? Hmm, finally we have total number of unique pictures. I think now we can calculate the correct pagination when getting pictures from a category **in recursive mode**. I didn't tested yet on galleries that have pictures in multiples categories, but I think this will be fine. The problem with the modification you made is that you have added this parameter with the same key name like the old one that showed a total different result (the number of images on that request based on "per page" parameter). This was more a lack of a future then a bug. Now what developers will do? option 1-we must break the compatibility with all version before 2.9.2 ? .... of course this is not possible. We cannot let old versions of piwigo in the air. option 2-we must get for info about what version is the gallery and use an old method for 2.9.1- and a new one for 2.9.2 (better because will show the total unique pictures). this will: -complicate our code -slow down the response (make a new API request to read the piwigo version using pwg.getInfos ... i think this also need authentication, so unusable for remote sites) Idea: Everything was such more easier if you have added this as a new parameter example "total_count". Then it was so simple to keep compatibility between old and new versions of piwigo. example: ``` if (!empty($api_response['result']['total_count'] )) { //check if array key exist (for 2.9.2+) //use the new method for counting (this is better because we have the total number of unique pictures } else { //(for piwigo 2.9.1-) //use old method for counting. example https://github.com/eliz82/piwigo2img/blob/master/piwigo2img.php#L262-L273 } ``` <!-- github-comment-id:334948121 -->
Author
Owner

You're right there should be a total count as in the other api calls

You're right there should be a total count as in the other api calls <!-- github-comment-id:334988729 -->
Author
Owner

Well ... just rename'it "total_count" or something like that. In this way we can check if this new api parameter exist and use new or old method for calculation pagination depending of the Piwigo version.

It remain to you if you let the old "count" also, but like user who reported this said, that "parameter" is redundant . You can always count the number of images by yourself using something like
count($api_response['result']['images'])

Well ... just rename'it "total_count" or something like that. In this way we can check if this new api parameter exist and use new or old method for calculation pagination depending of the Piwigo version. It remain to you if you let the old "count" also, but like user who reported this said, that "parameter" is redundant . You can always count the number of images by yourself using something like `count($api_response['result']['images'])` <!-- github-comment-id:336416155 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#709