1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
elementpropertyprovider.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Iblock\Grid\Column;
4
5
use Bitrix\Main\Grid;
6
use Bitrix\Iblock;
7
use Bitrix\Iblock\PropertyEnumerationTable;
8
use Bitrix\Iblock\PropertyTable;
9
10
//use CIBlockPropertyEnum;
11
12
class
ElementPropertyProvider
extends
BaseElementProvider
13
{
14
protected
const
COLUMN_ID_MORE_PHOTO
=
'MORE_PHOTO'
;
15
16
protected
const
PREFIX_ID
=
'PROPERTY_'
;
17
18
protected
array
$properties
;
19
20
public
function
prepareColumns
():
array
21
{
22
$iblockId
= $this->
getIblockId
();
23
if
(
$iblockId
===
null
)
24
{
25
return
[];
26
}
27
28
$isNewCardEnabled = $this->
isNewCardEnabled
();
29
30
$morePhotoId = $this->
getPropertyMorePhotoId
();
31
32
$result
= [];
33
foreach
($this->
getProperties
() as $row)
34
{
35
$columnId =
self::getColumnIdByPropertyId
($row[
'ID'
]);
36
$columnType =
Grid\Column\Type::TEXT
;
37
$multiple = $row[
'MULTIPLE'
] ===
'Y'
;
38
$preventDefault =
true
;
// TODO: what is this
39
40
$description
= [
41
'type'
=> $columnType,
42
'name'
=> $row[
'NAME'
],
43
'necessary'
=>
false
,
44
'editable'
=> $multiple ?
false
:
true
,
45
'multiple'
=> $multiple,
46
'select'
=> [
47
// EMPTY! Properties must be loaded separately due to multiple values.
48
]
49
];
50
51
$extendedMorePhoto = $isNewCardEnabled && $row[
'ID'
] === $morePhotoId;
52
if
($extendedMorePhoto)
53
{
54
$columnId = self::COLUMN_ID_MORE_PHOTO;
55
$columnType =
Grid\Column\Type::CUSTOM
;
56
57
$description
[
'editable'
] =
new
Grid\Column\Editable\CustomConfig
($columnId);
58
}
59
elseif
(
60
$row[
'PROPERTY_TYPE'
] ===
PropertyTable::TYPE_FILE
61
&& $multiple
62
&& !$extendedMorePhoto
63
)
64
{
65
$description
[
'editable'
] =
false
;
66
$preventDefault =
false
;
67
}
68
69
if
(!$multiple)
70
{
71
$description
[
'sort'
] = $columnId;
72
}
73
74
if
(isset($row[
'USER_TYPE'
]))
75
{
76
$description
[
'type'
] =
Grid\Column\Type::CUSTOM
;
77
$description
[
'editable'
] =
new
Grid\Column\Editable\CustomConfig
($columnId);
78
}
79
elseif
($row[
'PROPERTY_TYPE'
] ===
PropertyTable::TYPE_NUMBER
)
80
{
81
$description
[
'type'
] =
Grid\Column\Type::NUMBER
;
82
$description
[
'align'
] =
'right'
;
83
}
84
elseif
($row[
'PROPERTY_TYPE'
] ===
PropertyTable::TYPE_LIST
)
85
{
86
$listItems = $this->getPropertyEnumValues($row[
'ID'
]);
87
if
(!empty($listItems))
88
{
89
$description
[
'type'
] =
90
$multiple
91
?
Grid\Column\Type::MULTISELECT
92
:
Grid\Column\Type::DROPDOWN
93
;
94
$description
[
'editable'
] =
new
Iblock\Grid\Column\Editable\PropertyEnumerationConfig
(
95
$columnId,
96
$row,
97
$listItems,
98
);
99
}
100
else
101
{
102
$description
[
'editable'
] =
false
;
103
}
104
unset($listItems);
105
}
106
elseif
($row[
'PROPERTY_TYPE'
] ===
PropertyTable::TYPE_ELEMENT
)
107
{
108
$description
[
'type'
] =
Grid\Column\Type::CUSTOM
;
109
$description
[
'editable'
] =
new
Grid\Column\Editable\CustomConfig
($columnId);
110
}
111
elseif
($row[
'PROPERTY_TYPE'
] ===
PropertyTable::TYPE_SECTION
)
112
{
113
$description
[
'type'
] =
Grid\Column\Type::CUSTOM
;
114
$description
[
'editable'
] =
new
Grid\Column\Editable\CustomConfig
($columnId);
115
}
116
elseif
($row[
'PROPERTY_TYPE'
] ===
PropertyTable::TYPE_FILE
)
117
{
118
$description
[
'type'
] =
Grid\Column\Type::FILE
;
119
}
120
121
$description
[
'prevent_default'
] = $preventDefault;
// TODO: what is this
122
123
$result
[$columnId] =
$description
;
124
}
125
126
return
$this->createColumns(
$result
);
127
}
128
129
protected
function
getProperties
():
array
130
{
131
if
(!isset($this->properties))
132
{
133
$this->
loadProperties
();
134
}
135
136
return
$this->properties
;
137
}
138
139
protected
function
loadProperties
(): void
140
{
141
$this->properties = [];
142
$iblockId
= $this->
getIblockId
();
143
if
(
$iblockId
===
null
)
144
{
145
return
;
146
}
147
148
$iterator
=
PropertyTable::getList
([
149
'select'
=> [
150
'*'
,
151
],
152
'filter'
=> [
153
'=IBLOCK_ID'
=>
$iblockId
,
154
'=ACTIVE'
=>
'Y'
,
155
],
156
'order'
=> [
157
'SORT'
=>
'ASC'
,
158
'NAME'
=>
'ASC'
,
159
'ID'
=>
'ASC'
,
160
],
161
'cache'
=> [
162
'ttl'
=> 86400,
163
],
164
]);
165
while
($row =
$iterator
->fetch())
166
{
167
$row[
'ID'
] = (int)$row[
'ID'
];
168
$row[
'SORT'
] = (int)$row[
'SORT'
];
169
$row[
'IBLOCK_ID'
] = (int)$row[
'IBLOCK_ID'
];
170
if
($row[
'USER_TYPE'
] !==
null
)
171
{
172
$row[
'USER_TYPE'
] = trim($row[
'USER_TYPE'
]);
173
if
($row[
'USER_TYPE'
] ===
''
)
174
{
175
$row[
'USER_TYPE'
] =
null
;
176
}
177
}
178
$row[
'USER_TYPE_DESCRIPTION'
] = ($row[
'USER_TYPE'
] ? \CIBlockProperty::GetUserType($row[
'USER_TYPE'
]) : []);
179
if
(!is_array($row[
'USER_TYPE_SETTINGS_LIST'
]))
180
{
181
$row[
'USER_TYPE_SETTINGS_LIST'
] = [];
182
}
183
$row[
'USER_TYPE_SETTINGS'
] = $row[
'USER_TYPE_SETTINGS_LIST'
];
184
unset($row[
'USER_TYPE_SETTINGS_LIST'
]);
185
186
$this->properties[$row[
'ID'
]] = $row;
187
}
188
unset($row,
$iterator
);
189
}
190
191
protected
function
getPropertyMorePhotoId
(): ?int
192
{
193
$result
=
null
;
194
foreach
($this->
getProperties
() as $row)
195
{
196
if
(
197
$row[
'PROPERTY_TYPE'
] ===
PropertyTable::TYPE_FILE
198
&& $row[
'CODE'
] === \
CIBlockPropertyTools::CODE_MORE_PHOTO
199
)
200
{
201
$result
= $row[
'ID'
];
202
break
;
203
}
204
}
205
206
return
$result
;
207
}
208
209
private
function
getPropertyEnumValues(
int
$propertyId):
array
210
{
211
$result
= [];
212
213
$iterator
= PropertyEnumerationTable::getList([
214
'select'
=> [
215
'ID'
,
216
'VALUE'
,
217
'DEF'
,
218
'SORT'
,
219
],
220
'filter'
=> [
221
'=PROPERTY_ID'
=> $propertyId
222
],
223
'order'
=> [
224
'SORT'
=>
'ASC'
,
225
'VALUE'
=>
'ASC'
,
226
'ID'
=>
'ASC'
,
227
],
228
'cache'
=> [
229
'ttl'
=> 86400,
230
],
231
]);
232
while
($row =
$iterator
->fetch())
233
{
234
$id = (int)$row[
'ID'
];
235
$result
[$id] = [
236
'ID'
=> $id,
237
'VALUE'
=> $row[
'VALUE'
],
238
'DEF'
=> $row[
'DEF'
],
239
];
240
}
241
unset($row,
$iterator
);
242
243
return
$result
;
244
}
245
246
#region static
247
255
public
static
function
getPropertyIdsFromColumnsIds
(
array
$columnIds):
array
256
{
257
$result
= [];
258
259
$propertyPrefixRe =
'/^'
. preg_quote(self::PREFIX_ID) .
'(\d+)$/'
;
260
261
foreach
($columnIds as $columnId)
262
{
263
if
(preg_match($propertyPrefixRe, $columnId, $m))
264
{
265
$result
[$columnId] = (int)$m[1];
266
}
267
}
268
269
return
$result
;
270
}
271
277
public
static
function
getColumnIdByPropertyId
(
int
$id): string
278
{
279
return
self::PREFIX_ID . $id;
280
}
281
282
#endregion static
283
}
Bitrix\Iblock\Grid\Column\BaseElementProvider
Определения
baseelementprovider.php:12
Bitrix\Iblock\Grid\Column\BaseElementProvider\isNewCardEnabled
isNewCardEnabled()
Определения
baseelementprovider.php:28
Bitrix\Iblock\Grid\Column\BaseElementProvider\getIblockId
getIblockId()
Определения
baseelementprovider.php:18
Bitrix\Iblock\Grid\Column\Editable\PropertyEnumerationConfig
Определения
propertyenumerationconfig.php:10
Bitrix\Iblock\Grid\Column\ElementPropertyProvider
Определения
elementpropertyprovider.php:13
Bitrix\Iblock\Grid\Column\ElementPropertyProvider\getColumnIdByPropertyId
static getColumnIdByPropertyId(int $id)
Определения
elementpropertyprovider.php:277
Bitrix\Iblock\Grid\Column\ElementPropertyProvider\getPropertyIdsFromColumnsIds
static getPropertyIdsFromColumnsIds(array $columnIds)
Определения
elementpropertyprovider.php:255
Bitrix\Iblock\Grid\Column\ElementPropertyProvider\PREFIX_ID
const PREFIX_ID
Определения
elementpropertyprovider.php:16
Bitrix\Iblock\Grid\Column\ElementPropertyProvider\COLUMN_ID_MORE_PHOTO
const COLUMN_ID_MORE_PHOTO
Определения
elementpropertyprovider.php:14
Bitrix\Iblock\Grid\Column\ElementPropertyProvider\prepareColumns
prepareColumns()
Определения
elementpropertyprovider.php:20
Bitrix\Iblock\Grid\Column\ElementPropertyProvider\loadProperties
loadProperties()
Определения
elementpropertyprovider.php:139
Bitrix\Iblock\Grid\Column\ElementPropertyProvider\getProperties
getProperties()
Определения
elementpropertyprovider.php:129
Bitrix\Iblock\Grid\Column\ElementPropertyProvider\getPropertyMorePhotoId
getPropertyMorePhotoId()
Определения
elementpropertyprovider.php:191
Bitrix\Iblock\Grid\Column\ElementPropertyProvider\$properties
array $properties
Определения
elementpropertyprovider.php:18
Bitrix\Iblock\PropertyTable\TYPE_ELEMENT
const TYPE_ELEMENT
Определения
propertytable.php:68
Bitrix\Iblock\PropertyTable\TYPE_FILE
const TYPE_FILE
Определения
propertytable.php:67
Bitrix\Iblock\PropertyTable\TYPE_LIST
const TYPE_LIST
Определения
propertytable.php:70
Bitrix\Iblock\PropertyTable\TYPE_SECTION
const TYPE_SECTION
Определения
propertytable.php:69
Bitrix\Iblock\PropertyTable\TYPE_NUMBER
const TYPE_NUMBER
Определения
propertytable.php:66
Bitrix\Main\Grid\Column\Editable\CustomConfig
Определения
customconfig.php:11
Bitrix\Main\Grid\Column\Type\FILE
const FILE
Определения
type.php:27
Bitrix\Main\Grid\Column\Type\CUSTOM
const CUSTOM
Определения
type.php:21
Bitrix\Main\Grid\Column\Type\TEXT
const TEXT
Определения
type.php:10
Bitrix\Main\Grid\Column\Type\DROPDOWN
const DROPDOWN
Определения
type.php:18
Bitrix\Main\Grid\Column\Type\MULTISELECT
const MULTISELECT
Определения
type.php:19
Bitrix\Main\Grid\Column\Type\NUMBER
const NUMBER
Определения
type.php:16
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Определения
datamanager.php:431
CIBlockPropertyTools\CODE_MORE_PHOTO
const CODE_MORE_PHOTO
Определения
iblockproptools.php:11
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
$description
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения
.description.php:24
$iblockId
$iblockId
Определения
iblock_catalog_edit.php:30
false
return false
Определения
prolog_main_admin.php:185
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$iterator
$iterator
Определения
yandex_run.php:610
bitrix
modules
iblock
lib
grid
column
elementpropertyprovider.php
Создано системой
1.14.0