• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/timeline/orderpaymentcontroller.php
  • Класс: Bitrix\Crm\Timeline\OrderPaymentController
  • Вызов: OrderPaymentController::onCreate
public function onCreate($ownerID, array $params)
{
	if (!is_int($ownerID))
	{
		$ownerID = (int)$ownerID;
	}
	if ($ownerID <= 0)
	{
		throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID');
	}

	$fields = isset($params['FIELDS']) && is_array($params['FIELDS']) ? $params['FIELDS'] : null;
	if (!is_array($fields))
	{
		$fields = self::getEntity($ownerID);
	}
	if (!is_array($fields))
	{
		return;
	}

	$settingFields = [
		'SUM' => $fields['SUM'],
		'CURRENCY' => $fields['CURRENCY']
	];

	if ($fields['DATE_BILL'] instanceof Main\Type\Date)
	{
		$settingFields['DATE_BILL_TIMESTAMP'] = $fields['DATE_BILL']->getTimestamp();
	}

	$settings = ['FIELDS' => $settingFields];

	$orderId = (isset($fields['ORDER_ID']) && (int)$fields['ORDER_ID'] > 0) ? (int)$fields['ORDER_ID'] : 0;
	if ($orderId > 0)
	{
		$settings['BASE'] = [
			'ENTITY_TYPE_ID' => \CCrmOwnerType::Order,
			'ENTITY_ID' => (int)$fields['ORDER_ID'],
		];
	}

	$authorID = self::resolveCreatorID($fields);
	$bindings = [
		[
			'ENTITY_TYPE_ID' => \CCrmOwnerType::OrderPayment,
			'ENTITY_ID' => $ownerID,
		]
	];

	if ($orderId > 0)
	{
		$bindings[] = array(
			'ENTITY_TYPE_ID' => \CCrmOwnerType::Order,
			'ENTITY_ID' => $orderId
		);
	}

	$timelineEntryId = CreationEntry::create([
		'ENTITY_TYPE_ID' => \CCrmOwnerType::OrderPayment,
		'ENTITY_ID' => $ownerID,
		'AUTHOR_ID' => $authorID,
		'SETTINGS' => $settings,
		'BINDINGS' => $bindings,
	]);

	$enableHistoryPush = $timelineEntryId > 0;
	if ($enableHistoryPush && Main\Loader::includeModule('pull'))
	{
		$pushParams = array();
		if ($enableHistoryPush)
		{
			$historyFields = TimelineEntry::getByID($timelineEntryId);
			if(is_array($historyFields))
			{
				$pushParams['HISTORY_ITEM'] = $this->prepareHistoryDataModel(
					$historyFields,
					array('ENABLE_USER_INFO' => true)
				);
			}
		}

		$tag = $pushParams['TAG'] = TimelineEntry::prepareEntityPushTag(\CCrmOwnerType::OrderPayment, $ownerID);
		\CPullWatch::AddToStack(
			$tag,
			array(
				'module_id' => 'crm',
				'command' => 'timeline_order_payment_add',
				'params' => $pushParams,
			)
		);
	}
}