...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_activity.php
- Класс: \CAllCrmActivity
- Вызов: CAllCrmActivity::AttachBinding
static function AttachBinding($srcOwnerTypeID, $srcOwnerID, $targOwnerTypeID, $targOwnerID) { $dbResult = \Bitrix\Main\Application::getConnection()->query( "SELECT a.ID, a.RESPONSIBLE_ID FROM b_crm_act a INNER JOIN b_crm_act_bind b ON a.ID = b.ACTIVITY_ID WHERE b.OWNER_TYPE_ID = {$srcOwnerTypeID} AND b.OWNER_ID = {$srcOwnerID}" ); $itemFields = array(); while($fields = $dbResult->fetch()) { $itemFields[] = $fields; } $processed = 0; $responsibleMap = array(); foreach($itemFields as $fields) { $itemID = (int)$fields['ID']; if($itemID <= 0) { continue; } $isBound = false; $bindings = self::GetBindings($itemID); $oldBindings = $bindings; foreach($bindings as $binding) { if($binding['OWNER_TYPE_ID'] == $targOwnerTypeID && $binding['OWNER_ID'] == $targOwnerID) { $isBound = true; break; } } if($isBound) { continue; } $bindings[] = array('OWNER_TYPE_ID' => $targOwnerTypeID, 'OWNER_ID' => $targOwnerID); self::SaveBindings($itemID, $bindings, false, false, false); $processed++; $responsibleID = isset($fields['RESPONSIBLE_ID']) ? (int)$fields['RESPONSIBLE_ID'] : 0; if($responsibleID > 0) { $responsibleMap[$responsibleID] = true; } \Bitrix\Crm\Counter\Monitor::getInstance()->onChangeActivityBindings( $itemID, $oldBindings, $bindings ); } if($processed === 0) { return; } $responsibleIDs = array_keys($responsibleMap); \Bitrix\Crm\Activity\UncompletedActivity::synchronizeForBindingsAndResponsibles( [ ['OWNER_TYPE_ID' => $targOwnerTypeID, 'OWNER_ID' => $targOwnerID] ], array_merge($responsibleIDs, [0]) ); if(!empty($responsibleIDs)) { foreach($responsibleIDs as $responsibleID) { self::SynchronizeUserActivity($targOwnerTypeID, $targOwnerID, $responsibleID); } } self::SynchronizeUserActivity($targOwnerTypeID, $targOwnerID, 0); \Bitrix\Crm\Activity\CommunicationStatistics::rebuild($targOwnerTypeID, array($targOwnerID)); }