- Модуль: conversion
- Путь к файлу: ~/bitrix/modules/conversion/lib/internals/basecontext.php
- Класс: BitrixConversionInternalsBaseContext
- Вызов: BaseContext::addCounter
public function addCounter($day, $name, $value = null)
{
if (!($day instanceof Date))
throw new ArgumentTypeException('day', 'BitrixMainTypeDate');
if (! is_string($name))
throw new ArgumentTypeException('name', 'string');
if (! is_numeric($value))
throw new ArgumentTypeException('value', 'numeric');
if (($id = $this->id) === null)
throw new SystemException('Cannot add counter without context!');
static $types;
if (! $types)
{
$types = CounterManager::getTypes();
}
if (! $type = $types[$name])
throw new SystemException("Undefined counter '$name' type!");
if (! $type['ACTIVE'])
return;
// save to database
$primary = array(
'DAY' => $day,
'CONTEXT_ID' => $id,
'NAME' => $name
);
$data = array('VALUE' => new DBSqlExpression('?# + ?f', 'VALUE', $value));
$result = ContextCounterDayTable::update($primary, $data);
if ($result->getAffectedRowsCount() === 0)
{
try
{
$result = ContextCounterDayTable::add($primary + array('VALUE' => $value));
}
catch (DBSqlQueryException $e)
{
$result = ContextCounterDayTable::update($primary, $data);
}
}
$result->isSuccess(); // TODO isSuccess
}