Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
componentparams.php
1<?php
2
4
6
10final class ComponentParams
11{
12 private Grid $grid;
13
14 public function __construct(Grid $grid)
15 {
16 $this->grid = $grid;
17 }
18
19 public static function get(Grid $grid, array $additionParams = []): array
20 {
21 return (new self($grid))->getParams($additionParams);
22 }
23
24 public function getParams(array $additionParams = []): array
25 {
26 $rows = $this->grid->prepareRows();
27 $columns = $this->grid->prepareColumns();
28
29 $pagination = $this->grid->getPagination();
30 $issetPagination = isset($pagination);
31
32 $actionsPanel = $this->grid->getPanel();
33 $issetActionsPanel = isset($actionsPanel);
34 $actionsPanelControls = null;
35 if ($issetActionsPanel)
36 {
37 $actionsPanelControls = [
38 'GROUPS' => [
39 [
40 'ITEMS' => $actionsPanel->getControls(),
41 ],
42 ],
43 ];
44 }
45
46 $pageSizes = null;
47 if ($issetPagination)
48 {
49 $pageSizes = array_map(
50 static function (int $size) {
51 return [
52 'NAME' => (string)$size,
53 'VALUE' => (string)$size,
54 ];
55 },
56 $pagination->getPageSizes()
57 );
58 }
59
60 return $additionParams + [
61 // general
62 'GRID_ID' => $this->grid->getId(),
63 'ROWS' => $rows,
64 'COLUMNS' => $columns,
65 // pagination
66 'NAV_OBJECT' => $pagination,
67 'TOTAL_ROWS_COUNT' => $issetPagination ? $pagination->getRecordCount() : count($rows),
68 'SHOW_PAGINATION' => $issetPagination,
69 'SHOW_TOTAL_COUNTER' => true,
70 'PAGE_SIZES' => $pageSizes,
71 'SHOW_PAGESIZE' => $issetPagination,
72 // actions
73 'ACTION_PANEL' => $actionsPanelControls,
74 'SHOW_ACTION_PANEL' => $issetActionsPanel,
75 'SHOW_ROW_CHECKBOXES' => $issetActionsPanel,
76 'SHOW_SELECTED_COUNTER' => $issetActionsPanel,
77 // sort
78 'ALLOW_COLUMNS_SORT' => true,
79 'ALLOW_COLUMNS_RESIZE' => true,
80 'ALLOW_SORT' => true,
81 // ajax
82 'AJAX_MODE' => 'Y',
83 'AJAX_OPTION_JUMP' => 'N',
84 'AJAX_OPTION_STYLE' => 'N',
85 'AJAX_OPTION_HISTORY' => 'N',
86 // other
87 'HANDLE_RESPONSE_ERRORS' => true,
88 'SHOW_GRID_SETTINGS_MENU' => true,
89 ];
90 }
91}