Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
typebase.php
1<?php
2
4
7
14abstract class TypeBase
15{
16 static $helper = array();
17
18 const USER_TYPE_ID = '_generic';
19
23 public static function getHelper()
24 {
25 if(!array_key_exists(static::USER_TYPE_ID, static::$helper))
26 {
27 static::setHelper(new TypeHelper(static::USER_TYPE_ID));
28 }
29
30 return static::$helper[static::USER_TYPE_ID];
31 }
32
36 public static function setHelper(TypeHelper $helper)
37 {
38 static::$helper[static::USER_TYPE_ID] = $helper;
39 }
40
41 protected static function initDisplay(array $additional = array())
42 {
43 \CJSCore::init(array_merge(array('uf'), $additional));
44 }
45
46 protected static function buildTagAttributes(array $attributes)
47 {
48 $s = '';
49 foreach($attributes as $attribute => $value)
50 {
51 $s .= htmlspecialcharsbx($attribute) . '="' . htmlspecialcharsbx($value) . '" ';
52 }
53
54 return $s;
55 }
56
57 protected static function getFieldName($arUserField, $arAdditionalParameters = array())
58 {
59 $fieldName = $arUserField["FIELD_NAME"];
60 if($arUserField["MULTIPLE"] == "Y")
61 {
62 $fieldName .= "[]";
63 }
64
65 return $fieldName;
66 }
67
68 protected static function normalizeFieldValue($value)
69 {
70 if(!is_array($value))
71 {
72 $value = array($value);
73 }
74 if(empty($value))
75 {
76 $value = array(null);
77 }
78
79 return $value;
80 }
81
82 protected static function getFieldValue($arUserField, $arAdditionalParameters = array())
83 {
84 if(!$arAdditionalParameters["bVarsFromForm"])
85 {
86 if($arUserField["ENTITY_VALUE_ID"] <= 0)
87 {
88 switch($arUserField['USER_TYPE_ID'])
89 {
90 case \CUserTypeDate::USER_TYPE_ID:
91 case \CUserTypeDateTime::USER_TYPE_ID:
92
93 $full = $arUserField['USER_TYPE_ID'] === \CUserTypeDateTime::USER_TYPE_ID;
94 if($arUserField["SETTINGS"]["DEFAULT_VALUE"]["TYPE"] == "NOW")
95 {
96 $value = $full
97 ? \ConvertTimeStamp(time() + \CTimeZone::getOffset(), "FULL")
98 : \ConvertTimeStamp(time(), 'SHORT');
99 }
100 else
101 {
102 $value = $full
103 ? str_replace(" 00:00:00", "", \CDatabase::formatDate($arUserField["SETTINGS"]["DEFAULT_VALUE"]["VALUE"], "YYYY-MM-DD HH:MI:SS", \CLang::getDateFormat("FULL")))
104 : \CDatabase::formatDate($arUserField["SETTINGS"]["DEFAULT_VALUE"]["VALUE"], "YYYY-MM-DD", \CLang::getDateFormat('SHORT'));
105 }
106
107 break;
108 case \CUserTypeEnum::USER_TYPE_ID:
109
110 $value = $arUserField['MULTIPLE'] === 'Y' ? array() : null;
111 foreach($arUserField['ENUM'] as $enum)
112 {
113 if($enum['DEF'] === 'Y')
114 {
115 if($arUserField['MULTIPLE'] === 'Y')
116 {
117 $value[] = $enum['ID'];
118 }
119 else
120 {
121 $value = $enum['ID'];
122 break;
123 }
124 }
125 }
126
127 break;
128 default:
129 $value = $arUserField["SETTINGS"]["DEFAULT_VALUE"];
130
131 break;
132 }
133 }
134 else
135 {
136 $value = $arUserField["VALUE"];
137 }
138 }
139 else
140 {
141 $value = $_REQUEST[$arUserField["FIELD_NAME"]];
142 }
143
144 return static::normalizeFieldValue($value);
145 }
146
147 public static function getPublicText($userField)
148 {
149 $value = static::normalizeFieldValue($userField['VALUE']);
150
151 return join(', ', array_map(function($v)
152 {
153 return is_null($v) || is_scalar($v) ? (string)$v : '';
154 }, $value));
155 }
156
157}
static buildTagAttributes(array $attributes)
Definition typebase.php:46
static setHelper(TypeHelper $helper)
Definition typebase.php:36
static normalizeFieldValue($value)
Definition typebase.php:68
static getFieldName($arUserField, $arAdditionalParameters=array())
Definition typebase.php:57
static getPublicText($userField)
Definition typebase.php:147
static initDisplay(array $additional=array())
Definition typebase.php:41
static getFieldValue($arUserField, $arAdditionalParameters=array())
Definition typebase.php:82