25 if (func_num_args() == 2)
34 if ($this->
id ===
null && $this === $instance)
36 $pending =& self::$session[
'PENDING_COUNTERS'];
38 if (empty($pending[$name]))
41 $pending[$name] += (float) $value;
45 parent::addCounter($day, $name, $value);
59 $session =& self::$session;
61 if ($this->
id ===
null && $this === $instance)
63 $session[
'PENDING_DAY_COUNTERS'][$name] = (float) $value;
67 $unique =& $session[
'UNIQUE'];
69 if (!in_array($name, $unique,
true))
92 $isToday = $day instanceof
Date ? $day->
format(
'dmY') === date(
'dmY') :
false;
95 $unique =& self::$session[
'UNIQUE'];
96 if (($i = array_search($name, $unique,
true)) !==
false)
141 if (! is_string($entity))
144 if (! is_scalar($item))
149 if ($this->
id ===
null && $this === $instance)
151 self::$session[
'PENDING_ENTITY_ITEMS'][$entity.
':'.$item] = array(
'ENTITY' => $entity,
'ITEM' => $item);
157 Internals\ContextEntityItemTable::add(array(
158 'CONTEXT_ID' => $this->
id,
163 catch (\
Bitrix\Main\DB\SqlQueryException $e)
180 $context = Internals\ContextEntityItemTable::getList(array(
181 'select' => array(
'CONTEXT_ID'),
182 'filter' => array(
'=ENTITY' => $entity,
'=ITEM' => $item),
187 if ($contextId !== $instance->id)
189 $instance =
new self;
190 $instance->id = $contextId;
206 if (preg_match(
'/[a-z0-9_]{2}/i', $siteId) && self::getSiteId() != $siteId && \CSite::getById($siteId)->fetch())
208 $instance =
new self;
210 foreach (EventManager::getInstance()->findEventHandlers(
'conversion',
'OnSetDayContextAttributes') as $handler)
211 ExecuteModuleEventEx($handler, array($instance));
213 $instance->setAttribute(
'conversion_site', $siteId);
221 private static $instance;
222 private static $session;
231 if (! self::$instance)
233 $instance =
new self;
235 $session =& $_SESSION[$varName];
236 $expire = strtotime(
'today 23:59');
238 if (! (is_array($session) && is_int($session[
'ID']) && $session[
'EXPIRE'] === $expire))
240 $session = array(
'ID' =>
null,
'EXPIRE' => $expire,
'UNIQUE' => array());
242 if ($cookie = $_COOKIE[$varName])
246 $cookie = Json::decode($cookie);
254 if ( is_array($cookie)
255 && is_array($cookie[
'UNIQUE'])
256 && $cookie[
'EXPIRE'] === $expire
257 && (
$id = $cookie[
'ID']) !==
null
259 && (
$id === self::EMPTY_CONTEXT_ID || Internals\ContextTable::getByPrimary(
$id)->fetch())
262 $session[
'ID' ] =
$id;
263 $session[
'UNIQUE'] = $cookie[
'UNIQUE'];
267 $instance->id = $session[
'ID'];
268 self::$session =& $session;
269 self::$instance = $instance;
272 return self::$instance;
276 private function setCookie()
278 $session = self::$session;
283 'ID' => $session[
'ID'],
284 'EXPIRE' => $session[
'EXPIRE'],
285 'UNIQUE' => $session[
'UNIQUE'],
287 strtotime(
'+1 year'),
290 $cookie->setHttpOnly(
false);
292 Main\Context::getCurrent()->getResponse()->addCookie($cookie);
299 $session =& self::$session;
301 if ($instance->id ===
null)
303 foreach (EventManager::getInstance()->findEventHandlers(
'conversion',
'OnSetDayContextAttributes') as $handler)
304 ExecuteModuleEventEx($handler, array($instance));
309 $session[
'ID'] = $instance->id;
310 $instance->setCookie();
312 if (!empty($session[
'PENDING_COUNTERS']) && is_array($session[
'PENDING_COUNTERS']))
314 foreach ($session[
'PENDING_COUNTERS'] as $name => $value)
315 $instance->addCounter($name, $value);
318 if (!empty($session[
'PENDING_DAY_COUNTERS']) && is_array($session[
'PENDING_DAY_COUNTERS']))
320 foreach ($session[
'PENDING_DAY_COUNTERS'] as $name => $value)
321 $instance->addDayCounter($name, $value);
324 if (!empty($session[
'PENDING_ENTITY_ITEMS']) && is_array($session[
'PENDING_ENTITY_ITEMS']))
326 foreach ($session[
'PENDING_ENTITY_ITEMS'] as $i)
327 $instance->attachEntityItem($i[
'ENTITY'], $i[
'ITEM']);
338 $name =
'BITRIX_CONVERSION_CONTEXT_'.self::getSiteId();
347 static $siteId =
null;
349 if ($siteId ===
null)
353 if (defined(
'ADMIN_SECTION') && ADMIN_SECTION ===
true)
355 if ($row = SiteTable::getList(array(
356 'select' => array(
'LID'),
357 'order' => array(
'DEF' =>
'DESC',
'SORT' =>
'ASC'),
361 $siteId = $row[
'LID'];
static getSiteInstance($siteId)
static getEntityItemInstance($entity, $item)
addDayCounter($name, $value)
subDayCounter($day, $name, $value)
subCurrencyCounter($day, $name, $value, $currency)
attachEntityItem($entity, $item)
addCounter($day, $name, $value=null)
addCurrencyCounter($name, $value, $currency)
subCounter($day, $name, $value=1)
static convertToBaseCurrency($value, $currency)