1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
booleantype.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\UserField\Types;
4
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Main\ORM\Fields\BooleanField;
7use CUserTypeManager;
8
9Loc::loadMessages(__FILE__);
10
15class BooleanType extends BaseType
16{
17 public const
18 USER_TYPE_ID = 'boolean',
19 RENDER_COMPONENT = 'bitrix:main.field.boolean';
20
21 public const
22 DISPLAY_DROPDOWN = 'DROPDOWN',
23 DISPLAY_RADIO = 'RADIO',
24 DISPLAY_CHECKBOX = 'CHECKBOX';
25
29 public static function getDescription(): array
30 {
31 return [
32 'DESCRIPTION' => Loc::getMessage('USER_TYPE_BOOL_DESCRIPTION'),
33 'BASE_TYPE' => CUserTypeManager::BASE_TYPE_INT,
34 ];
35 }
36
40 public static function getDbColumnType(): string
41 {
43 $helper = $connection->getSqlHelper();
44 return $helper->getColumnTypeByField(new \Bitrix\Main\ORM\Fields\IntegerField('x'));
45 }
46
51 public static function prepareSettings(array $userField): array
52 {
53 $label = ($userField['SETTINGS']['LABEL'] ?? ['', '']);
54
55 if($label[0] === Loc::getMessage('MAIN_NO'))
56 {
57 $label[0] = '';
58 }
59 if($label[1] === Loc::getMessage('MAIN_YES'))
60 {
61 $label[1] = '';
62 }
63
64 $labelCheckbox = ($userField['SETTINGS']['LABEL_CHECKBOX'] ?? '');
65 if($labelCheckbox === Loc::getMessage('MAIN_YES'))
66 {
67 $labelCheckbox = '';
68 }
69
70 $def = (int)($userField['SETTINGS']['DEFAULT_VALUE'] ?? 0);
71 if($def !== 1)
72 {
73 $def = 0;
74 }
75
76 $disp = ($userField['SETTINGS']['DISPLAY'] ?? '');
77 if($disp !== 'CHECKBOX' && $disp !== 'RADIO' && $disp !== 'DROPDOWN')
78 {
79 $disp = 'CHECKBOX';
80 }
81
82 return [
83 'DEFAULT_VALUE' => $def,
84 'DISPLAY' => $disp,
85 'LABEL' => [
86 $label[0], $label[1]
87 ],
88 'LABEL_CHECKBOX' => $labelCheckbox,
89 ];
90 }
91
96 public static function getLabels(array $userField): array
97 {
98 $label = [Loc::getMessage('MAIN_NO'), GetMessage('MAIN_YES')];
99 if(isset($userField['SETTINGS']['LABEL']) && is_array($userField['SETTINGS']['LABEL']))
100 {
101 foreach($label as $key => $value)
102 {
103 if($userField['SETTINGS']['LABEL'][$key] <> '')
104 {
105 $label[$key] = $userField['SETTINGS']['LABEL'][$key];
106 }
107 }
108 }
109
110 return $label;
111 }
112
118 public static function getFilterData(array $userField, array $additionalParameters): array
119 {
120 return [
121 'id' => $additionalParameters['ID'],
122 'name' => $additionalParameters['NAME'],
123 'type' => 'list',
124 'items' => [
125 'Y' => Loc::getMessage('MAIN_YES'),
126 'N' => Loc::getMessage('MAIN_NO')
127 ],
128 'filterable' => ''
129 ];
130 }
131
137 public static function onBeforeSave($userField, $value): int
138 {
139 $result = 0;
140 if($value)
141 {
142 $result = 1;
143 }
144 return $result;
145 }
146
151 final public static function getAllDisplays(): array
152 {
153 $reflection = new \ReflectionClass(__CLASS__);
154 $constants = $reflection->getConstants();
155 $result = [];
156 foreach($constants as $name => $value)
157 {
158 if(str_starts_with($name, 'DISPLAY_'))
159 {
160 $result[$name] = $value;
161 }
162 }
163 return $result;
164 }
165
166 public static function getAdminListViewHtmlMulty(array $userField, ?array $additionalParameters): string
167 {
168 return parent::renderAdminListView($userField, $additionalParameters);
169 }
170
171 public static function isMandatorySupported(): bool
172 {
173 return false;
174 }
175
176 public static function isMultiplicitySupported(): bool
177 {
178 return false;
179 }
180
181 public static function checkFields(array $userField, $value): array
182 {
183 return [];
184 }
185
186 public static function getEntityField($fieldName, $fieldParameters)
187 {
188 $fieldParameters['values'] = [0, 1];
189
190 $field = (new BooleanField($fieldName, $fieldParameters))
191 ->configureNullable();
192
193 return $field;
194 }
195}
$connection
Определения actionsdefinitions.php:38
static getConnection($name="")
Определения application.php:638
static isMultiplicitySupported()
Определения booleantype.php:176
static getAdminListViewHtmlMulty(array $userField, ?array $additionalParameters)
Определения booleantype.php:166
static getLabels(array $userField)
Определения booleantype.php:96
static getFilterData(array $userField, array $additionalParameters)
Определения booleantype.php:118
static onBeforeSave($userField, $value)
Определения booleantype.php:137
static checkFields(array $userField, $value)
Определения booleantype.php:181
static getEntityField($fieldName, $fieldParameters)
Определения booleantype.php:186
static prepareSettings(array $userField)
Определения booleantype.php:51
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$name
Определения menu_edit.php:35
if(empty($signedUserToken)) $key
Определения quickway.php:257
foreach($arTemplatesList as $templ) if(mb_strpos($templ["NAME"] $def
Определения template_copy.php:264