- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/chat.php
- Класс: BitrixImOpenLinesChat
- Вызов: Chat::update
public function update($fields)
{
$result = false;
if($this->isDataLoaded())
{
foreach($fields as $field => $value)
{
if ($this->chat[$field] === $value)
{
unset($fields[$field]);
}
else
{
$this->chat[$field] = $value;
}
}
if (!empty($fields))
{
ChatTable::update($this->chat['ID'], $fields);
$relations = CIMChat::GetRelationById($this->chat['ID'], false, true, false);
foreach ($relations as $rel)
{
CIMContactList::CleanChatCache($rel['USER_ID']);
if (isset($fields['AUTHOR_ID']))
{
if ($rel['USER_ID'] == $this->chat['AUTHOR_ID'])
{
RelationTable::update($rel['ID'], Array('MANAGER' => 'N'));
}
if ($rel['USER_ID'] == $fields['AUTHOR_ID'])
{
RelationTable::update($rel['ID'], Array('MANAGER' => 'Y'));
}
}
}
if (array_key_exists('AUTHOR_ID', $fields))
{
//CRM
if(!empty($fields['AUTHOR_ID']) && !User::getInstance($fields['AUTHOR_ID'])->isBot())
{
$session = new Session();
$session->setChat($this);
$loadSession = $session->load(Array(
'USER_CODE' => $this->chat['ENTITY_ID']
));
if($loadSession)
{
$crmManager = new Crm($session);
$crmManager->setOperatorId($fields['AUTHOR_ID'], false);
}
}
//END CRM
$parsedUserCode = SessionCommon::parseUserCode($this->chat['ENTITY_ID']);
if (BitrixImOpenLinesConnector::isLiveChat($parsedUserCode['CONNECTOR_ID']))
{
$lineId = Queue::getActualLineId([
'LINE_ID' => $parsedUserCode['CONFIG_ID'],
'USER_CODE' => $this->chat['ENTITY_ID']
]);
PullEvent::add($parsedUserCode['CONNECTOR_USER_ID'], Array(
'module_id' => 'imopenlines',
'command' => 'sessionOperatorChange',
'params' => Array(
'chatId' => (int)$parsedUserCode['EXTERNAL_CHAT_ID'],
'operatorChatId' => (int)$this->chat['ID'],
'operator' => Rest::objectEncode(
Queue::getUserData($lineId, $fields['AUTHOR_ID'])
)
)
));
}
}
}
$result = true;
}
return $result;
}