Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
rows.php
1<?php
2
4
10
20class Rows
21{
26 private array $actions;
27
29
33 protected array $actionsProviders;
34
40 {
41 $this->rowAssembler = $rowAssembler;
42
43 $this->actionsProviders = [];
44 foreach ($actionsProviders as $provider)
45 {
46 $this->actionsProviders[] = $provider;
47 }
48 }
49
57 public function prepareRows(iterable $rawRows): array
58 {
59 $result = [];
60
61 foreach ($rawRows as $row)
62 {
63 $result[] = $this->prepareRow($row);
64 }
65
66 return $this->rowAssembler->prepareRows($result);
67 }
68
76 protected function prepareRow(array $rawValue): array
77 {
78 $result = [
79 'data' => $rawValue,
80 ];
81
82 if (isset($rawValue['ID']))
83 {
84 $result['id'] = $rawValue['ID'];
85 }
86
87 if (!empty($this->actionsProviders))
88 {
89 $result['actions'] = [];
90
91 foreach ($this->actionsProviders as $provider)
92 {
93 $result['actions'] += $provider->prepareControls($rawValue);
94 }
95 }
96
97 return $result;
98 }
99
103 final public function getActions(): array
104 {
105 if (!isset($this->actions))
106 {
107 $this->actions = [];
108
109 foreach ($this->actionsProviders as $provider)
110 {
111 foreach ($provider->prepareActions() as $action)
112 {
113 $this->actions[$action::getId()] ??= $action;
114 }
115 }
116 }
117
118 return $this->actions;
119 }
120
128 final protected function getActionById(string $id): ?Action
129 {
130 if (empty($id))
131 {
132 return null;
133 }
134
135 return $this->getActions()[$id] ?? null;
136 }
137
145 public function processRequest(GridRequest $request): ?GridResponse
146 {
147 $result = null;
148
149 if (!check_bitrix_sessid())
150 {
151 return null;
152 }
153
154 $actionId = $request->getRowActionId();
155 if (isset($actionId))
156 {
157 $action = $this->getActionById($actionId);
158 if ($action)
159 {
160 $result = $action->processRequest($request->getHttpRequest());
161 }
162 }
163
164 return
165 isset($result)
166 ? (new GridResponseFactory)->createFromResult($result)
167 : null
168 ;
169 }
170}
processRequest(GridRequest $request)
Definition rows.php:145
getActionById(string $id)
Definition rows.php:128
prepareRow(array $rawValue)
Definition rows.php:76
__construct(RowAssembler $rowAssembler, DataProvider ... $actionsProviders)
Definition rows.php:39
prepareRows(iterable $rawRows)
Definition rows.php:57
RowAssembler $rowAssembler
Definition rows.php:28