Bitrix-D7  20.5.0
internals/sitecurrency.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage sale
6  * @copyright 2001-2014 Bitrix
7  */
8 namespace Bitrix\Sale\Internals;
9 
10 use Bitrix\Main,
12 
13 class SiteCurrencyTable extends Main\Entity\DataManager
14 {
15  private static $cache = array();
16 
17  public static function getFilePath()
18  {
19  return __FILE__;
20  }
21 
22  public static function getTableName()
23  {
24  return 'b_sale_lang';
25  }
26 
27  public static function getMap()
28  {
29  return array(
30  'LID' => array(
31  'data_type' => 'string',
32  'primary' => true,
33  'format' => '/^[A-Za-z0-9_]{2}$/'
34  ),
35  'CURRENCY' => array(
36  'data_type' => 'string',
37  'format' => '/^[A-Z]{3}$/'
38  )
39  );
40  }
41 
42  /**
43  * Returns site currency data.
44  *
45  * @param string $siteId Site id.
46  * @return bool|array
47  */
48  public static function getCurrency($siteId)
49  {
50  $siteId = (string)$siteId;
51  if ($siteId == '')
52  return false;
53  if (empty(self::$cache))
54  {
55  $managed = Application::getInstance()->getManagedCache();
56  $key = self::getTableName();
57 
58  if ($managed->read(3600, $key))
59  self::$cache = $managed->get($key);
60  else
61  {
62  $result = self::getList(array(
63  'select' => array('*')
64  ));
65  while ($row = $result->fetch())
66  self::$cache[$row['LID']] = $row;
67  unset($row, $result);
68  $managed->set($key, self::$cache);
69  }
70  }
71  return (isset(self::$cache[$siteId]) ? self::$cache[$siteId] : false);
72  }
73 
74  /**
75  * Returns site currency.
76  *
77  * @param string $siteId Site id.
78  * @return string
79  */
80  public static function getSiteCurrency($siteId)
81  {
82  $siteData = self::getCurrency($siteId);
83  return (!empty($siteData['CURRENCY']) ? $siteData['CURRENCY'] : (string)Main\Config\Option::get('sale', 'default_currency'));
84  }
85 
86  public static function onAfterAdd(Main\Entity\Event $event)
87  {
88  Application::getInstance()->getManagedCache()->clean(self::getTableName());
89  self::$cache = array();
90  }
91 
92  public static function onAfterUpdate(Main\Entity\Event $event)
93  {
94  Application::getInstance()->getManagedCache()->clean(self::getTableName());
95  self::$cache = array();
96  }
97 
98  public static function onAfterDelete(Main\Entity\Event $event)
99  {
100  Application::getInstance()->getManagedCache()->clean(self::getTableName());
101  self::$cache = array();
102  }
103 }
Base class for any application.
static getInstance()
Returns current instance of the Application.
static get($moduleId, $name, $default="", $siteId=false)
Returns a value of an option.
static getSiteCurrency($siteId)
Returns site currency.
static onAfterDelete(Main\Entity\Event $event)
static onAfterUpdate(Main\Entity\Event $event)
static getCurrency($siteId)
Returns site currency data.
static onAfterAdd(Main\Entity\Event $event)