Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sitecurrency.php
1<?php
9
10use Bitrix\Main,
12
29class SiteCurrencyTable extends Main\Entity\DataManager
30{
31 private static $cache = array();
32
33 public static function getFilePath()
34 {
35 return __FILE__;
36 }
37
38 public static function getTableName()
39 {
40 return 'b_sale_lang';
41 }
42
43 public static function getMap()
44 {
45 return array(
46 'LID' => array(
47 'data_type' => 'string',
48 'primary' => true,
49 'format' => '/^[A-Za-z0-9_]{2}$/'
50 ),
51 'CURRENCY' => array(
52 'data_type' => 'string',
53 'format' => '/^[A-Z]{3}$/'
54 )
55 );
56 }
57
64 public static function getCurrency($siteId)
65 {
66 $siteId = (string)$siteId;
67 if ($siteId == '')
68 return false;
69 if (empty(self::$cache))
70 {
71 $managed = Application::getInstance()->getManagedCache();
72 $key = self::getTableName();
73
74 if ($managed->read(3600, $key))
75 self::$cache = $managed->get($key);
76 else
77 {
78 $result = self::getList(array(
79 'select' => array('*')
80 ));
81 while ($row = $result->fetch())
82 self::$cache[$row['LID']] = $row;
83 unset($row, $result);
84 $managed->set($key, self::$cache);
85 }
86 }
87 return (isset(self::$cache[$siteId]) ? self::$cache[$siteId] : false);
88 }
89
96 public static function getSiteCurrency($siteId)
97 {
98 $siteData = self::getCurrency($siteId);
99 return (!empty($siteData['CURRENCY']) ? $siteData['CURRENCY'] : (string)Main\Config\Option::get('sale', 'default_currency'));
100 }
101
102 public static function onAfterAdd(Main\Entity\Event $event)
103 {
104 Application::getInstance()->getManagedCache()->clean(self::getTableName());
105 self::$cache = array();
106 }
107
108 public static function onAfterUpdate(Main\Entity\Event $event)
109 {
110 Application::getInstance()->getManagedCache()->clean(self::getTableName());
111 self::$cache = array();
112 }
113
114 public static function onAfterDelete(Main\Entity\Event $event)
115 {
116 Application::getInstance()->getManagedCache()->clean(self::getTableName());
117 self::$cache = array();
118 }
119}
static onAfterDelete(Main\Entity\Event $event)
static onAfterUpdate(Main\Entity\Event $event)
static onAfterAdd(Main\Entity\Event $event)