1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
gridcomponent.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Iblock\Component\Grid
;
4
5
use
Bitrix\Iblock\Integration\UI\Grid\General\BaseProvider
;
6
use
Bitrix\Main\AccessDeniedException
;
7
use
Bitrix\Main\Context
;
8
use
Bitrix\Main\Filter\Filter
;
9
use
Bitrix\Main\Grid\MessageType
;
10
use
Bitrix\Main\Grid\Options
;
11
use
Bitrix\Main\HttpRequest
;
12
use
Bitrix\Main\Localization\Loc
;
13
use
Bitrix\Main\Result
;
14
use
Bitrix\Main\UI\PageNavigation
;
15
use
Bitrix\Main\Web\Json
;
16
use CBitrixComponent;
17
use CMain;
18
use Iterator;
19
use Throwable;
20
24
abstract
class
GridComponent
extends
CBitrixComponent
25
{
26
private
array
$rowsFilter;
27
private
Options
$gridOptions;
28
29
protected
PageNavigation
$pagination
;
30
38
abstract
protected
function
getRawRows
(
array
$params
);
39
45
abstract
protected
function
getFilter
(): ?
Filter
;
46
52
abstract
protected
function
getTotalCount
(): int;
53
59
abstract
protected
function
getGridProvider
():
BaseProvider
;
60
66
protected
function
getGridOptions
():
Options
67
{
68
$this->gridOptions ??=
new
Options
($this->
getGridProvider
()->getId());
69
70
return
$this->gridOptions;
71
}
72
80
protected
function
init
(): void
81
{
82
}
83
89
protected
function
initRows
(): void
90
{
91
$params
= [
92
'select'
=> $this->
getRowsSelect
(),
93
'filter'
=> $this->
getRowsFilter
(),
94
'order'
=> $this->
getRowsSorting
(),
95
];
96
97
$pagination = $this->
getRowsPagination
();
98
if
($pagination)
99
{
100
$params
[
'limit'
] =
$pagination
->getLimit();
101
$params
[
'offset'
] =
$pagination
->getOffset();
102
}
103
104
$rows
= [];
105
foreach
($this->
getRawRows
(
$params
) as $row)
106
{
107
$rows
[] = $this->
prepareRow
($row);
108
}
109
110
$this->
getGridProvider
()->setRows(
$rows
);
111
112
if
(
$pagination
)
113
{
114
$this->
getGridProvider
()->setNavObject($pagination);
115
}
116
}
117
125
protected
function
prepareRow
(
array
$row):
array
126
{
127
return
$this->
getGridProvider
()->prepareRow($row);
128
}
129
135
protected
function
initResult
(): void
136
{
137
$this->arResult[
'GRID'
] = $this->
getGridProvider
()->toArray();
138
}
139
145
protected
function
initToolbar
(): void
146
{
147
}
148
152
public
function
executeComponent
()
153
{
154
try
155
{
156
$this->
init
();
157
158
if
(!$this->
checkReadPermissions
())
159
{
160
throw
new
AccessDeniedException
();
161
}
162
163
$this->
processActionsGrid
();
164
165
$this->
initRows
();
166
$this->
initResult
();
167
$this->
initToolbar
();
168
169
$this->
includeComponentTemplate
();
170
}
171
catch
(
AccessDeniedException
$e)
172
{
173
$this->arResult[
'ERROR'
] = Loc::getMessage(
'IBLOCK_GRID_COMPONENT_ERROR_ACCESS_DENIED'
);
174
$this->
includeComponentTemplate
(
'error'
);
175
}
176
}
177
183
protected
function
checkReadPermissions
(): bool
184
{
185
return
true
;
186
}
187
193
final
protected
function
getRowsFilter
():
array
194
{
195
if
(isset($this->rowsFilter))
196
{
197
return
$this->rowsFilter;
198
}
199
200
$filterObject = $this->
getFilter
();
201
if
($filterObject)
202
{
203
$this->rowsFilter = $filterObject->getValue();
204
}
205
else
206
{
207
$this->rowsFilter = [];
208
}
209
210
$additionalFilter = $this->
getAdditionalRowsFilter
();
211
if
(isset($additionalFilter))
212
{
213
$this->rowsFilter[] = $additionalFilter;
214
}
215
216
return
$this->rowsFilter;
217
}
218
219
protected
function
getAdditionalRowsFilter
(): ?
array
220
{
221
return
null
;
222
}
223
229
protected
function
getRowsSelect
():
array
230
{
231
$columns = array_column($this->
getGridProvider
()->getColumns(),
'id'
);
232
233
return
array_filter($columns);
234
}
235
241
protected
function
getRowsSorting
():
array
242
{
243
return
$this->
getGridOptions
()->getSorting()[
'sort'
];
244
}
245
251
protected
function
getRowsPagination
(): ?
PageNavigation
252
{
253
if
(!isset($this->pagination))
254
{
255
$this->pagination =
new
PageNavigation
(
'page'
);
256
$this->pagination->setPageSizes(
257
$this->
getPageSizes
()
258
);
259
$this->pagination->setRecordCount(
260
$this->
getTotalCount
()
261
);
262
263
$this->initFromGrid($this->pagination);
264
$this->pagination->initFromUri();
265
}
266
267
return
$this->pagination
;
268
}
269
275
protected
function
getPageSizes
():
array
276
{
277
$gridSizes = $this->
getGridProvider
()->getPageSizes();
278
$gridSizes = array_column($gridSizes,
'VALUE'
);
279
280
\Bitrix\Main\Type\Collection::normalizeArrayValuesByInt
($gridSizes);
281
282
return
$gridSizes;
283
}
284
292
private
function
initFromGrid(
PageNavigation
$pagination
): void
293
{
294
$params
= $this->
getGridOptions
()->GetNavParams();
295
$pagination->
setPageSize
((
int
)
$params
[
'nPageSize'
]);
296
}
297
303
protected
function
processActionsGrid
(): void
304
{
305
$request
= Context::getCurrent()->getRequest();
306
307
$actionName =
'action_button_'
. $this->
getGridProvider
()->getId();
308
$action
=
$request
->getPost($actionName);
309
310
if
(isset(
$action
))
311
{
312
try
313
{
314
$result
= $this->
processActionGrid
(
$action
,
$request
);
315
if
(isset(
$result
) && !
$result
->isSuccess())
316
{
317
$this->sendErrorsResponse(
318
$result
->getErrorMessages()
319
);
320
}
321
}
322
catch
(
AccessDeniedException
$e)
323
{
324
$this->sendErrorsResponse([
325
Loc::getMessage(
'IBLOCK_GRID_COMPONENT_ERROR_ACCESS_DENIED'
)
326
]);
327
}
328
catch
(Throwable $e)
329
{
330
$this->sendErrorsResponse([
331
$e->getMessage()
332
]);
333
}
334
}
335
}
336
344
protected
function
sendErrorsResponse(
array
$messages
): void
345
{
346
global
$APPLICATION
;
347
351
352
$APPLICATION
->RestartBuffer();
353
354
foreach
(
$messages
as &
$message
)
355
{
356
if
(is_array(
$message
) && isset(
$message
[
'TEXT'
]))
357
{
358
$message
= [
359
'TYPE'
=>
$message
[
'TYPE'
] ??
MessageType::ERROR
,
360
'TEXT'
=>
$message
[
'TEXT'
],
361
];
362
}
363
else
364
{
365
$message
= [
366
'TYPE'
=>
MessageType::ERROR
,
367
'TEXT'
=> (string)
$message
,
368
];
369
}
370
}
371
unset(
$message
);
372
373
CMain::FinalActions(
374
Json::encode([
375
'messages'
=>
$messages
,
376
])
377
);
378
}
379
388
protected
function
processActionGrid
(
string
$actionName,
HttpRequest
$request
): ?
Result
389
{
390
return
null
;
391
}
392
}
$APPLICATION
global $APPLICATION
Определения
include.php:80
Bitrix\Iblock\Component\Grid\GridComponent
Определения
gridcomponent.php:25
Bitrix\Iblock\Component\Grid\GridComponent\getPageSizes
getPageSizes()
Определения
gridcomponent.php:275
Bitrix\Iblock\Component\Grid\GridComponent\initToolbar
initToolbar()
Определения
gridcomponent.php:145
Bitrix\Iblock\Component\Grid\GridComponent\getFilter
getFilter()
Bitrix\Iblock\Component\Grid\GridComponent\getRowsSelect
getRowsSelect()
Определения
gridcomponent.php:229
Bitrix\Iblock\Component\Grid\GridComponent\getAdditionalRowsFilter
getAdditionalRowsFilter()
Определения
gridcomponent.php:219
Bitrix\Iblock\Component\Grid\GridComponent\init
init()
Определения
gridcomponent.php:80
Bitrix\Iblock\Component\Grid\GridComponent\getTotalCount
getTotalCount()
Bitrix\Iblock\Component\Grid\GridComponent\getGridOptions
getGridOptions()
Определения
gridcomponent.php:66
Bitrix\Iblock\Component\Grid\GridComponent\getGridProvider
getGridProvider()
Bitrix\Iblock\Component\Grid\GridComponent\getRowsPagination
getRowsPagination()
Определения
gridcomponent.php:251
Bitrix\Iblock\Component\Grid\GridComponent\prepareRow
prepareRow(array $row)
Определения
gridcomponent.php:125
Bitrix\Iblock\Component\Grid\GridComponent\getRowsSorting
getRowsSorting()
Определения
gridcomponent.php:241
Bitrix\Iblock\Component\Grid\GridComponent\$pagination
PageNavigation $pagination
Определения
gridcomponent.php:29
Bitrix\Iblock\Component\Grid\GridComponent\processActionsGrid
processActionsGrid()
Определения
gridcomponent.php:303
Bitrix\Iblock\Component\Grid\GridComponent\initRows
initRows()
Определения
gridcomponent.php:89
Bitrix\Iblock\Component\Grid\GridComponent\processActionGrid
processActionGrid(string $actionName, HttpRequest $request)
Определения
gridcomponent.php:388
Bitrix\Iblock\Component\Grid\GridComponent\getRowsFilter
getRowsFilter()
Определения
gridcomponent.php:193
Bitrix\Iblock\Component\Grid\GridComponent\executeComponent
executeComponent()
Определения
gridcomponent.php:152
Bitrix\Iblock\Component\Grid\GridComponent\checkReadPermissions
checkReadPermissions()
Определения
gridcomponent.php:183
Bitrix\Iblock\Component\Grid\GridComponent\getRawRows
getRawRows(array $params)
Bitrix\Iblock\Component\Grid\GridComponent\initResult
initResult()
Определения
gridcomponent.php:135
Bitrix\Iblock\Integration\UI\Grid\General\BaseProvider
Определения
BaseProvider.php:15
Bitrix\Main\AccessDeniedException
Определения
AccessDeniedException.php:9
Bitrix\Main\Grid\MessageType
Определения
messagetype.php:11
Bitrix\Main\Grid\MessageType\ERROR
const ERROR
Определения
messagetype.php:13
Bitrix\Main\Grid\Options
Определения
options.php:13
Bitrix\Main\HttpRequest
Определения
httprequest.php:20
Bitrix\Main\Localization\Loc
Определения
loc.php:12
Bitrix\Main\ORM\Data\Result
Определения
result.php:16
Bitrix\Main\Type\Collection\normalizeArrayValuesByInt
static normalizeArrayValuesByInt(&$map, $sorted=true)
Определения
collection.php:150
Bitrix\Main\UI\PageNavigation
Определения
pagenavigation.php:27
Bitrix\Main\UI\PageNavigation\setPageSize
setPageSize($n)
Определения
pagenavigation.php:139
Bitrix\Main\Web\Json
Определения
json.php:9
CBitrixComponent\includeComponentTemplate
includeComponentTemplate($templatePage="", $customTemplatePath="")
Определения
component.php:724
CBitrixComponent\$request
$request
Определения
component.php:65
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
Bitrix\Iblock\Component\Grid
Определения
gridcomponent.php:3
Bitrix\Main\Context
Определения
culture.php:9
Bitrix\Main\Filter
$message
$message
Определения
payment.php:8
$messages
$messages
Определения
template.php:8
$params
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения
template.php:799
$rows
$rows
Определения
options.php:264
$action
$action
Определения
file_dialog.php:21
bitrix
modules
iblock
lib
component
grid
gridcomponent.php
Создано системой
1.14.0