CAllCrmActivity::ChangeCalendarEventOwner

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmActivity
  4. ChangeCalendarEventOwner
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_activity.php
  • Класс: \CAllCrmActivity
  • Вызов: CAllCrmActivity::ChangeCalendarEventOwner
static function ChangeCalendarEventOwner($oldOwnerTypeID, $oldOwnerID, $newOwnerTypeID, $newOwnerID)
{
	if(!(IsModuleInstalled('calendar') && CModule::IncludeModule('calendar')))
	{
		return;
	}

	$oldSlug = Crm\UserField\Types\ElementType::getValueByIdentifier(new Crm\ItemIdentifier(
		$oldOwnerTypeID,
		$oldOwnerID
	));
	$events = CCalendarEvent::GetList(
		array(
			'arFilter' => array(
				'=UF_CRM_CAL_EVENT' => $oldSlug,
				'=DELETED' => 'N'
			),
			'arSelect' => array('ID'),
			'getUserfields' => true,
			'checkPermissions' => false
		)
	);

	if(!is_array($events))
	{
		return;
	}

	$newSlug = Crm\UserField\Types\ElementType::getValueByIdentifier(new Crm\ItemIdentifier(
		$newOwnerTypeID,
		$newOwnerID
	));
	foreach($events as $event)
	{
		if(!(isset($event['UF_CRM_CAL_EVENT']) && is_array($event['UF_CRM_CAL_EVENT'])))
		{
			continue;
		}

		for($i = 0, $length = count($event['UF_CRM_CAL_EVENT']); $i < $length; $i++)
		{
			if($event['UF_CRM_CAL_EVENT'][$i] !== $oldSlug)
			{
				continue;
			}

			$event['UF_CRM_CAL_EVENT'][$i] = $newSlug;
			CCalendarEvent::UpdateUserFields(
				$event['ID'],
				array('UF_CRM_CAL_EVENT' => $event['UF_CRM_CAL_EVENT'])
			);
			break;
		}
	}
}

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