Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
formatcode.php
1<?php
2
4
8
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}
static getDefault(string $regionId=null)
static setCurrent(string $formatCode, string $siteId='')
static getCurrent(string $regionId=null, string $siteId='')