Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
elementcountfieldassembler.php
1<?php
2
4
7use CIBlockSection;
8
10{
11 public function __construct()
12 {
13 parent::__construct([
14 'ELEMENT_CNT',
15 ]);
16 }
17
18 protected function prepareRow(array $row): array
19 {
20 $value = '';
21
22 $id = (int)($row['data']['ID'] ?? 0);
23 $rowType = $row['data']['ROW_TYPE'] ?? null;
24 if ($id > 0 && $rowType === RowType::SECTION)
25 {
26 $count = (int)($row['data']['ELEMENT_CNT'] ?? 0);
27 $allCount = CIBlockSection::GetSectionElementsCount($id, ['CNT_ALL' => 'Y']);
28
29 $value = "{$count} ({$allCount})";
30 }
31
32 $row['columns'] ??= [];
33 $row['columns']['ELEMENT_CNT'] = $value;
34
35 return $row;
36 }
37}