Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sectiontype.php
1<?php
2
4
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
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}
static getDefaultValue(array $userField, array $additionalParameters=[])
static getEnumList(array &$userField, array $additionalParameters=[])
static onSearchIndex(array $userField)
static getGroupActionData(array $userField, ?array $additionalParameters)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29