2021-04-02 17:20:02 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
2021-05-19 16:35:13 +00:00
|
|
|
* This class defines a Paginated OrderedCollection based on CodeIgniter4 Pager to get the pagination metadata
|
2021-04-02 17:20:02 +00:00
|
|
|
*
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2021 Ad Aures
|
2021-04-02 17:20:02 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2021-08-23 11:05:16 +00:00
|
|
|
namespace Modules\Fediverse\Objects;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
use CodeIgniter\Pager\Pager;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
class OrderedCollectionPage extends OrderedCollectionObject
|
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
protected string $type = 'OrderedCollectionPage';
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
protected string $partOf;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
protected ?string $prev = null;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
protected ?string $next = null;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function __construct(Pager $pager, ?array $orderedItems = null)
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
parent::__construct($orderedItems, $pager);
|
|
|
|
|
|
|
|
$isFirstPage = $pager->getCurrentPage() === $pager->getFirstPage();
|
|
|
|
$isLastPage = $pager->getCurrentPage() === $pager->getLastPage();
|
2021-05-06 14:00:48 +00:00
|
|
|
if ($isFirstPage) {
|
|
|
|
$this->first = null;
|
|
|
|
}
|
2022-03-04 14:33:48 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
if ($isLastPage) {
|
|
|
|
$this->last = null;
|
|
|
|
}
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
$this->id = $pager->getPageURI($pager->getCurrentPage());
|
|
|
|
$this->partOf = $pager->getPageURI();
|
|
|
|
$this->prev = $pager->getPreviousPageURI();
|
|
|
|
$this->current = $pager->getPageURI($pager->getCurrentPage());
|
|
|
|
$this->next = $pager->getNextPageURI();
|
|
|
|
}
|
|
|
|
}
|