- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/statistics/contactactivitystatisticentry.php
- Класс: Bitrix\Crm\Statistics\ContactActivityStatisticEntry
- Вызов: ContactActivityStatisticEntry::register
static function register($ownerID, array $entityFields = null, array $options = null)
{
if(!is_int($ownerID))
$ownerID = (int)$ownerID;
if($ownerID <= 0)
throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID');
if(!is_array($options))
$options = array();
$date = isset($options['DATE']) ? $options['DATE'] : null;
if(!$date)
throw new Main\ArgumentException('Options DATE must be specified.', 'DATE');
$providerId = isset($options['PROVIDER_ID']) ? $options['PROVIDER_ID'] : null;
if(!$providerId)
throw new Main\ArgumentException('Options PROVIDER_ID must be specified.', 'PROVIDER_ID');
$providerTypeId = isset($options['PROVIDER_TYPE_ID']) ? $options['PROVIDER_TYPE_ID'] : null;
if(!$providerTypeId)
throw new Main\ArgumentException('Options PROVIDER_TYPE_ID must be specified.', 'PROVIDER_TYPE_ID');
$value = isset($options['VALUE']) ? $options['VALUE'] : null;
if($value === null)
throw new Main\ArgumentException('Options VALUE must be specified.', 'VALUE');
if(!is_array($entityFields))
{
$dbResult = \CCrmContact::GetListEx(
array(),
array('=ID' => $ownerID, 'CHECK_PERMISSIONS' => 'N'),
false,
false,
array('ASSIGNED_BY_ID')
);
$entityFields = is_object($dbResult) ? $dbResult->Fetch() : null;
if(!is_array($entityFields))
{
return false;
}
}
$responsibleID = isset($entityFields['ASSIGNED_BY_ID']) ? (int)$entityFields['ASSIGNED_BY_ID'] : 0;
$value = (int)$value;
if ($value === 0)
{
ContactActivityStatisticsTable::delete(array(
'OWNER_ID' => $ownerID,
'DEADLINE_DATE' => $date,
'PROVIDER_ID' => $providerId,
'PROVIDER_TYPE_ID' => $providerTypeId
));
return true;
}
$present = self::get($ownerID, $date, $providerId, $providerTypeId);
if(is_array($present))
{
if($responsibleID === (int)$present['RESPONSIBLE_ID'] && $value === (int)$present['TOTAL_QTY'])
return true;
if($responsibleID !== (int)$present['RESPONSIBLE_ID'])
{
ContactActivityStatisticsTable::synchronize(
$ownerID,
array('RESPONSIBLE_ID' => $responsibleID)
);
}
}
$data = array(
'OWNER_ID' => $ownerID,
'DEADLINE_DATE' => $date,
'PROVIDER_ID' => $providerId,
'PROVIDER_TYPE_ID' => $providerTypeId,
'RESPONSIBLE_ID' => $responsibleID,
'TOTAL_QTY' => $value
);
ContactActivityStatisticsTable::upsert($data);
return true;
}