• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/mysql/sonet_relation.php
  • Класс: \CCrmSonetRelation
  • Вызов: CCrmSonetRelation::Replace
public function Replace($entityTypeID, $entityID, $currentParent, $previousParent, $options = array())
{
	if(!CCrmOwnerType::IsDefined($entityTypeID))
	{
		return false;
	}

	$entityID = intval($entityID);
	if($entityID <= 0)
	{
		return false;
	}

	if(!is_array($currentParent) || !is_array($previousParent))
	{
		return false;
	}

	if(!is_array($options))
	{
		$options = array();
	}

	$entityTypeIDKey = isset($options['ENTITY_TYPE_ID_KEY']) ? $options['ENTITY_TYPE_ID_KEY'] : '';
	if($entityTypeIDKey === '')
	{
		$entityTypeIDKey = 'ENTITY_TYPE_ID';
	}

	$entityIDKey = isset($options['ENTITY_ID_KEY']) ? $options['ENTITY_ID_KEY'] : '';
	if($entityIDKey === '')
	{
		$entityIDKey = 'ENTITY_ID';
	}

	$currentParentEntityTypeID = isset($currentParent[$entityTypeIDKey]) ? intval($currentParent[$entityTypeIDKey]) : CCrmOwnerType::Undefined;
	$currentParentEntityID = isset($currentParent[$entityIDKey]) ? intval($currentParent[$entityIDKey]) : 0;

	$previousParentEntityTypeID = isset($previousParent[$entityTypeIDKey]) ? intval($previousParent[$entityTypeIDKey]) : CCrmOwnerType::Undefined;
	$previousParentEntityID = isset($previousParent[$entityIDKey]) ? intval($previousParent[$entityIDKey]) : 0;

	if(!CCrmOwnerType::IsDefined($currentParentEntityTypeID) || !CCrmOwnerType::IsDefined($previousParentEntityTypeID))
	{
		return false;
	}

	global $DB;
	$tableName = self::TABLE_NAME;

	$slEntityType = $DB->ForSql(CCrmLiveFeedEntity::GetByEntityTypeID($entityTypeID));
	$currentSlParentEntityType = $DB->ForSql(CCrmLiveFeedEntity::GetByEntityTypeID($currentParentEntityTypeID));
	$previousSlParentEntityType = $DB->ForSql(CCrmLiveFeedEntity::GetByEntityTypeID($previousParentEntityTypeID));

	$updateSql = "UPDATE {$tableName} SET SL_PARENT_ENTITY_TYPE = '{$currentSlParentEntityType}', PARENT_ENTITY_ID = {$currentParentEntityID}
		WHERE SL_ENTITY_TYPE = '{$slEntityType}' AND ENTITY_ID = {$entityID} AND SL_PARENT_ENTITY_TYPE = '{$previousSlParentEntityType}'AND PARENT_ENTITY_ID = {$previousParentEntityID}";
	$dbResult = $DB->Query($updateSql, false, 'File: '.__FILE__.'
Line: '.__LINE__); return is_object($dbResult) && $dbResult->AffectedRowsCount() > 0; }