76 lines
1.4 KiB
PHP
76 lines
1.4 KiB
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 count(): int
|
|
{
|
|
return $this->count;
|
|
}
|
|
|
|
public function page(): int
|
|
{
|
|
return $this->page;
|
|
}
|
|
|
|
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 $this->limit() ? $this->pageCount = ceil($this->count() / $this->limit()) : 1;
|
|
}
|
|
|
|
public function hasPagination() : int
|
|
{
|
|
return $this->pageCount() > 1;
|
|
}
|
|
|
|
public function skipCount(bool $value) : self
|
|
{
|
|
$this->skipCount = $value;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function resultShown() : int
|
|
{
|
|
$total = $this->page() * $this->limit();
|
|
|
|
return $total <= $this->count() ? $total : $this->count();
|
|
}
|
|
|
|
public function jsonSerialize(): mixed
|
|
{
|
|
$this->pageCount();
|
|
|
|
return $this;
|
|
}
|
|
}
|