Skip to content

Commit

Permalink
Allow to set a custom pagination template
Browse files Browse the repository at this point in the history
  • Loading branch information
qzminski committed Jul 23, 2024
1 parent ebfd1ee commit b9e784d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/Util/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Codefog\HasteBundle\Util;

use Contao\Config;
use Contao\FrontendTemplate;
use Contao\Input;
use Contao\Template;

class Pagination
{
Expand All @@ -29,14 +31,17 @@ class Pagination

protected int $offset;

protected Template|string|null $template = null;

protected \Contao\Pagination $pagination;

public function __construct(int $total, int $perPage, string $urlParameter)
public function __construct(int $total, int $perPage, string $urlParameter, Template|string|null $template = null)
{
$this->setTotal($total);
$this->setPerPage($perPage);
$this->setUrlParameter($urlParameter);
$this->setMaxPaginationLinks(Config::get('maxPaginationLinks'));
$this->setTemplate($template);
}

public function getCurrentState(): int
Expand Down Expand Up @@ -124,6 +129,21 @@ public function getPagination(): \Contao\Pagination
return $this->pagination;
}

public function getTemplate(): ?Template
{
$this->compile();

return $this->template;
}

public function setTemplate(Template|string|null $template): self
{
$this->currentState = self::STATE_DIRTY;
$this->template = $template;

return $this;
}

public function getCurrentPage(): int
{
return (int) (Input::get($this->getUrlParameter()) ?: 1);
Expand Down Expand Up @@ -159,11 +179,16 @@ protected function compile(): void
$limit = $this->getTotal() - $offset;
}

if (is_string($this->template)) {
$this->template = new FrontendTemplate($this->template);
}

$this->pagination = new \Contao\Pagination(
$this->getTotal(),
$this->getPerPage(),
$this->getMaxPaginationLinks(),
$this->getUrlParameter(),
$this->template,
);

$this->currentState = self::STATE_CLEAN;
Expand Down

0 comments on commit b9e784d

Please sign in to comment.