1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
pagenavigation.php
См. документацию.
1<?php
8namespace Bitrix\Main\UI;
9
10use Bitrix\Main\Web;
11
27{
28 protected $id;
29 protected $pageSizes = array();
30 protected $pageSize = 20;
31 protected $recordCount;
32 protected $currentPage;
33 protected $allowAll = false;
34 protected $allRecords = false;
35
39 public function __construct(string $id)
40 {
41 $this->id = $id;
42 }
43
49 public function initFromUri()
50 {
51 $navParams = [];
52
53 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
54
55 if(($value = $request->getQuery($this->id)) !== null)
56 {
57 if (is_string($value))
58 {
59 //parameters are in the QUERY_STRING
60 $params = explode("-", $value);
61 for($i = 0, $n = count($params); $i < $n; $i += 2)
62 {
64 }
65 }
66 }
67 else
68 {
69 //probably parametrs are in the SEF URI
70 $matches = [];
71 if(preg_match("'/".preg_quote($this->id, "'")."/page-([\\d]+|all)+(/size-([\\d]+))?'", $request->getRequestUri(), $matches))
72 {
73 $navParams["page"] = $matches[1];
74 if(isset($matches[3]))
75 {
76 $navParams["size"] = $matches[3];
77 }
78 }
79 }
80
81 if(isset($navParams["size"]))
82 {
83 //set page size from user request
84 if(in_array($navParams["size"], $this->pageSizes))
85 {
86 $this->setPageSize((int)$navParams["size"]);
87 }
88 }
89
90 if(isset($navParams["page"]))
91 {
92 if($navParams["page"] == "all" && $this->allowAll == true)
93 {
94 //show all records in one page
95 $this->allRecords = true;
96 }
97 else
98 {
99 //set current page within boundaries
100 $currentPage = (int)$navParams["page"];
101 if($currentPage >= 1)
102 {
103 if($this->recordCount !== null)
104 {
105 $maxPage = $this->getPageCount();
106 if($currentPage > $maxPage)
107 {
108 $currentPage = $maxPage;
109 }
110 }
112 }
113 }
114 }
115 }
116
121 public function getPageCount()
122 {
123 if($this->allRecords)
124 {
125 return 1;
126 }
127 $maxPages = (int)floor($this->recordCount/$this->pageSize);
128 if(($this->recordCount % $this->pageSize) > 0)
129 {
130 $maxPages++;
131 }
132 return $maxPages;
133 }
134
139 public function setPageSize($n)
140 {
141 $this->pageSize = (int)$n;
142 return $this;
143 }
144
149 public function setCurrentPage($n)
150 {
151 $this->currentPage = (int)$n;
152 return $this;
153 }
154
159 public function getCurrentPage()
160 {
161 if($this->currentPage !== null)
162 {
163 return $this->currentPage;
164 }
165 return 1;
166 }
167
172 public function allowAllRecords($mode)
173 {
174 $this->allowAll = (bool)$mode;
175 return $this;
176 }
177
182 public function setRecordCount($n)
183 {
184 $this->recordCount = (int)$n;
185 return $this;
186 }
187
192 public function getRecordCount()
193 {
194 return $this->recordCount;
195 }
196
202 public function setPageSizes(array $sizes)
203 {
204 $this->pageSizes = $sizes;
205 return $this;
206 }
207
212 public function getPageSizes()
213 {
214 return $this->pageSizes;
215 }
216
221 public function getPageSize()
222 {
223 return $this->pageSize;
224 }
225
230 public function getId()
231 {
232 return $this->id;
233 }
234
239 public function getOffset()
240 {
241 if($this->allRecords)
242 {
243 return 0;
244 }
245 return ($this->getCurrentPage() - 1) * $this->pageSize;
246 }
247
252 public function getLimit()
253 {
254 if($this->allRecords)
255 {
256 return $this->getRecordCount();
257 }
258 return $this->pageSize;
259 }
260
265 public function allRecordsShown()
266 {
267 return $this->allRecords;
268 }
269
274 public function allRecordsAllowed()
275 {
276 return $this->allowAll;
277 }
278
287 public function addParams(Web\Uri $uri, $sef, $page, $size = null)
288 {
289 if($sef == true)
290 {
291 $this->clearParams($uri, $sef);
292
293 $path = $uri->getPath();
294 $pos = mb_strrpos($path, "/");
295 $path = mb_substr($path, 0, $pos + 1).$this->id."/page-".$page."/".($size !== null? "size-".$size."/" : '').mb_substr($path, $pos + 1);
296 $uri->setPath($path);
297 }
298 else
299 {
300 $uri->addParams(array($this->id => "page-".$page.($size !== null? "-size-".$size : '')));
301 }
302 return $uri;
303 }
304
311 public function clearParams(Web\Uri $uri, $sef)
312 {
313 if($sef == true)
314 {
315 $path = $uri->getPath();
316 $path = preg_replace("'/".preg_quote($this->id, "'")."/page-([\\d]+|all)+(/size-([\\d]+))?'", "", $path);
317 $uri->setPath($path);
318 }
319 else
320 {
321 $uri->deleteParams(array($this->id));
322 }
323 return $uri;
324 }
325}
$path
Определения access_edit.php:21
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
setPageSizes(array $sizes)
Определения pagenavigation.php:202
allowAllRecords($mode)
Определения pagenavigation.php:172
addParams(Web\Uri $uri, $sef, $page, $size=null)
Определения pagenavigation.php:287
clearParams(Web\Uri $uri, $sef)
Определения pagenavigation.php:311
__construct(string $id)
Определения pagenavigation.php:39
Определения uri.php:17
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$navParams
Определения csv_new_run.php:35
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
Определения cookie.php:3
$i
Определения factura.php:643
$page
Определения order_form.php:33
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$matches
Определения index.php:22
$n
Определения update_log.php:107