Missing implicit pager type

Created on 24 September 2024, 6 months ago

Problem/Motivation

I have a migration based on the `SLO` API (https://opendata.slo.nl/), a dataset that uses a special type of pager.
Instead of the currently available options, it just shares the total amount of data objects and gives you the data, from that you can calculate the page amount. This way you have less boilerplate about paging in the JSON output and a better cache-able JSON.
But now the Json pager selector has no option that can tackle this issue.

Steps to reproduce

Given the following JSON example;
```
{
"count": 2,
"data": [
{
"uuid": "512e4729-03a4-43a2-95ba-758071d1b725",
"title": "abc",
"prefix": "abc"
}
]
}
```
It should know there are 2 pages, since the data now only shows 1 item, and the total amount of items are 2.

We know this makes assumptions, but if the API states this is the behaviour...

Proposed resolution

Introduce a new type of pager, I propose `counter`
Where we add the page when needed.

```
case 'counter':
$count_key = !empty($this->configuration['pager']['count_key']) ? $this->configuration['pager']['count_key'] : 'count';
$key = !empty($this->configuration['pager']['key']) ? $this->configuration['pager']['key'] : 'page';
if ($this->sourceData && array_key_exists($count_key, $this->sourceData)) {
$count = $this->sourceData[$count_key];
$cumulative_items = $items = count($this->sourceData[$this->configuration['item_selector']]);
$path = UrlHelper::parse($url);
$page = $path['query'][$key] ?? 0;

while ($count > $cumulative_items) {
$path['query'][$key] = $page + 1;
$next_urls[] = Url::fromUri($path['path'], [
'query' => $path['query'],
'fragment' => $path['fragment'],
])->toString();
$cumulative_items += $items;
}
}
break;
```

Feature request
Status

Active

Version

6.0

Component

Plugins

Created by

🇳🇱Netherlands makertimswis

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024