- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/statistics/companyactivitystatusstatisticentry.php
- Класс: Bitrix\Crm\Statistics\CompanyActivityStatusStatisticEntry
- Вызов: CompanyActivityStatusStatisticEntry::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']) && is_array($options['VALUE']) ? $options['VALUE'] : null;
if(!$value)
throw new Main\ArgumentException('Options VALUE must be specified.', 'VALUE');
if(!is_array($entityFields))
{
$dbResult = \CCrmCompany::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;
$answered = isset($value[StatisticsStatus::Answered]) ? (int)$value[StatisticsStatus::Answered]: 0;
$unanswered = isset($value[StatisticsStatus::Unanswered]) ? (int)$value[StatisticsStatus::Unanswered] : 0;
if ($answered === 0 && $unanswered === 0)
{
CompanyActivityStatusStatisticsTable::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']
&& $answered === (int)$present['ANSWERED_QTY']
&& $unanswered === (int)$present['UNANSWERED_QTY']
)
return true;
if($responsibleID !== (int)$present['RESPONSIBLE_ID'])
{
CompanyActivityStatusStatisticsTable::synchronize(
$ownerID,
array('RESPONSIBLE_ID' => $responsibleID)
);
}
}
$data = array(
'OWNER_ID' => $ownerID,
'DEADLINE_DATE' => $date,
'PROVIDER_ID' => $providerId,
'PROVIDER_TYPE_ID' => $providerTypeId,
'RESPONSIBLE_ID' => $responsibleID,
'ANSWERED_QTY' => $answered,
'UNANSWERED_QTY' => $unanswered
);
CompanyActivityStatusStatisticsTable::upsert($data);
return true;
}