- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/history/leadstatushistoryentry.php
- Класс: Bitrix\Crm\History\LeadStatusHistoryEntry
- Вызов: LeadStatusHistoryEntry::synchronize
static function synchronize($ownerID, array $entityFields = null)
{
if(!is_int($ownerID))
{
$ownerID = (int)$ownerID;
}
if($ownerID <= 0)
{
throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID');
}
$query = new Query(LeadStatusHistoryTable::getEntity());
$query->addSelect('RESPONSIBLE_ID');
$query->addFilter('=OWNER_ID', $ownerID);
$query->setLimit(1);
$dbResult = $query->exec();
$first = $dbResult->fetch();
if(!is_array($first))
{
return false;
}
if(!is_array($entityFields))
{
$dbResult = \CCrmLead::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;
if($responsibleID === (int)$first['RESPONSIBLE_ID'])
{
return false;
}
LeadStatusHistoryTable::synchronize($ownerID, array('RESPONSIBLE_ID' => $responsibleID));
return true;
}