Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
sectiontype.php
1
<?php
2
3
namespace
Bitrix\Iblock\UserField\Types
;
4
5
use
Bitrix\Main\Loader
;
6
use
Bitrix\Main\Localization\Loc
;
7
use
Bitrix\Main\Type
;
8
use
Bitrix\Iblock
;
9
use CDBResult;
10
use CUserTypeManager;
11
use CIBlockSectionEnum;
12
17
class
SectionType
extends
ElementType
18
{
19
public
const
20
USER_TYPE_ID
=
'iblock_section'
,
21
RENDER_COMPONENT
=
'bitrix:iblock.field.section'
;
22
26
public
static
function
getDescription
(): array
27
{
28
return
[
29
'DESCRIPTION'
=>
Loc::getMessage
(
'USER_TYPE_IBSEC_DESCRIPTION'
),
30
'BASE_TYPE'
=> CUserTypeManager::BASE_TYPE_INT,
31
];
32
}
33
38
public
static
function
onSearchIndex
(array $userField): string
39
{
40
$res =
''
;
41
if
(!isset($userField[
'VALUE'
]))
42
{
43
return
$res;
44
}
45
46
if
(is_array($userField[
'VALUE'
]))
47
{
48
$val = $userField[
'VALUE'
];
49
}
50
else
51
{
52
$val = [$userField[
'VALUE'
]];
53
}
54
55
Type\Collection::normalizeArrayValuesByInt($val);
56
57
if
(!empty($val) && Loader::includeModule(
'iblock'
))
58
{
59
$iterator = Iblock\SectionTable::getList([
60
'select'
=> [
61
'NAME'
,
62
'LEFT_MARGIN'
,
63
],
64
'filter'
=> [
65
'@ID'
=> $val,
66
],
67
'order'
=> [
68
'LEFT_MARGIN'
=>
'ASC'
,
69
],
70
]);
71
while
($row = $iterator->fetch())
72
{
73
$res .= $row[
'NAME'
] .
"\r\n"
;
74
}
75
unset($row, $iterator);
76
}
77
unset($val);
78
79
return
$res;
80
}
81
86
public
static
function
getList
(array $userField)
87
{
88
if
(self::$iblockIncluded ===
null
)
89
{
90
self::$iblockIncluded = Loader::includeModule(
'iblock'
);
91
}
92
93
$section =
false
;
94
95
if
(self::$iblockIncluded && (
int
)$userField[
'SETTINGS'
][
'IBLOCK_ID'
])
96
{
97
$section = CIBlockSectionEnum::getTreeList(
98
(
int
)$userField[
'SETTINGS'
][
'IBLOCK_ID'
],
99
$userField[
'SETTINGS'
][
'ACTIVE_FILTER'
]
100
);
101
}
102
return
$section;
103
}
104
110
public
static
function
getEnumList
(array &$userField, array $additionalParameters = []): void
111
{
112
if
(self::$iblockIncluded ===
null
)
113
{
114
self::$iblockIncluded = Loader::includeModule(
'iblock'
);
115
}
116
117
if
(!self::$iblockIncluded)
118
{
119
return
;
120
}
121
122
$userField[
'SETTINGS'
][
'IBLOCK_ID'
] ??= 0;
123
$userField[
'SETTINGS'
][
'SHOW_NO_VALUE'
] ??=
'Y'
;
124
$userField[
'SETTINGS'
][
'DISPLAY'
] ??=
''
;
125
$userField[
'SETTINGS'
][
'ACTIVE_FILTER'
] ??=
'N'
;
126
127
$result = [];
128
$showNoValue = (
129
$userField[
'MANDATORY'
] !==
'Y'
130
|| $userField[
'SETTINGS'
][
'SHOW_NO_VALUE'
] !==
'N'
131
|| (
132
isset($additionalParameters[
'SHOW_NO_VALUE'
])
133
&& $additionalParameters[
'SHOW_NO_VALUE'
] === true
134
)
135
);
136
137
if
(
138
$showNoValue
139
&& (
140
$userField[
'SETTINGS'
][
'DISPLAY'
] !== self::DISPLAY_CHECKBOX
141
|| $userField[
'MULTIPLE'
] !==
'Y'
142
)
143
)
144
{
145
$result = [
146
null
=> static::getEmptyCaption($userField)
147
];
148
}
149
150
$sectionEnumList = CIBlockSectionEnum::getTreeList(
151
(
int
)$userField[
'SETTINGS'
][
'IBLOCK_ID'
],
152
$userField[
'SETTINGS'
][
'ACTIVE_FILTER'
]
153
);
154
155
if
(!is_object($sectionEnumList))
156
{
157
return
;
158
}
159
160
while
($section = $sectionEnumList->Fetch())
161
{
162
$result[$section[
'ID'
]] = $section[
'NAME'
];
163
}
164
165
$userField[
'USER_TYPE'
][
'FIELDS'
] = $result;
166
}
167
173
public
static
function
getGroupActionData
(array $userField, ?array $additionalParameters): array
174
{
175
$result = [];
176
$enum = call_user_func([$userField[
'USER_TYPE'
][
'CLASS_NAME'
],
'getlist'
], $userField);
177
if
(!$enum)
178
{
179
return
$result;
180
}
181
182
while
($item = $enum->GetNext())
183
{
184
$result[] = [
'NAME'
=> $item[
'VALUE'
],
'VALUE'
=> $item[
'ID'
]];
185
}
186
187
return
$result;
188
}
189
195
public
static
function
getDefaultValue
(array $userField, array $additionalParameters = [])
196
{
197
$value = ($userField[
'SETTINGS'
][
'DEFAULT_VALUE'
] ??
''
);
198
199
return
($userField[
'MULTIPLE'
] ===
'Y'
? [$value] : $value);
200
}
201
}
Bitrix\Iblock\UserField\Types\ElementType
Definition
elementtype.php:20
Bitrix\Iblock\UserField\Types\SectionType
Definition
sectiontype.php:18
Bitrix\Iblock\UserField\Types\SectionType\getDefaultValue
static getDefaultValue(array $userField, array $additionalParameters=[])
Definition
sectiontype.php:195
Bitrix\Iblock\UserField\Types\SectionType\USER_TYPE_ID
const USER_TYPE_ID
Definition
sectiontype.php:20
Bitrix\Iblock\UserField\Types\SectionType\getEnumList
static getEnumList(array &$userField, array $additionalParameters=[])
Definition
sectiontype.php:110
Bitrix\Iblock\UserField\Types\SectionType\getList
static getList(array $userField)
Definition
sectiontype.php:86
Bitrix\Iblock\UserField\Types\SectionType\getDescription
static getDescription()
Definition
sectiontype.php:26
Bitrix\Iblock\UserField\Types\SectionType\onSearchIndex
static onSearchIndex(array $userField)
Definition
sectiontype.php:38
Bitrix\Iblock\UserField\Types\SectionType\RENDER_COMPONENT
const RENDER_COMPONENT
Definition
sectiontype.php:21
Bitrix\Iblock\UserField\Types\SectionType\getGroupActionData
static getGroupActionData(array $userField, ?array $additionalParameters)
Definition
sectiontype.php:173
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Iblock\UserField\Types
Definition
elementtype.php:3
Bitrix\Iblock
Bitrix\Main\Type
Definition
collection.php:2
modules
iblock
lib
userfield
types
sectiontype.php
Создано системой
1.10.0