ulmus/src/SearchRequest/SearchRequestPaginationTrait.php
2022-04-13 03:38:57 +00:00

51 lines
942 B
PHP

<?php
namespace Ulmus\SearchRequest;
trait SearchRequestPaginationTrait {
public int $count = 0;
public int $page = 1;
public int $pageCount = 0;
public int $limit = 25;
public bool $skipCount = false;
public ? array $columns = null;
public function limit(): int
{
return $this->limit;
}
public function offset(): int
{
return (int) ( abs( ( $this->page - 1 ) * $this->limit() ) );
}
public function pagination(int $page, int $itemCount) : void
{
$this->count = $itemCount;
$this->page = $page;
}
public function pageCount() : int
{
return ceil($this->count / $this->limit());
}
public function hasPagination() : int
{
return $this->pageCount() > 1;
}
public function skipCount(bool $value) : self
{
$this->skipCount = $value;
return $this;
}
}