CallTracker::onAfterUpdate

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CallTracker
  4. onAfterUpdate
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/activity/provider/calltracker.php
  • Класс: Bitrix\Crm\Activity\Provider\CallTracker
  • Вызов: CallTracker::onAfterUpdate
static function onAfterUpdate(
	int $id,
	array $changedFields,
	array $oldActivityFields,
	array $newActivityFields,
	array $params = null
)
{
	// counter should be updated only if deadline, completed flag or responsible was changed
	// also we try to guess, was the activity counted in counter before or not

	$prevDeadline = $oldActivityFields['DEADLINE'] ?? null;
	$curDeadline = $newActivityFields['DEADLINE'] ?? null;
	$deadlineChanged = ($prevDeadline !== $curDeadline);
	$prevDeadline = $prevDeadline ? new \Bitrix\Main\Type\DateTime($prevDeadline) : null;
	$curDeadline = $curDeadline ? new \Bitrix\Main\Type\DateTime($curDeadline) : null;

	$prevCompleted = ($oldActivityFields['COMPLETED'] ?? '') == 'Y';
	$curCompleted = ($newActivityFields['COMPLETED'] ?? '')  == 'Y';
	$completedChanged = ($prevCompleted !== $curCompleted);

	$prevResponsibleId = (int)($oldActivityFields['RESPONSIBLE_ID'] ?? 0);
	$curResponsibleId = (int)($newActivityFields['RESPONSIBLE_ID'] ?? 0);
	$responsibleIdChanged = ($prevResponsibleId !== $curResponsibleId);

	if (!$completedChanged && !$deadlineChanged && !$responsibleIdChanged)
	{
		// nothing important was changed
		return;
	}

	$wasCounterUpdatedEarlier = self::needUpdateCounter($prevCompleted, $prevDeadline);
	$needUpdateCounterNow = self::needUpdateCounter($curCompleted, $curDeadline);

	$needIncrease =
		($completedChanged || $deadlineChanged)
		&& !$wasCounterUpdatedEarlier
		&& $needUpdateCounterNow
	;

	$needDecrease =
		($completedChanged || $deadlineChanged)
		&& $wasCounterUpdatedEarlier
		&& !$needUpdateCounterNow
	;

	if ($responsibleIdChanged)
	{
		$needIncrease = false;
		$needDecrease = $wasCounterUpdatedEarlier;
	}

	if ($curResponsibleId > 0)
	{
		$counter = \Bitrix\Crm\Counter\EntityCounterFactory::createCallTrackerCounter($curResponsibleId);
		if ($needIncrease)
		{
			$counter->increase();
		}
		if ($needDecrease)
		{
			$counter->decrease();
		}
	}
	if ($responsibleIdChanged && $prevResponsibleId > 0 && $needUpdateCounterNow)
	{
		$prevUserCounter = \Bitrix\Crm\Counter\EntityCounterFactory::createCallTrackerCounter($prevResponsibleId);
		$prevUserCounter->increase();
	}
}

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