1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sectiontype.php
См. документацию.
1<?php
2
3namespace Bitrix\Iblock\UserField\Types;
4
5use Bitrix\Main\Loader;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Type;
8use Bitrix\Iblock;
9use CDBResult;
10use CUserTypeManager;
11use CIBlockSectionEnum;
12
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
56
57 if (!empty($val) && Loader::includeModule('iblock'))
58 {
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['MANDATORY'] ??= 'N';
123 $userField['SETTINGS']['IBLOCK_ID'] ??= 0;
124 $userField['SETTINGS']['SHOW_NO_VALUE'] ??= 'Y';
125 $userField['SETTINGS']['DISPLAY'] ??= '';
126 $userField['SETTINGS']['ACTIVE_FILTER'] ??= 'N';
127
128 $result = [];
129 $showNoValue = (
130 $userField['MANDATORY'] !== 'Y'
131 || $userField['SETTINGS']['SHOW_NO_VALUE'] !== 'N'
132 || (
133 isset($additionalParameters['SHOW_NO_VALUE'])
134 && $additionalParameters['SHOW_NO_VALUE'] === true
135 )
136 );
137
138 if(
139 $showNoValue
140 && (
141 $userField['SETTINGS']['DISPLAY'] !== self::DISPLAY_CHECKBOX
142 || $userField['MULTIPLE'] !== 'Y'
143 )
144 )
145 {
146 $result = [
147 null => static::getEmptyCaption($userField)
148 ];
149 }
150
151 $filter = [];
152
153 $checkValue = ($additionalParameters['mode'] ?? '') === self::MODE_VIEW;
154 if ($checkValue)
155 {
156 $currentValues = static::getFieldValue($userField, $additionalParameters);
157 if (!empty($currentValues))
158 {
159 if (is_array($currentValues))
160 {
162 }
163 else
164 {
166 if ($currentValues <= 0)
167 {
168 $currentValues = null;
169 }
170 }
171 }
172 if (!empty($currentValues))
173 {
174 $filter['ID'] = $currentValues;
175 }
176 else
177 {
178 $userField['USER_TYPE']['FIELDS'] = $result;
179
180 return;
181 }
182 }
183 $filter['ACTIVE'] = $userField['SETTINGS']['ACTIVE_FILTER'] === 'Y';
184
185 if (isset($additionalParameters['SKIP_CHECK_PERMISSIONS']) && $additionalParameters['SKIP_CHECK_PERMISSIONS'])
186 {
187 $filter['CHECK_PERMISSIONS'] = 'N';
188 }
189
190 $sections = self::getElements(
191 (int)$userField['SETTINGS']['IBLOCK_ID'],
192 $filter
193 );
194
195 if (!is_array($sections))
196 {
197 return;
198 }
199
200 if (!empty($currentValues))
201 {
202 $result = $sections;
203 }
204 else
205 {
206 $result = array_replace($result, $sections);
207 }
208
209 $userField['USER_TYPE']['FIELDS'] = $result;
210 }
211
212 protected static function getElements(int $iblockId, array $additionalFilter = [])
213 {
214 if (self::$iblockIncluded === null)
215 {
216 self::$iblockIncluded = Loader::includeModule('iblock');
217 }
218 if ($iblockId <= 0 || !self::$iblockIncluded)
219 {
220 return null;
221 }
222
223 $additionalFilter['ACTIVE'] ??= false;
224
225 $filter = [
226 'IBLOCK_ID' => $iblockId,
227 'CHECK_PERMISSIONS' => $additionalFilter['CHECK_PERMISSIONS'] ?? 'Y',
228 'MIN_PERMISSION' => \CIBlockRights::PUBLIC_READ,
229 ];
230 if ($additionalFilter['ACTIVE'])
231 {
232 $filter['ACTIVE'] = 'Y';
233 }
234 if (isset($additionalFilter['ID']))
235 {
236 $filter['ID'] = $additionalFilter['ID'];
237 }
238
239 $result = [];
240 $iterator = \CIBlockSection::GetList(
241 [
242 'LEFT_MARGIN' => 'ASC',
243 ],
244 $filter,
245 false,
246 [
247 'ID',
248 'NAME',
249 ]
250 );
251
252 while ($element = $iterator->Fetch())
253 {
254 $result[$element['ID']] = $element['NAME'];
255 }
256 unset($element, $iterator);
257
258 return $result;
259 }
260
268 public static function getGroupActionData(array $userField, ?array $additionalParameters): array
269 {
270 $result = [];
271 $enum = call_user_func([$userField['USER_TYPE']['CLASS_NAME'], 'getlist'], $userField);
272 if(!$enum)
273 {
274 return $result;
275 }
276
277 while ($item = $enum->GetNext())
278 {
279 $result[] = ['NAME' => $item['VALUE'], 'VALUE' => $item['ID']];
280 }
281 unset(
282 $item,
283 $enum,
284 );
285
286 return $result;
287 }
288
296 public static function getDefaultValue(array $userField, array $additionalParameters = [])
297 {
298 $value = ($userField['SETTINGS']['DEFAULT_VALUE'] ?? '');
299
300 return ($userField['MULTIPLE'] === 'Y' ? [$value] : $value);
301 }
302}
static getDefaultValue(array $userField, array $additionalParameters=[])
Определения sectiontype.php:296
static getElements(int $iblockId, array $additionalFilter=[])
Определения sectiontype.php:212
static getEnumList(array &$userField, array $additionalParameters=[])
Определения sectiontype.php:110
static getList(array $userField)
Определения sectiontype.php:86
static onSearchIndex(array $userField)
Определения sectiontype.php:38
static getGroupActionData(array $userField, ?array $additionalParameters)
Определения sectiontype.php:268
static includeModule($moduleName)
Определения loader.php:67
static getList(array $parameters=array())
Определения datamanager.php:431
static normalizeArrayValuesByInt(&$map, $sorted=true)
Определения collection.php:150
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
if($request->isPost() && $currentAction !==null &&check_bitrix_sessid()) $currentValues
Определения options.php:198
$iblockId
Определения iblock_catalog_edit.php:30
$filter
Определения iblock_catalog_list.php:54
$val
Определения options.php:1793
$iterator
Определения yandex_run.php:610