1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Pager.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Main\Provider\Params;
6
7use Bitrix\Main\ArgumentException;
8use Bitrix\Main\UI\PageNavigation;
9
13class Pager implements PagerInterface
14{
18 public function __construct(protected int $limit = 50, protected int $offset = 0)
19 {
20 $this
21 ->setLimit($this->limit)
22 ->setOffset($this->offset)
23 ;
24 }
25
29 public static function buildFromPageNavigation(PageNavigation $pageNavigation): static
30 {
31 return new static(limit: $pageNavigation->getLimit() ?: 50, offset: $pageNavigation->getOffset() ?: 0);
32 }
33
34 public function getLimit(): int
35 {
36 return $this->limit;
37 }
38
42 public function setLimit(int $limit): static
43 {
44 if ($limit < 1)
45 {
46 throw new ArgumentException('The limit should be a positive number');
47 }
48
49 $this->limit = $limit;
50
51 return $this;
52 }
53
54 public function getOffset(): int
55 {
56 return $this->offset;
57 }
58
62 public function setOffset(int $offset): static
63 {
64 if ($offset < 0)
65 {
66 throw new ArgumentException('The offset should be a not negative number');
67 }
68
69 $this->offset = $offset;
70
71 return $this;
72 }
73
77 public function setPage(int $page): static
78 {
79 if ($page < 1)
80 {
81 throw new ArgumentException('The page should be a positive number');
82 }
83
84 $this->offset = ($page - 1) * $this->limit;
85
86 return $this;
87 }
88
92 public function setSize(int $size): PagerInterface
93 {
94 return $this->setLimit($size);
95 }
96}
static buildFromPageNavigation(PageNavigation $pageNavigation)
Определения Pager.php:29
__construct(protected int $limit=50, protected int $offset=0)
Определения Pager.php:18
setSize(int $size)
Определения Pager.php:92
setLimit(int $limit)
Определения Pager.php:42
setOffset(int $offset)
Определения Pager.php:62
setPage(int $page)
Определения Pager.php:77
$page
Определения order_form.php:33