• Модуль: imopenlines
  • Путь к файлу: ~/bitrix/modules/imopenlines/lib/session.php
  • Класс: BitrixImOpenLinesSession
  • Вызов: Session::answer
public function answer($userId): void
{
	$this->setOperatorId($userId, false, false);

	if ($this->getData('CRM_ACTIVITY_ID') > 0)
	{
		$closeDate = new MainTypeDateTime();
		$closeDate->add((int)$this->getConfig('AUTO_CLOSE_TIME').' SECONDS');
		$closeDate->add('1 DAY');

		$crmManager = new Crm($this);
		if ($crmManager->isLoaded())
		{
			$crmManager->setSessionAnswered(['DATE_CLOSE' => $closeDate]);
			$crmManager->executeAutomationAnswerControlTrigger($this);
			$crmManager->executeAutomationAnswerTrigger($this);

			if (
				$this->getData('STATUS') <= self::STATUS_ANSWER
				&& $this->getConfig('IGNORE_WELCOME_FORM_RESPONSIBLE') === 'Y'
				&& $this->getData('CRM') === 'Y'
			)
			{
				$crmEntitiesManager = BitrixImOpenLinesCrmCommon::getActivityBindings($this->getData('CRM_ACTIVITY_ID'));
				if($crmEntitiesManager->isSuccess())
				{
					$entities = $crmEntitiesManager->getData();
					if (isset($entities[Crm::ENTITY_CONTACT]) && $entities[Crm::ENTITY_CONTACT] > 0)
					{
						$entity = new CCrmContact(false);
						$data = ['ASSIGNED_BY_ID' => $crmManager->getResponsibleCrmId()];
						$entity->Update($entities[Crm::ENTITY_CONTACT], $data);
					}
					if (isset($entities[Crm::ENTITY_LEAD]) && $entities[Crm::ENTITY_LEAD] > 0)
					{
						$entity = new CCrmLead(false);
						$data = ['ASSIGNED_BY_ID' => $crmManager->getResponsibleCrmId()];
						$entity->Update($entities[Crm::ENTITY_LEAD], $data);
					}
				}
			}
		}
	}

	$sessionUpdate = [
		'OPERATOR_ID' => $userId,
		'WAIT_ACTION' => 'N',
		'WAIT_ANSWER' => 'N',
		'SEND_NO_ANSWER_TEXT' => 'Y'
	];
	if (
		$this->getData('DATE_OPERATOR_ANSWER') <= 0 &&
		!User::getInstance($userId)->isBot()
	)
	{
		$currentDate = new DateTime();
		$sessionUpdate['DATE_OPERATOR_ANSWER'] = $currentDate;

		$dateCreate = $this->getData('DATE_CREATE');
		if (
			!empty($dateCreate) &&
			$dateCreate instanceof DateTime
		)
		{
			$sessionUpdate['TIME_ANSWER'] = $currentDate->getTimestamp()-$dateCreate->getTimestamp();
		}
	}

	$this->update($sessionUpdate);
}