- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/livechatmanager.php
- Класс: BitrixImOpenLinesLiveChatManager
- Вызов: LiveChatManager::update
public function update($fields, $options = [])
{
$prevConfig = $this->get();
$update = Array();
if (isset($fields['URL_CODE_PUBLIC']))
{
$fields['URL_CODE_PUBLIC'] = trim($fields['URL_CODE_PUBLIC']);
if (empty($fields['URL_CODE_PUBLIC']))
{
if ($prevConfig['URL_CODE_PUBLIC_ID'] > 0)
{
BitrixImAlias::delete($prevConfig['URL_CODE_PUBLIC_ID']);
}
$update['URL_CODE_PUBLIC'] = '';
$update['URL_CODE_PUBLIC_ID'] = 0;
}
else
{
$fields['URL_CODE_PUBLIC'] = self::prepareAlias($fields['URL_CODE_PUBLIC']);
if ($prevConfig['URL_CODE_PUBLIC_ID'] > 0)
{
if ($prevConfig['URL_CODE_PUBLIC'] != $fields['URL_CODE_PUBLIC'])
{
$result = BitrixImAlias::update($prevConfig['URL_CODE_PUBLIC_ID'], Array('ALIAS' => $fields['URL_CODE_PUBLIC']));
if ($result)
{
$update['URL_CODE_PUBLIC'] = $fields['URL_CODE_PUBLIC'];
}
}
}
else
{
$fields['URL_CODE_PUBLIC_ID'] = BitrixImAlias::add(Array(
'ALIAS' => $fields['URL_CODE_PUBLIC'],
'ENTITY_TYPE' => BitrixImAlias::ENTITY_TYPE_LIVECHAT,
'ENTITY_ID' => $this->id
));
if ($fields['URL_CODE_PUBLIC_ID'])
{
$update['URL_CODE_PUBLIC'] = $fields['URL_CODE_PUBLIC'];
$update['URL_CODE_PUBLIC_ID'] = $fields['URL_CODE_PUBLIC_ID'];
}
}
}
}
if (isset($fields['TEMPLATE_ID']) && in_array($fields['TEMPLATE_ID'], Array(self::TEMPLATE_COLOR, self::TEMPLATE_COLORLESS)))
{
$update['TEMPLATE_ID'] = $fields['TEMPLATE_ID'];
}
if (isset($fields['CSS_ACTIVE']))
{
$update['CSS_ACTIVE'] = $fields['CSS_ACTIVE'] == 'Y'? 'Y': 'N';
}
if (isset($fields['BACKGROUND_IMAGE']))
{
$update['BACKGROUND_IMAGE'] = intval($fields['BACKGROUND_IMAGE']);
}
if (isset($fields['CSS_PATH']))
{
$update['CSS_PATH'] = mb_substr($fields['CSS_PATH'], 0, 255);
}
if (isset($fields['CSS_TEXT']))
{
$update['CSS_TEXT'] = $fields['CSS_TEXT'];
}
if (isset($fields['COPYRIGHT_REMOVED']) && Limit::canRemoveCopyright())
{
$update['COPYRIGHT_REMOVED'] = $fields['COPYRIGHT_REMOVED'] == 'Y'? 'Y': 'N';
}
if (isset($fields['SHOW_SESSION_ID']))
{
$update['SHOW_SESSION_ID'] = $fields['SHOW_SESSION_ID'] === 'Y'? 'Y': 'N';
}
if (isset($fields['CACHE_WIDGET_ID']))
{
$update['CACHE_WIDGET_ID'] = intval($fields['CACHE_WIDGET_ID']);
}
if (isset($fields['CACHE_BUTTON_ID']))
{
$update['CACHE_BUTTON_ID'] = intval($fields['CACHE_BUTTON_ID']);
}
if (isset($fields['PHONE_CODE']))
{
$update['PHONE_CODE'] = $fields['PHONE_CODE'];
}
if (isset($fields['TEXT_PHRASES']))
{
$update['TEXT_PHRASES'] = $fields['TEXT_PHRASES'];
}
$result = ModelLivechatTable::update($this->id, $update);
if ($result->isSuccess())
{
if ($this->config)
{
foreach ($update as $key => $value)
{
$this->config[$key] = $value;
}
}
if (isset($options['CLEAN_CACHE_CONNECTOR']) && BitrixMainLoader::includeModule('imconnector'))
{
BitrixImConnectorConnector::cleanCacheConnector(
$this->id,
BitrixImConnectorConnector::getCacheIdConnector($this->id, 'livechat')
);
}
}
return $result->isSuccess();
}