2021-04-02 19:20:02 +02:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 11:52:11 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-04-02 19:20:02 +02:00
|
|
|
/**
|
2021-05-19 18:35:13 +02:00
|
|
|
* This class defines a Paginated OrderedCollection based on CodeIgniter4 Pager to get the pagination metadata
|
2021-04-02 19:20:02 +02:00
|
|
|
*
|
2022-02-19 17:06:11 +01:00
|
|
|
* @copyright 2021 Ad Aures
|
2021-04-02 19:20:02 +02:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2021-08-23 13:05:16 +02:00
|
|
|
namespace Modules\Fediverse\Objects;
|
2021-04-02 19:20:02 +02:00
|
|
|
|
2021-05-19 18:35:13 +02:00
|
|
|
use CodeIgniter\Pager\Pager;
|
2021-08-23 13:05:16 +02:00
|
|
|
use Modules\Fediverse\Core\ObjectType;
|
2021-04-02 19:20:02 +02:00
|
|
|
|
|
|
|
class OrderedCollectionObject extends ObjectType
|
|
|
|
{
|
2021-05-18 19:16:36 +02:00
|
|
|
protected string $type = 'OrderedCollection';
|
2021-05-19 18:35:13 +02:00
|
|
|
|
2021-05-18 19:16:36 +02:00
|
|
|
protected int $totalItems;
|
2021-05-19 18:35:13 +02:00
|
|
|
|
2021-06-08 11:52:11 +02:00
|
|
|
protected ?string $first = null;
|
2021-05-19 18:35:13 +02:00
|
|
|
|
2021-06-08 11:52:11 +02:00
|
|
|
protected ?string $current = null;
|
2021-05-19 18:35:13 +02:00
|
|
|
|
2021-06-08 11:52:11 +02:00
|
|
|
protected ?string $last = null;
|
2021-04-02 19:20:02 +02:00
|
|
|
|
|
|
|
/**
|
2021-07-12 20:40:22 +02:00
|
|
|
* @param ObjectType[]|null $orderedItems
|
2021-04-02 19:20:02 +02:00
|
|
|
*/
|
2021-05-06 16:00:48 +02:00
|
|
|
public function __construct(
|
2021-05-14 19:59:35 +02:00
|
|
|
protected ?array $orderedItems = null,
|
2021-05-06 16:00:48 +02:00
|
|
|
?Pager $pager = null
|
|
|
|
) {
|
2021-04-02 19:20:02 +02:00
|
|
|
$this->id = current_url();
|
|
|
|
|
2021-05-06 16:00:48 +02:00
|
|
|
if ($pager !== null) {
|
2021-04-02 19:20:02 +02:00
|
|
|
$totalItems = $pager->getTotal();
|
|
|
|
$this->totalItems = $totalItems;
|
|
|
|
|
2021-05-06 16:00:48 +02:00
|
|
|
if ($totalItems !== 0) {
|
2021-04-02 19:20:02 +02:00
|
|
|
$this->first = $pager->getPageURI($pager->getFirstPage());
|
|
|
|
$this->current = $pager->getPageURI();
|
|
|
|
$this->last = $pager->getPageURI($pager->getLastPage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|