CallTracker::onAfterAdd

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CallTracker
  4. onAfterAdd
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/activity/provider/calltracker.php
  • Класс: Bitrix\Crm\Activity\Provider\CallTracker
  • Вызов: CallTracker::onAfterAdd
static function onAfterAdd($activityFields, array $params = null)
{
	if(!is_array($params))
	{
		$params = [];
	}
	if(isset($params['IS_RESTORATION']) && $params['IS_RESTORATION'])
	{
		return;
	}

	$userId = isset($activityFields['RESPONSIBLE_ID']) ? (int)$activityFields['RESPONSIBLE_ID'] : 0;
	$deadline = isset($activityFields['DEADLINE']) ? new \Bitrix\Main\Type\DateTime($activityFields['DEADLINE']) : null;
	$completed = isset($activityFields['COMPLETED']) && $activityFields['COMPLETED'] === 'Y';
	$bindings = (isset($activityFields['BINDINGS']) && is_array($activityFields['BINDINGS']))
		? $activityFields['BINDINGS']
		: [];

	$isBoundToDeal = array_reduce(
		$bindings,
		function ($wasBound, $binding)
		{
			return $wasBound || ($binding['OWNER_TYPE_ID'] === \CCrmOwnerType::Deal);
		},
		false
	);

	if ($isBoundToDeal && self::needUpdateCounter($completed, $deadline))
	{
		$counter = \Bitrix\Crm\Counter\EntityCounterFactory::createCallTrackerCounter($userId);
		$counter->increase();
	}
}

Добавить комментарий