Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
namehelper.php
1
<?
9
namespace
Bitrix\Sale\Location\Admin
;
10
11
use
Bitrix\Main
;
12
use
Bitrix\Main\Localization\Loc
;
13
14
abstract
class
NameHelper
extends
Helper
15
{
16
#####################################
17
#### Entity settings
18
#####################################
19
20
public
static
function
getEntityRoadCode
()
21
{
22
return
'name'
;
23
}
24
25
public
static
function
getColumns
($page)
26
{
27
return
array_merge(parent::getColumns($page), self::getMap($page));
28
}
29
30
// get part of the whole field map for responsibility zone of the current entity
31
// call this only with self::
32
public
static
function
getMap
($page)
33
{
34
static
$flds;
35
36
if
($flds ==
null
)
37
{
38
$preFlds = static::readMap(self::getEntityRoadCode(), $page);
39
40
// actually, NAME is not required when adding through LocationTable::add(), unless SHORT_NAME is set
41
unset($preFlds[
'NAME'
][
'required'
]);
42
43
$flds = array();
44
$languages =
self::getLanguageList
();
45
46
foreach
($languages as $lang)
47
{
48
foreach
($preFlds as $code => $column)
49
{
50
$tmpCol = $column;
51
52
$tmpCol[
'title'
] = $tmpCol[
'title'
].
' ('
.$lang.
')'
;
53
$flds[$code.
'_'
.ToUpper($lang)] = $tmpCol;
54
}
55
}
56
}
57
58
return
$flds;
59
}
60
61
#####################################
62
#### CRUD wrappers
63
#####################################
64
65
// generalized filter to orm filter proxy
66
public
static
function
getParametersForList
($proxed)
67
{
68
$parameters = parent::getParametersForList($proxed);
69
70
$fldSubMap = static::readMap(self::getEntityRoadCode(),
'list'
);
71
$roadMap = static::getEntityRoadMap();
72
$road = $roadMap[
self::getEntityRoadCode
()][
'name'
];
73
$class = $road.
'Table'
;
74
$languages =
self::getLanguageList
();
75
76
// select all names
77
foreach
($languages as $lang)
78
{
79
$lang = ToUpper($lang);
80
81
$parameters[
'runtime'
][
'NAME__'
.$lang] = array(
82
'data_type'
=> $road,
83
'reference'
=> array(
84
'=this.ID'
=>
'ref.'
.$class::getReferenceFieldName(),
85
'=ref.'
. $class::getLanguageFieldName() => array(
'?'
, ToLower($lang))
// oracle is case-sensitive
86
),
87
'join_type'
=>
'left'
88
);
89
90
if
(!isset($parameters[
'select'
]))
91
$parameters[
'select'
] = array();
92
foreach
($fldSubMap as $code => $fld)
93
$parameters[
'select'
][$code.
'_'
.$lang] =
'NAME__'
.$lang.
'.'
.$code;
94
}
95
96
// filter
97
if
(is_array($proxed[
'FILTER'
]) && !empty($proxed[
'FILTER'
]))
98
{
99
foreach
($languages as $lang)
100
{
101
$lang = ToUpper($lang);
102
103
foreach
($fldSubMap as $code => $fld)
104
{
105
$key = $code.
'_'
.$lang;
106
107
if
(isset($proxed[
'FILTER'
][$key]))
108
{
109
$parameters[
'filter'
][static::getFilterModifier($fld[
'data_type'
]).
'NAME__'
.$lang.
'.'
.$code] = $proxed[
'FILTER'
][$key];
110
}
111
}
112
}
113
}
114
115
return
$parameters;
116
}
117
118
##############################################
119
##############################################
120
##############################################
121
122
public
static
function
validateUpdateRequest
($data)
123
{
124
$errors = parent::validateUpdateRequest($data);
125
126
// formally check language ids in NAME parameter
127
if
(is_array($data[
'NAME'
]) && !empty($data[
'NAME'
]))
128
{
129
$languages =
self::getLanguageList
();
130
131
foreach
($data[
'NAME'
] as $lid => $name)
132
{
133
if
(!isset($languages[$lid]))
134
{
135
$errors[] =
Loc::getMessage
(
'SALE_LOCATION_ADMIN_NAME_HELPER_ENTITY_UNKNOWN_LANGUAGE_ID_ERROR'
);
136
break
;
137
}
138
}
139
}
140
141
return
$errors;
142
}
143
144
public
static
function
proxyUpdateRequest
($data)
145
{
146
$names = static::extractNames($data);
147
$data = parent::proxyUpdateRequest($data);
148
149
if
(!empty($names))
150
$data[
'NAME'
] = $names;
151
152
return
$data;
153
}
154
155
// an adapter from CAdminList to ORM getList() logic
156
public
static
function
proxyListRequest
($page)
157
{
158
$parameters = parent::proxyListRequest($page);
159
160
$fldSubMap = static::readMap(self::getEntityRoadCode(),
'list'
);
161
$roadMap = static::getEntityRoadMap();
162
$road = $roadMap[
self::getEntityRoadCode
()][
'name'
];
163
$class = $road.
'Table'
;
164
$languages =
self::getLanguageList
();
165
166
// select
167
168
foreach
($languages as $lang)
169
{
170
$lang = ToUpper($lang);
171
172
$parameters[
'runtime'
][
'NAME__'
.$lang] = array(
173
'data_type'
=> $road,
174
'reference'
=> array(
175
'=this.ID'
=>
'ref.'
.$class::getReferenceFieldName(),
176
'=ref.'
. $class::getLanguageFieldName() => array(
'?'
, ToLower($lang))
// oracle is case-sensitive
177
),
178
'join_type'
=>
'left'
179
);
180
181
if
(!isset($parameters[
'select'
]))
182
$parameters[
'select'
] = array();
183
foreach
($fldSubMap as $code => $fld)
184
$parameters[
'select'
][$code.
'_'
.$lang] =
'NAME__'
.$lang.
'.'
.$code;
185
}
186
187
// filter
188
if
(self::checkUseFilter())
189
{
190
foreach
($languages as $lang)
191
{
192
$lang = ToUpper($lang);
193
194
foreach
($fldSubMap as $code => $fld)
195
{
196
$key =
'find_'
.$code.
'_'
.$lang;
197
198
if
(
$GLOBALS
[$key] <>
''
)
199
{
200
$parameters[
'filter'
][static::getFilterModifier($fld[
'data_type'
]).
'NAME__'
.$lang.
'.'
.$code] =
$GLOBALS
[$key];
201
}
202
}
203
}
204
}
205
206
return
$parameters;
207
}
208
209
public
static
function
getNameToDisplay
($id)
210
{
211
if
(!($id = intval($id)))
212
return
''
;
213
214
$class = static::getEntityClass(
'main'
);
215
$nameClass = static::getEntityClass(self::getEntityRoadCode());
216
$item = $class::getList(array(
217
'filter'
=> array(
'=ID'
=> $id,
'NAME.'
.$nameClass::getLanguageFieldName() => LANGUAGE_ID),
218
'select'
=> array(
'LNAME'
=>
'NAME.NAME'
)
219
))->fetch();
220
221
return
$item[
'LNAME'
];
222
}
223
224
#####################################
225
#### Entity-specific
226
#####################################
227
228
public
static
function
getLanguageList
()
229
{
230
static
$languages;
231
232
if
($languages ==
null
)
233
{
234
$lang = new \CLanguage();
235
$res = $lang->GetList();
236
$languages = array();
237
while
($item = $res->Fetch())
238
$languages[$item[
'LANGUAGE_ID'
]] = $item[
'LANGUAGE_ID'
];
239
}
240
241
return
$languages;
242
}
243
244
public
static
function
getTranslatedName
($names, $languageId)
245
{
246
if
(!is_array($names) || empty($names) || (
string
) $languageId ==
''
)
247
return
''
;
248
249
$languageIdMapped = static::mapLanguage($languageId);
250
251
if
(is_array($names[$languageId]) && (
string
) $names[$languageId][
'NAME'
] !=
''
)
252
return
$names[$languageId];
253
254
if
(is_array($names[$languageIdMapped]) && (
string
) $names[$languageIdMapped][
'NAME'
] !=
''
)
255
return
$names[$languageIdMapped];
256
257
$languageId = ToUpper($languageId);
258
$languageIdMapped = ToUpper($languageIdMapped);
259
260
if
(is_array($names[$languageId]) && (
string
) $names[$languageId][
'NAME'
] !=
''
)
261
return
$names[$languageId];
262
263
if
(is_array($names[$languageIdMapped]) && (
string
) $names[$languageIdMapped][
'NAME'
] !=
''
)
264
return
$names[$languageIdMapped];
265
266
if
((
string
) $names[
'EN'
] !=
''
)
267
return
$names[
'EN'
];
268
269
return
''
;
270
}
271
272
// extracts NAME data from known data, rather than do a separate query for it
273
public
static
function
extractNames
(&$data)
274
{
275
$fldSubMap = static::readMap(self::getEntityRoadCode());
276
$languages =
self::getLanguageList
();
277
278
$names = array();
279
foreach
($languages as $lang)
280
{
281
foreach
($fldSubMap as $code => $fld)
282
{
283
$langU = ToUpper($lang);
284
285
$key = $code.
'_'
.$langU;
286
if
(isset($data[$key]))
287
$names[$lang][$code] = $data[$key];
288
289
unset($data[$key]);
290
}
291
}
292
293
return
$names;
294
}
295
296
public
static
function
checkIsNameField
($code)
297
{
298
$map =
self::getMap
(
'detail'
);
299
return
isset($map[$code]);
300
}
301
302
public
static
function
getNameMap
()
303
{
304
$map = static::readMap(
'name'
,
'detail'
);
305
306
// actually, NAME is not required when adding through LocationTable::add(), unless SHORT_NAME is set
307
// unset($map['NAME']['required']);
308
309
return
$map;
310
}
311
312
#####################################
313
#### Utilitary functions
314
#####################################
315
316
public
static
function
translitFromUTF8
($string)
317
{
318
$match = array(
319
"\xD0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=>
"r"
,
"\xD1\x81"
=>
"s"
,
"\xD1\x82"
=>
"t"
,
331
"\xD1\x83"
=>
"u"
,
"\xD1\x84"
=>
"f"
,
"\xD1\x85"
=>
"h"
,
"\xD1\x86"
=>
"c"
,
"\xD1\x87"
=>
"ch"
,
332
"\xD1\x88"
=>
"sh"
,
"\xD1\x89"
=>
"sch"
,
"\xD1\x8C"
=>
""
,
"\xD1\x8B"
=>
"y"
,
"\xD1\x8A"
=>
""
,
333
"\xD1\x8d"
=>
"e"
,
"\xD1\x8E"
=>
"yu"
,
"\xD1\x8F"
=>
"ya"
,
334
);
335
336
return
str_replace(array_keys($match), array_values($match), $string);
337
}
338
339
public
static
function
mapLanguage
($lid)
340
{
341
if
($lid ==
'ua'
|| $lid ==
'kz'
)
342
return
'ru'
;
343
344
return
'en'
;
345
}
346
}
Bitrix\Main\Diag\Helper
Definition
helper.php:5
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Sale\Location\Admin\NameHelper
Definition
namehelper.php:15
Bitrix\Sale\Location\Admin\NameHelper\getNameToDisplay
static getNameToDisplay($id)
Definition
namehelper.php:209
Bitrix\Sale\Location\Admin\NameHelper\getMap
static getMap($page)
Definition
namehelper.php:32
Bitrix\Sale\Location\Admin\NameHelper\getColumns
static getColumns($page)
Definition
namehelper.php:25
Bitrix\Sale\Location\Admin\NameHelper\translitFromUTF8
static translitFromUTF8($string)
Definition
namehelper.php:316
Bitrix\Sale\Location\Admin\NameHelper\proxyUpdateRequest
static proxyUpdateRequest($data)
Definition
namehelper.php:144
Bitrix\Sale\Location\Admin\NameHelper\getTranslatedName
static getTranslatedName($names, $languageId)
Definition
namehelper.php:244
Bitrix\Sale\Location\Admin\NameHelper\checkIsNameField
static checkIsNameField($code)
Definition
namehelper.php:296
Bitrix\Sale\Location\Admin\NameHelper\getParametersForList
static getParametersForList($proxed)
Definition
namehelper.php:66
Bitrix\Sale\Location\Admin\NameHelper\getLanguageList
static getLanguageList()
Definition
namehelper.php:228
Bitrix\Sale\Location\Admin\NameHelper\getEntityRoadCode
static getEntityRoadCode()
Definition
namehelper.php:20
Bitrix\Sale\Location\Admin\NameHelper\extractNames
static extractNames(&$data)
Definition
namehelper.php:273
Bitrix\Sale\Location\Admin\NameHelper\validateUpdateRequest
static validateUpdateRequest($data)
Definition
namehelper.php:122
Bitrix\Sale\Location\Admin\NameHelper\mapLanguage
static mapLanguage($lid)
Definition
namehelper.php:339
Bitrix\Sale\Location\Admin\NameHelper\proxyListRequest
static proxyListRequest($page)
Definition
namehelper.php:156
Bitrix\Sale\Location\Admin\NameHelper\getNameMap
static getNameMap()
Definition
namehelper.php:302
Bitrix\Main
Bitrix\Main\$GLOBALS
$GLOBALS['____1444769544']
Definition
license.php:1
Bitrix\Sale\Location\Admin
Definition
defaultsitehelper.php:9
modules
sale
lib
location
admin
namehelper.php
Создано системой
1.10.0