CAllCrmActivity::CreateFromDealEvent

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmActivity
  4. CreateFromDealEvent
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_activity.php
  • Класс: \CAllCrmActivity
  • Вызов: CAllCrmActivity::CreateFromDealEvent
static function CreateFromDealEvent(&$arDeal)
{
	$dealID = intval($arDeal['ID']);
	$originID = "DEAL_EVENT_{$dealID}";
	if(self::GetByOriginID($originID) !== false)
	{
		return false; //Already exists
	}

	$now = time() + CTimeZone::GetOffset();
	$typeID = $arDeal['EVENT_ID'] === 'PHONE' ? CCrmActivityType::Call : CCrmActivityType::Activity;
	$subject = GetMessage($typeID === CCrmActivityType::Call ? 'CRM_ACTIVITY_FROM_DEAL_EVENT_CALL' : 'CRM_ACTIVITY_FROM_DEAL_EVENT_INFO');

	$date = $now;
	if(isset($arDeal['EVENT_DATE']))
	{
		$date = MakeTimeStamp($arDeal['EVENT_DATE']);
	}
	elseif(isset($arDeal['DATE_MODIFY']))
	{
		$date = MakeTimeStamp($arDeal['DATE_MODIFY']);
	}
	elseif(isset($arDeal['DATE_CREATE']))
	{
		$date = MakeTimeStamp($arDeal['DATE_CREATE']);
	}

	$dateFmt = ConvertTimeStamp($date, 'FULL', SITE_ID);

	$responsibleID = 0;
	if(isset($arDeal['ASSIGNED_BY_ID']))
	{
		$responsibleID = intval($arDeal['ASSIGNED_BY_ID']);
	}
	elseif(isset($arDeal['MODIFY_BY_ID']))
	{
		$responsibleID = intval($arDeal['MODIFY_BY_ID']);
	}
	elseif(isset($arDeal['CREATED_BY_ID']))
	{
		$responsibleID = intval($arDeal['CREATED_BY_ID']);
	}

	$arFields = array(
		'TYPE_ID' => $typeID,
		'OWNER_TYPE_ID' => CCrmOwnerType::Deal,
		'OWNER_ID' => $dealID,
		'SUBJECT' => $subject,
		'START_TIME' => $dateFmt,
		'END_TIME' => $dateFmt,
		'COMPLETED' => ($date <= $now) ? 'Y' : 'N',
		'RESPONSIBLE_ID' => $responsibleID,
		'PRIORITY' => CCrmActivityPriority::Medium,
		'DESCRIPTION' => isset($arDeal['EVENT_DESCRIPTION']) ? $arDeal['EVENT_DESCRIPTION'] : '',
		'LOCATION' => '',
		'DIRECTION' => $typeID === CCrmActivityType::Call ? CCrmActivityDirection::Outgoing : CCrmActivityDirection::Undefined,
		'NOTIFY_TYPE' => CCrmActivityNotifyType::None,
		'BINDINGS' => array(
			array(
				'OWNER_TYPE_ID' => CCrmOwnerType::Deal,
				'OWNER_ID' => $arDeal['ID']
			)
		),
		'ORIGIN_ID' => $originID,
		'SETTINGS' => array()
	);

	return self::Add($arFields, false, false);
}

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