Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
type.php
1<?php
10
11
16
17class Type extends TypeBase
18{
19 const USER_TYPE_ID = 'rest';
20
21 public static function getDBColumnType()
22 {
23 $connection = \Bitrix\Main\Application::getConnection();
24 $helper = $connection->getSqlHelper();
25 return $helper->getColumnTypeByField(new \Bitrix\Main\ORM\Fields\TextField('x'));
26 }
27
28 public static function getPublicView($arUserField, $arAdditionalParameters = array())
29 {
30 $value = static::getFieldValue($arUserField, $arAdditionalParameters);
31
32 $arUserField['VALUE'] = $value;
33
34 return static::getApplication($arUserField, array(), 'view');
35 }
36
37 public static function getPublicEdit($arUserField, $arAdditionalParameters = array())
38 {
39 $fieldName = static::getFieldName($arUserField, $arAdditionalParameters);
40 $value = static::getFieldValue($arUserField, $arAdditionalParameters);
41
42 $arUserField['VALUE'] = $value;
43
44 return static::getApplication($arUserField, array(
45 'NAME' => $fieldName
46 ), 'edit');
47 }
48
49 function getEditFormHTML($arUserField, $arHtmlControl)
50 {
51 return static::getApplication($arUserField, $arHtmlControl, 'edit');
52 }
53
54 function getEditFormHTMLMulty($arUserField, $arHtmlControl)
55 {
56 return static::getApplication($arUserField, $arHtmlControl, 'edit');
57 }
58
59 protected static function getApplication($arUserField, $arHtmlControl, $mode = 'edit')
60 {
61 global $APPLICATION;
62
63 $fieldName = $arHtmlControl['NAME'];
64 $value = static::normalizeFieldValue($arUserField['VALUE']);
65
66 $placementHandlerList = PlacementTable::getHandlersList(UserFieldType::PLACEMENT_UF_TYPE);
67 $currentPlacementHandler = null;
68 foreach($placementHandlerList as $placementInfo)
69 {
70 if($arUserField['USER_TYPE_ID'] === Callback::getUserTypeId($placementInfo))
71 {
72 $currentPlacementHandler = $placementInfo;
73 break;
74 }
75 }
76
77 $html = '';
78 if($currentPlacementHandler !== null)
79 {
80 ob_start();
81
82 if($mode === 'edit'):
83?>
84<div style="display: none;" id="uf_rest_value_<?=$arUserField['FIELD_NAME']?>">
85<?
86 foreach($value as $res):
87?>
88 <input type="hidden" name="<?=$fieldName?>" value="<?=HtmlFilter::encode($res)?>" />
89<?
90 endforeach;
91 endif;
92?>
93</div>
94<?
95 $placementSid = $APPLICATION->includeComponent(
96 'bitrix:app.layout',
97 '',
98 array(
99 'ID' => $currentPlacementHandler['APP_ID'],
100 'PLACEMENT_ID' => $currentPlacementHandler['ID'],
101 'PLACEMENT' => UserFieldType::PLACEMENT_UF_TYPE,
102 'SHOW_LOADER' => 'N',
103 'SET_TITLE' => 'N',
104 'PLACEMENT_OPTIONS' => array(
105 'MODE' => $mode,
106 'ENTITY_ID' => $arUserField['ENTITY_ID'],
107 'FIELD_NAME' => $arUserField['FIELD_NAME'],
108 'ENTITY_VALUE_ID' => $arUserField['ENTITY_VALUE_ID'],
109 'VALUE' => $arUserField['MULTIPLE'] === 'N' ? $value[0] : $value,
110 'MULTIPLE' => $arUserField['MULTIPLE'],
111 'MANDATORY' => $arUserField['MANDATORY'],
112 'XML_ID' => $arUserField['XML_ID'],
113 ),
114 'PARAM' => array(
115 'FRAME_HEIGHT' => '200px',
116 )
117 ),
118 null,
119 array('HIDE_ICONS' => 'Y')
120 );
121?>
122<script>
123 (function(){
124 'use strict';
125
126 new BX.rest.UserField('<?=$placementSid?>', {
127 value: <?=\CUtil::phpToJsObject($arUserField['VALUE'])?>,
128 callback: function(value)
129 {
130<?
131 if($mode === 'edit'):
132?>
133 if(!BX.type.isArray(value))
134 {
135 value = [value];
136 }
137
138 var html = '';
139 for(var i = 0; i < value.length; i++)
140 {
141 html += '<input type="hidden" name="<?=$fieldName?>" value="'+BX.util.htmlspecialchars(value[i])+'" />';
142 }
143
144 BX('uf_rest_value_<?=$arUserField['FIELD_NAME']?>').innerHTML = html;
145
146 var input = BX('uf_rest_value_<?=$arUserField['FIELD_NAME']?>').firstChild;
147 if(input)
148 {
149 BX.fireEvent(input, 'change');
150 }
151<?
152 endif;
153?>
154 }
155 });
156
157 })();
158</script>
159
160<?
161 $html = ob_get_clean();
162 }
163
164 \CJSCore::init(array('rest_userfield'));
165
166 return static::getHelper()->wrapDisplayResult($html);
167
168 }
169
170 function prepareSettings($arUserField){}
171 function getSettingsHTML($arUserField, $arHtmlControl, $bVarsFromForm){}
172 function getFilterHTML($arUserField, $arHtmlControl){}
173 function getFilterData($arUserField, $arHtmlControl){}
174 function getAdminListViewHTML($arUserField, $arHtmlControl){}
175 function getAdminListViewHTMLMulty($arUserField, $arHtmlControl){}
176 function getAdminListEditHTML($arUserField, $arHtmlControl){}
177 function getAdminListEditHTMLMulty($arUserField, $arHtmlControl){}
178}
static getHandlersList($placement, $skipInstallCheck=false, int $userId=null)
static getUserTypeId($userTypeInfo)
Definition callback.php:88
getFilterHTML($arUserField, $arHtmlControl)
Definition type.php:172
prepareSettings($arUserField)
Definition type.php:170
static getPublicView($arUserField, $arAdditionalParameters=array())
Definition type.php:28
getFilterData($arUserField, $arHtmlControl)
Definition type.php:173
getSettingsHTML($arUserField, $arHtmlControl, $bVarsFromForm)
Definition type.php:171
getAdminListViewHTMLMulty($arUserField, $arHtmlControl)
Definition type.php:175
getEditFormHTMLMulty($arUserField, $arHtmlControl)
Definition type.php:54
static getApplication($arUserField, $arHtmlControl, $mode='edit')
Definition type.php:59
getAdminListViewHTML($arUserField, $arHtmlControl)
Definition type.php:174
getEditFormHTML($arUserField, $arHtmlControl)
Definition type.php:49
static getPublicEdit($arUserField, $arAdditionalParameters=array())
Definition type.php:37
getAdminListEditHTMLMulty($arUserField, $arHtmlControl)
Definition type.php:177
getAdminListEditHTML($arUserField, $arHtmlControl)
Definition type.php:176