Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
formatcode.php
1
<?php
2
3
namespace
Bitrix\Location\Infrastructure
;
4
5
use
Bitrix\Main\Config\Option
;
6
use
Bitrix\Main\Event
;
7
use
Bitrix\Main\Application
;
8
14
class
FormatCode
15
{
16
protected
static
$optionName
=
'address_format_code'
;
17
protected
static
$onChangedEventName
=
'onCurrentFormatCodeChanged'
;
18
19
public
static
function
getCurrent
(
string
$regionId =
null
,
string
$siteId =
''
): string
20
{
21
return
Option::get(
22
'location'
,
23
static::$optionName,
24
static::getDefault($regionId),
25
$siteId
26
);
27
}
28
29
public
static
function
setCurrent
(
string
$formatCode,
string
$siteId =
''
): void
30
{
31
Option::set(
32
'location'
,
33
static::$optionName,
34
$formatCode,
35
$siteId
36
);
37
38
$event =
new
Event
(
'location'
, static::$onChangedEventName, [
'formatCode'
=> $formatCode]);
39
$event->send();
40
}
41
46
public
static
function
getDefault
(
string
$regionId =
null
): string
47
{
48
$regionId = $regionId ?? static::getRegion();
49
50
$map = [
51
'kz'
=>
'RU_2'
,
52
'en'
=>
'US'
,
53
'eu'
=>
'EU'
,
54
'de'
=>
'EU'
,
55
'la'
=>
'EU'
,
56
'br'
=>
'BR'
,
57
'fr'
=>
'EU'
,
58
'it'
=>
'EU'
,
59
'pl'
=>
'EU'
,
60
'uk'
=>
'UK'
,
61
];
62
63
return
$map[$regionId] ??
'RU'
;
64
}
65
69
private
static
function
getRegion(): string
70
{
71
$region =
Application::getInstance
()->getLicense()->getRegion();
72
73
return
$region ?? LANGUAGE_ID;
74
}
75
}
Bitrix\Location\Infrastructure\FormatCode
Definition
formatcode.php:15
Bitrix\Location\Infrastructure\FormatCode\$onChangedEventName
static $onChangedEventName
Definition
formatcode.php:17
Bitrix\Location\Infrastructure\FormatCode\getDefault
static getDefault(string $regionId=null)
Definition
formatcode.php:46
Bitrix\Location\Infrastructure\FormatCode\$optionName
static $optionName
Definition
formatcode.php:16
Bitrix\Location\Infrastructure\FormatCode\setCurrent
static setCurrent(string $formatCode, string $siteId='')
Definition
formatcode.php:29
Bitrix\Location\Infrastructure\FormatCode\getCurrent
static getCurrent(string $regionId=null, string $siteId='')
Definition
formatcode.php:19
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getInstance
static getInstance()
Definition
application.php:95
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Location\Infrastructure
Definition
datainstaller.php:3
modules
location
lib
infrastructure
formatcode.php
Создано системой
1.10.0