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
|
|
|
*
|
|
|
|
* @copyright 2021 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace ActivityPub\Objects;
|
|
|
|
|
|
|
|
use ActivityPub\Core\ObjectType;
|
2021-05-19 16:35:13 +00:00
|
|
|
use CodeIgniter\Pager\Pager;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
class OrderedCollectionObject extends ObjectType
|
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
protected string $type = 'OrderedCollection';
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
protected int $totalItems;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
protected ?string $first = null;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
protected ?string $current = null;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
protected ?string $last = null;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-14 17:59:35 +00:00
|
|
|
* @param ObjectType[] $orderedItems
|
2021-04-02 17:20:02 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function __construct(
|
2021-05-14 17:59:35 +00:00
|
|
|
protected ?array $orderedItems = null,
|
2021-05-06 14:00:48 +00:00
|
|
|
?Pager $pager = null
|
|
|
|
) {
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->id = current_url();
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
if ($pager !== null) {
|
2021-04-02 17:20:02 +00:00
|
|
|
$totalItems = $pager->getTotal();
|
|
|
|
$this->totalItems = $totalItems;
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
if ($totalItems !== 0) {
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->first = $pager->getPageURI($pager->getFirstPage());
|
|
|
|
$this->current = $pager->getPageURI();
|
|
|
|
$this->last = $pager->getPageURI($pager->getLastPage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|