Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basetype.php
1<?php
2
4
5abstract class BaseType
6{
7 public const
8 MODE_EDIT = 'main.edit',
9 MODE_VIEW = 'main.view';
10
11 private const
12 MODE_ADMIN_SETTINGS = 'main.admin_settings',
13 MODE_EDIT_FORM = 'main.edit_form',
14 MODE_FILTER_HTML = 'main.filter_html',
15 MODE_ADMIN_LIST_VIEW_HTML = 'main.admin_list_view_html',
16 MODE_ADMIN_LIST_EDIT_HTML = 'main.admin_list_edit_html',
17 MODE_PUBLIC_TEXT = 'main.public_text';
18
19 protected const
21 RENDER_COMPONENT = null; // component name, sample bitrix:main.field.string
22
26 public static function getUserTypeDescription(): array
27 {
28 return array_merge(static::getBaseUserTypeDescription(), static::getDescription());
29 }
30
34 protected static function getDescription(): array
35 {
36 return [];
37 }
38
42 protected static function getBaseUserTypeDescription(): array
43 {
44 return [
45 'USER_TYPE_ID' => static::USER_TYPE_ID,
46 'CLASS_NAME' => static::class,
47 'EDIT_CALLBACK' => [static::class, 'renderEdit'],
48 'VIEW_CALLBACK' => [static::class, 'renderView'],
49 'USE_FIELD_COMPONENT' => true,
50 ];
51 }
52
58 public static function renderField(array $userField, ?array $additionalParameters = []): string
59 {
60 return self::getHtml($userField, $additionalParameters);
61 }
62
75 public static function renderView(array $userField, ?array $additionalParameters = []): string
76 {
77 $additionalParameters['mode'] = self::MODE_VIEW;
78 return self::getHtml($userField, $additionalParameters);
79 }
80
92 public static function renderEdit(array $userField, ?array $additionalParameters = []): string
93 {
94 $additionalParameters['mode'] = self::MODE_EDIT;
95 return self::getHtml($userField, $additionalParameters);
96 }
97
108 public static function renderSettings($userField, ?array $additionalParameters, $varsFromForm): string
109 {
110 $additionalParameters['mode'] = self::MODE_ADMIN_SETTINGS;
111 $additionalParameters['bVarsFromForm'] = $varsFromForm;
112 return self::getHtml($userField, $additionalParameters);
113 }
114
126 public static function renderEditForm(array $userField, ?array $additionalParameters): string
127 {
128 $additionalParameters['mode'] = self::MODE_EDIT_FORM;
129 $userField['USE_COMPONENT'] = 'Y';
130 return self::getHtml($userField, $additionalParameters);
131 }
132
143 public static function renderAdminListView(array $userField, ?array $additionalParameters): string
144 {
145 $additionalParameters['mode'] = self::MODE_ADMIN_LIST_VIEW_HTML;
146 return self::getHtml($userField, $additionalParameters);
147 }
148
158 public static function renderAdminListEdit(array $userField, ?array $additionalParameters)
159 {
160 $additionalParameters['mode'] = self::MODE_ADMIN_LIST_EDIT_HTML;
161 return self::getHtml($userField, $additionalParameters);
162 }
163
174 public static function renderFilter(array $userField, ?array $additionalParameters): string
175 {
176 $additionalParameters['mode'] = self::MODE_FILTER_HTML;
177 return self::getHtml($userField, $additionalParameters);
178 }
179
184 public static function renderText(array $userField): string
185 {
186 $additionalParameters = [];
187 $additionalParameters['mode'] = self::MODE_PUBLIC_TEXT;
188 return self::getHtml($userField, $additionalParameters);
189 }
190
196 private static function getHtml($userField, $additionalParameters): string
197 {
198 global $APPLICATION;
199 ob_start();
200 $APPLICATION->IncludeComponent(
201 self::getComponentName(),
202 '',
203 [
204 'userField' => $userField,
205 'additionalParameters' => $additionalParameters,
206 ]
207 );
208 return ob_get_clean();
209 }
210
216 private static function getComponentName(): string
217 {
218 if (str_contains(static::RENDER_COMPONENT, ':'))
219 {
220 return static::RENDER_COMPONENT;
221 }
222 return 'bitrix:' . static::RENDER_COMPONENT;
223 }
224
231 public static function getSettingsHtml($userField, ?array $additionalParameters, $varsFromForm): string
232 {
233 return static::renderSettings($userField, $additionalParameters, $varsFromForm);
234 }
235
241 public static function getPublicView(array $userField, ?array $additionalParameters = []): string
242 {
243 return static::renderView($userField, $additionalParameters);
244 }
245
251 public static function getPublicEdit(array $userField, ?array $additionalParameters = []): string
252 {
253 return static::renderEdit($userField, $additionalParameters);
254 }
255
261 public static function getEditFormHtml(array $userField, ?array $additionalParameters): string
262 {
263 return static::renderEditForm($userField, $additionalParameters);
264 }
265
271 public static function getAdminListViewHtml(array $userField, ?array $additionalParameters)
272 {
273 return static::renderAdminListView($userField, $additionalParameters);
274 }
275
281 public static function getAdminListEditHTML(array $userField, ?array $additionalParameters)
282 {
283 return static::renderAdminListEdit($userField, $additionalParameters);
284 }
285
291 public static function getFilterHtml(array $userField, ?array $additionalParameters): string
292 {
293 return static::renderFilter($userField, $additionalParameters);
294 }
295
300 public static function getPublicText(array $userField): string
301 {
302 return static::renderText($userField);
303 }
304
310 public static function getDefaultValue(array $userField, array $additionalParameters = [])
311 {
312 $value = ($userField['SETTINGS']['DEFAULT_VALUE'] ?? null);
313 return ($userField['MULTIPLE'] === 'Y' ? [$value] : $value);
314 }
315
316 abstract public static function getDbColumnType(): string;
317
318 public static function isMandatorySupported(): bool
319 {
320 return true;
321 }
322
323 public static function isMultiplicitySupported(): bool
324 {
325 return true;
326 }
327}
static renderAdminListEdit(array $userField, ?array $additionalParameters)
Definition basetype.php:158
static getPublicEdit(array $userField, ?array $additionalParameters=[])
Definition basetype.php:251
static renderEdit(array $userField, ?array $additionalParameters=[])
Definition basetype.php:92
static getDefaultValue(array $userField, array $additionalParameters=[])
Definition basetype.php:310
static getAdminListEditHTML(array $userField, ?array $additionalParameters)
Definition basetype.php:281
static renderEditForm(array $userField, ?array $additionalParameters)
Definition basetype.php:126
static getEditFormHtml(array $userField, ?array $additionalParameters)
Definition basetype.php:261
static getAdminListViewHtml(array $userField, ?array $additionalParameters)
Definition basetype.php:271
static renderText(array $userField)
Definition basetype.php:184
static renderField(array $userField, ?array $additionalParameters=[])
Definition basetype.php:58
static getSettingsHtml($userField, ?array $additionalParameters, $varsFromForm)
Definition basetype.php:231
static renderView(array $userField, ?array $additionalParameters=[])
Definition basetype.php:75
static renderSettings($userField, ?array $additionalParameters, $varsFromForm)
Definition basetype.php:108
static getFilterHtml(array $userField, ?array $additionalParameters)
Definition basetype.php:291
static renderFilter(array $userField, ?array $additionalParameters)
Definition basetype.php:174
static getPublicText(array $userField)
Definition basetype.php:300
static getPublicView(array $userField, ?array $additionalParameters=[])
Definition basetype.php:241
static renderAdminListView(array $userField, ?array $additionalParameters)
Definition basetype.php:143