1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
grid.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Grid;
4
5use Bitrix\Main\Context;
6use Bitrix\Main\Filter\Filter;
7use Bitrix\Main\Grid\Action\Action;
8use Bitrix\Main\Grid\Action\PaginationAction;
9use Bitrix\Main\Grid\Column\Column;
10use Bitrix\Main\Grid\Column\Columns;
11use Bitrix\Main\Grid\Pagination\PageNavigationStorage;
12use Bitrix\Main\Grid\Pagination\Storage\StorageSupporter;
13use Bitrix\Main\Grid\Panel\Panel;
14use Bitrix\Main\Grid\Row\Assembler\EmptyRowAssembler;
15use Bitrix\Main\Grid\Row\Rows;
16use Bitrix\Main\Grid\UI\GridResponse;
17use Bitrix\Main\Grid\UI\Request\GridRequestFactory;
18use Bitrix\Main\Grid\UI\Response\GridResponseFactory;
19use Bitrix\Main\HttpRequest;
20use Bitrix\Main\UI\PageNavigation;
21
74abstract class Grid
75{
76 use StorageSupporter;
77 use DeprecatedMethods;
78
79 private array $rawRows;
80 private Options $options;
81 private Settings $settings;
82 private Columns $columns;
83 private Rows $rows;
84
85 // optional
86 private ?Panel $panel = null;
87 private ?Filter $filter = null;
88 private ?PageNavigation $pagination = null;
89
90 // internal
91 private array $actionsMap;
94
98 public function __construct(Settings $settings)
99 {
100 $this->settings = $settings;
101 $this->gridRequestFactory = new GridRequestFactory;
102 $this->gridResponseFactory = new GridResponseFactory;
103 }
104
105 #region public api
106
112 final public function getId(): string
113 {
114 return $this->getSettings()->getId();
115 }
116
122 final public function getSettings(): Settings
123 {
124 return $this->settings;
125 }
126
132 final public function getOptions(): Options
133 {
134 $this->options ??= new Options($this->getId());
135
136 return $this->options;
137 }
138
144 final public function getColumns(): Columns
145 {
146 $this->columns ??= $this->createColumns();
147
148 return $this->columns;
149 }
150
156 final public function getRows(): Rows
157 {
158 $this->rows ??= $this->createRows();
159
160 return $this->rows;
161 }
162
168 final public function getPanel(): ?Panel
169 {
170 $this->panel ??= $this->createPanel();
171
172 return $this->panel;
173 }
174
180 final public function getFilter(): ?Filter
181 {
182 $this->filter ??= $this->createFilter();
183
184 return $this->filter;
185 }
186
192 final public function getPagination(): ?PageNavigation
193 {
194 $this->pagination ??= $this->createPagination();
195
196 return $this->pagination;
197 }
198
206 public function setRawRows(iterable $rawValue): void
207 {
208 $this->rawRows = [];
209
210 foreach ($rawValue as $item)
211 {
212 $this->rawRows[] = $item;
213 }
214 }
215
221 final protected function getRawRows(): array
222 {
223 return $this->rawRows;
224 }
225
231 public function prepareRows(): array
232 {
233 return $this->getRows()->prepareRows($this->getRawRows());
234 }
235
241 public function prepareColumns(): array
242 {
243 $result = [];
244
245 foreach ($this->getColumns() as $column)
246 {
247 $result[] = $column;
248 }
249
250 return $result;
251 }
252
262 public function processRequest(?HttpRequest $request = null): void
263 {
264 $request ??= Context::getCurrent()->getRequest();
265 $gridRequest = $this->gridRequestFactory->createFromRequest($request);
266
267 $response = $this->processGridActionsRequest($gridRequest);
268 if ($response instanceof GridResponse)
269 {
270 if ($response->isSendable())
271 {
272 $response->send();
273 }
274
275 return;
276 }
277
278 $panel = $this->getPanel();
279 if (isset($panel))
280 {
281 $response = $panel->processRequest($gridRequest, $this->getFilter());
282 if ($response instanceof GridResponse)
283 {
284 if ($response->isSendable())
285 {
286 $response->send();
287 }
288
289 return;
290 }
291 }
292
293 $response = $this->getRows()->processRequest($gridRequest);
294 if ($response instanceof GridResponse)
295 {
296 if ($response->isSendable())
297 {
298 $response->send();
299 }
300
301 return;
302 }
303 }
304
305 #region orm
306
314 public function getOrmParams(): array
315 {
316 $params = [
317 'select' => $this->getOrmSelect(),
318 'order' => $this->getOrmOrder(),
319 ];
320
321 $filter = $this->getOrmFilter();
322 if (isset($filter))
323 {
324 $params['filter'] = $filter;
325 }
326
327 $pagination = $this->getPagination();
328 if (isset($pagination))
329 {
330 $params['limit'] = $pagination->getLimit();
331 $params['offset'] = $pagination->getOffset();
332 }
333
334 return $params;
335 }
336
344 public function getOrmSelect(): array
345 {
346 return $this->getColumns()->getSelect(
347 $this->getVisibleColumnsIds()
348 );
349 }
350
358 public function getOrmFilter(): ?array
359 {
360 $filter = $this->getFilter();
361 if (isset($filter))
362 {
363 return $filter->getValue();
364 }
365
366 return null;
367 }
368
376 public function getOrmOrder(): array
377 {
378 $sorting = $this->getOptions()->getSorting(
379 $this->getDefaultSorting()
380 );
381
382 return $sorting['sort'];
383 }
384
385 #endregion orm
386 #endregion public api
387
395 protected function getActions(): array
396 {
397 $actions = [];
398
399 $pagination = $this->getPagination();
400 if (isset($pagination))
401 {
402 $actions[] = new PaginationAction($pagination, $this->getPaginationStorage());
403 }
404
405 return $actions;
406 }
407
415 final protected function getActionById(string $id): ?Action
416 {
417 if (empty($id))
418 {
419 return null;
420 }
421
422 if (!isset($this->actionsMap))
423 {
424 $this->actionsMap = [];
425
426 foreach ($this->getActions() as $action)
427 {
428 $this->actionsMap[$action::getId()] = $action;
429 }
430 }
431
432 return $this->actionsMap[$id] ?? null;
433 }
434
445 {
446 $result = null;
447
448 if (!check_bitrix_sessid())
449 {
450 return null;
451 }
452
453 $requestGridId = $request->getGridId();
454 if ($requestGridId !== $this->getId())
455 {
456 return null;
457 }
458
459 $action = $this->getActionById(
460 $request->getGridActionId() ?? ''
461 );
462 if ($action)
463 {
464 $result = $action->processRequest($request->getHttpRequest());
465 }
466 else
467 {
468 return null;
469 }
470
471 return
472 isset($result)
473 ? $this->gridResponseFactory->createFromResult($result)
474 : null
475 ;
476 }
477
486 public function getVisibleColumnsIds(): array
487 {
488 $visibleColumns = $this->getOptions()->GetVisibleColumns();
489 if (empty($visibleColumns))
490 {
491 $visibleColumns = [];
492
493 foreach ($this->getColumns() as $column)
494 {
495 if ($column->isDefault())
496 {
497 $visibleColumns[] = $column->getId();
498 }
499 }
500 }
501
502 return $visibleColumns;
503 }
504
510 protected function getDefaultSorting(): array
511 {
512 return [
513 'ID' => 'ASC',
514 ];
515 }
516
522 abstract protected function createColumns(): Columns;
523
529 protected function createRows(): Rows
530 {
531 $emptyRowAssembler = new EmptyRowAssembler(
532 $this->getVisibleColumnsIds()
533 );
534
535 return new Rows(
536 $emptyRowAssembler
537 );
538 }
539
545 protected function createPanel(): ?Panel
546 {
547 return null;
548 }
549
555 protected function createFilter(): ?Filter
556 {
557 return null;
558 }
559
569 protected function createPagination(): ?PageNavigation
570 {
571 return null;
572 }
573}
574
575trait DeprecatedMethods
576{
589 public function initPagination(int $totalRowsCount, ?string $navId = null): void
590 {
591 $navParams = $this->getOptions()->GetNavParams();
592 if (empty($navId))
593 {
594 $navId = $this->getId() . '_nav';
595 }
596
597 $this->pagination = new PageNavigation($navId);
598 $this->pagination->allowAllRecords(false);
599 $this->pagination->setPageSize($navParams['nPageSize']);
600 $this->pagination->setPageSizes($this->getPageSizes());
601 $this->pagination->setRecordCount($totalRowsCount);
602 $this->pagination->setCurrentPage(1);
603
604 $storage = $this->getPaginationStorage();
605 if ($storage instanceof PageNavigationStorage)
606 {
607 $storage->fill($this->pagination);
608 }
609 }
610
618 protected function getPageSizes(): array
619 {
620 return [
621 5,
622 10,
623 20,
624 50,
625 100,
626 ];
627 }
628}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
createPanel()
Определения grid.php:545
getId()
Определения grid.php:112
getOptions()
Определения grid.php:132
getPanel()
Определения grid.php:168
getFilter()
Определения grid.php:180
getOrmParams()
Определения grid.php:314
getOrmOrder()
Определения grid.php:376
__construct(Settings $settings)
Определения grid.php:98
getActionById(string $id)
Определения grid.php:415
getColumns()
Определения grid.php:144
GridRequestFactory $gridRequestFactory
Определения grid.php:92
getVisibleColumnsIds()
Определения grid.php:486
setRawRows(iterable $rawValue)
Определения grid.php:206
GridResponseFactory $gridResponseFactory
Определения grid.php:93
prepareColumns()
Определения grid.php:241
processRequest(?HttpRequest $request=null)
Определения grid.php:262
getOrmFilter()
Определения grid.php:358
createPagination()
Определения grid.php:569
getPagination()
Определения grid.php:192
createFilter()
Определения grid.php:555
createRows()
Определения grid.php:529
getRawRows()
Определения grid.php:221
getRows()
Определения grid.php:156
processGridActionsRequest(GridRequest $request)
Определения grid.php:444
getSettings()
Определения grid.php:122
prepareRows()
Определения grid.php:231
getOrmSelect()
Определения grid.php:344
getDefaultSorting()
Определения grid.php:510
getActions()
Определения grid.php:395
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$filter
Определения iblock_catalog_list.php:54
$navParams
Определения csv_new_run.php:35
$panel
Определения options.php:177
check_bitrix_sessid($varname='sessid')
Определения tools.php:4686
$settings
Определения product_settings.php:43
if(empty($decryptedData)) $storage
Определения quickway.php:270
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$response
Определения result.php:21
$rows
Определения options.php:264
$action
Определения file_dialog.php:21