Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
basefieldassembler.php
1
<?php
2
3
namespace
Bitrix\Iblock\Grid\Row\Assembler\Property
;
4
5
6
use
Bitrix\Main
;
7
use
Bitrix\Main\Grid\Row\FieldAssembler
;
8
use
Bitrix\Iblock\Grid\Column\ElementPropertyProvider
;
9
use
Bitrix\Iblock\Grid\RowType
;
10
use
Bitrix\Iblock\PropertyTable
;
11
12
abstract
class
BaseFieldAssembler
extends
FieldAssembler
13
{
14
protected
const
NORMALIZE_EMPTY
= 0;
15
protected
const
NORMALIZE_BY_INT
= 1;
16
17
protected
int
$iblockId
;
18
19
protected
array
$customEditableColumnIds
;
20
21
protected
array
$properties
;
22
23
public
function
__construct
(
int
$iblockId
, array
$customEditableColumnIds
)
24
{
25
$this->iblockId =
$iblockId
;
26
27
$this->customEditableColumnIds =
$customEditableColumnIds
;
28
29
parent::__construct(
30
$this->
getPropertyColumnsIds
()
31
);
32
}
33
34
protected
function
getIblockId
(): int
35
{
36
return
$this->iblockId
;
37
}
38
39
abstract
protected
function
getPropertyFilter
(): array;
40
41
abstract
protected
function
validateProperty
(array $property): ?array;
42
43
protected
function
loadProperties
(): void
44
{
45
if
(isset($this->properties))
46
{
47
return
;
48
}
49
50
$this->properties = [];
51
$iterator =
PropertyTable::getList
([
52
'select'
=> [
53
'ID'
,
54
'IBLOCK_ID'
,
55
'NAME'
,
56
'SORT'
,
57
'DEFAULT_VALUE'
,
58
'PROPERTY_TYPE'
,
59
'ROW_COUNT'
,
60
'COL_COUNT'
,
61
'LIST_TYPE'
,
62
'MULTIPLE'
,
63
'FILE_TYPE'
,
64
'MULTIPLE_CNT'
,
65
'LINK_IBLOCK_ID'
,
66
'WITH_DESCRIPTION'
,
67
'IS_REQUIRED'
,
68
'USER_TYPE'
,
69
'USER_TYPE_SETTINGS_LIST'
,
70
'HINT'
,
71
],
72
'filter'
=> array_merge(
73
[
74
'=IBLOCK_ID'
=> $this->
getIblockId
(),
75
'=ACTIVE'
=>
'Y'
,
76
],
77
$this->
getPropertyFilter
()
78
),
79
'order'
=> [
80
'SORT'
=>
'ASC'
,
81
'NAME'
=>
'ASC'
,
82
'ID'
=>
'ASC'
,
83
],
84
'cache'
=> [
85
'ttl'
=> 86400,
86
],
87
]);
88
89
while
($row = $iterator->fetch())
90
{
91
$row[
'ID'
] = (int)$row[
'ID'
];
92
$row[
'IBLOCK_ID'
] = (int)$row[
'IBLOCK_ID'
];
93
94
$row[
'USER_TYPE'
] = trim((
string
)$row[
'USER_TYPE'
]);
95
if
($row[
'USER_TYPE'
] ===
''
)
96
{
97
$row[
'USER_TYPE'
] =
null
;
98
}
99
100
$row[
'HINT'
] = trim((
string
)$row[
'HINT'
]);
101
if
($row[
'HINT'
] ===
''
)
102
{
103
$row[
'HINT'
] =
null
;
104
}
105
106
$row = $this->
validateProperty
($row);
107
108
if
($row)
109
{
110
$this->properties[ElementPropertyProvider::getColumnIdByPropertyId($row[
'ID'
])] = $row;
111
}
112
}
113
unset($row, $iterator);
114
}
115
116
protected
function
isMultipleColumn
(
string
$columnId): bool
117
{
118
return
($this->properties[$columnId][
'MULTIPLE'
] ??
'N'
) ===
'Y'
;
119
}
120
121
protected
function
getPropertyColumnsIds
(): array
122
{
123
$this->
loadProperties
();
124
125
return
array_keys($this->properties);
126
}
127
128
protected
function
getColumnValues
(mixed $rawValues,
string
$fieldName =
'VALUE'
): array
129
{
130
if
(!is_array($rawValues))
131
{
132
return
[];
133
}
134
if
(array_key_exists($fieldName, $rawValues))
135
{
136
return
[$rawValues[$fieldName]];
137
}
138
else
139
{
140
$result = [];
141
foreach
($rawValues as $row)
142
{
143
if
(is_array($row)&& array_key_exists($fieldName, $row))
144
{
145
$result[] = $row[$fieldName];
146
}
147
}
148
149
return
$result;
150
}
151
}
152
153
protected
function
compileColumnValues
(array $rowList,
int
$normalizationMode = self::NORMALIZE_EMPTY): array
154
{
155
$result = [];
156
foreach
($rowList as $row)
157
{
158
foreach
($this->
getColumnIds
() as $columnId)
159
{
160
$columnValues = $this->
getColumnValues
($row[
'data'
][$columnId] ??
null
);
161
if
(!empty($columnValues))
162
{
163
$result = array_merge($result, $columnValues);
164
}
165
unset($columnValues);
166
}
167
}
168
169
if
(empty($result))
170
{
171
return
$result;
172
}
173
174
if
($normalizationMode === self::NORMALIZE_BY_INT)
175
{
176
Main\Type\Collection::normalizeArrayValuesByInt($result,
false
);
177
}
178
179
return
$result;
180
}
181
182
protected
static
function
getRowType
(array $row): ?string
183
{
184
$rowType = (string)($row[
'data'
][
'ROW_TYPE'
] ??
''
);
185
if
($rowType ===
RowType::ELEMENT
|| $rowType ===
RowType::SECTION
)
186
{
187
return
$rowType;
188
}
189
190
return
null
;
191
}
192
193
protected
static
function
isElementRow
(array $row): bool
194
{
195
return
static::getRowType($row) ===
RowType::ELEMENT
;
196
}
197
198
protected
static
function
getFlatColumnValues
(mixed $rawValues, $fieldName =
'VALUE'
)
199
{
200
if
(!is_array($rawValues))
201
{
202
return
null
;
203
}
204
if
(array_key_exists($fieldName, $rawValues))
205
{
206
return
$rawValues[$fieldName];
207
}
208
else
209
{
210
$result = [];
211
foreach
($rawValues as $row)
212
{
213
if
(is_array($row) && array_key_exists($fieldName, $row))
214
{
215
$result[] = $row[$fieldName];
216
}
217
}
218
219
return
$result;
220
}
221
}
222
}
Bitrix\Iblock\Grid\Column\ElementPropertyProvider
Definition
elementpropertyprovider.php:13
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler
Definition
basefieldassembler.php:13
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\$customEditableColumnIds
array $customEditableColumnIds
Definition
basefieldassembler.php:19
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\getIblockId
getIblockId()
Definition
basefieldassembler.php:34
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\getPropertyFilter
getPropertyFilter()
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\NORMALIZE_BY_INT
const NORMALIZE_BY_INT
Definition
basefieldassembler.php:15
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\isElementRow
static isElementRow(array $row)
Definition
basefieldassembler.php:193
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\getPropertyColumnsIds
getPropertyColumnsIds()
Definition
basefieldassembler.php:121
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\isMultipleColumn
isMultipleColumn(string $columnId)
Definition
basefieldassembler.php:116
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\validateProperty
validateProperty(array $property)
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\__construct
__construct(int $iblockId, array $customEditableColumnIds)
Definition
basefieldassembler.php:23
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\getRowType
static getRowType(array $row)
Definition
basefieldassembler.php:182
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\$iblockId
int $iblockId
Definition
basefieldassembler.php:17
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\loadProperties
loadProperties()
Definition
basefieldassembler.php:43
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\getColumnValues
getColumnValues(mixed $rawValues, string $fieldName='VALUE')
Definition
basefieldassembler.php:128
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\getFlatColumnValues
static getFlatColumnValues(mixed $rawValues, $fieldName='VALUE')
Definition
basefieldassembler.php:198
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\$properties
array $properties
Definition
basefieldassembler.php:21
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\compileColumnValues
compileColumnValues(array $rowList, int $normalizationMode=self::NORMALIZE_EMPTY)
Definition
basefieldassembler.php:153
Bitrix\Iblock\Grid\Row\Assembler\Property\BaseFieldAssembler\NORMALIZE_EMPTY
const NORMALIZE_EMPTY
Definition
basefieldassembler.php:14
Bitrix\Iblock\Grid\RowType
Definition
rowtype.php:8
Bitrix\Iblock\Grid\RowType\ELEMENT
const ELEMENT
Definition
rowtype.php:9
Bitrix\Iblock\Grid\RowType\SECTION
const SECTION
Definition
rowtype.php:10
Bitrix\Iblock\PropertyTable
Definition
propertytable.php:60
Bitrix\Main\Grid\Row\FieldAssembler
Definition
fieldassembler.php:22
Bitrix\Main\Grid\Row\FieldAssembler\getColumnIds
getColumnIds()
Definition
fieldassembler.php:44
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Iblock\Grid\Row\Assembler\Property
Definition
basefieldassembler.php:3
Bitrix\Main
modules
iblock
lib
grid
row
assembler
property
basefieldassembler.php
Создано системой
1.10.0