- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/lib/command.php
- Класс: BitrixImCommand
- Вызов: Command::getListCache
static function getListCache($lang = LANGUAGE_ID)
{
$cache = BitrixMainDataCache::createInstance();
if($cache->initCache(self::CACHE_TTL, 'list_v5_'.$lang, self::CACHE_PATH))
{
$result = $cache->getVars();
}
else
{
$loadRestLang = false;
$result = Array();
$orm = BitrixImModelCommandTable::getList();
while ($row = $orm->fetch())
{
$row['COMMAND_ID'] = $row['ID'];
$row['CONTEXT'] = '';
if ($row['BOT_ID'] > 0)
{
$row['CATEGORY'] = BitrixImUser::getInstance($row['BOT_ID'])->getFullName();
}
else if ($row['MODULE_ID'] == 'im')
{
$row['CATEGORY'] = Loc::getMessage('COMMAND_IM_CATEGORY');
}
else
{
$moduleClass = new CModule();
$module = $moduleClass->createModuleObject($row['MODULE_ID']);
$row['CATEGORY'] = $module->MODULE_NAME;
}
if (!empty($row['CLASS']) && !empty($row['METHOD_LANG_GET']))
{
if (BitrixMainLoader::includeModule($row['MODULE_ID']) && class_exists($row["CLASS"]) && method_exists($row["CLASS"], $row["METHOD_LANG_GET"]))
{
$localize = call_user_func_array(array($row["CLASS"], $row["METHOD_LANG_GET"]), Array($row['COMMAND'], $lang));
if ($localize)
{
$row['TITLE'] = $localize['TITLE'];
$row['PARAMS'] = $localize['PARAMS'];
}
else
{
$row['HIDDEN'] = 'Y';
$row['METHOD_LANG_GET'] = '';
}
}
else
{
$row['HIDDEN'] = 'Y';
$row['METHOD_LANG_GET'] = '';
}
}
else
{
$row['TITLE'] = '';
$row['PARAMS'] = '';
if ($row['MODULE_ID'] == 'rest')
{
$loadRestLang = true;
if ($row['BOT_ID'] <= 0 && $row['APP_ID'])
{
$res = BitrixRestAppTable::getList([
'filter' => array('=CLIENT_ID' => $row['APP_ID']),
]);
if ($app = $res->fetch())
{
$row['CATEGORY'] = !empty($app['APP_NAME'])
? $app['APP_NAME']
: (!empty($app['APP_NAME_DEFAULT'])
? $app['APP_NAME_DEFAULT']
: $app['CODE']
)
;
}
}
}
}
$result[$row['COMMAND_ID']] = $row;
}
if ($loadRestLang)
{
$langSet = Array();
$orm = BitrixImModelCommandLangTable::getList();
while ($row = $orm->fetch())
{
if (!isset($result[$row['COMMAND_ID']]))
continue;
$langSet[$row['COMMAND_ID']][$row['LANGUAGE_ID']]['TITLE'] = $row['TITLE'];
$langSet[$row['COMMAND_ID']][$row['LANGUAGE_ID']]['PARAMS'] = $row['PARAMS'];
}
$langAlter = BitrixImBot::getDefaultLanguage();
foreach ($result as $commandId => $commandData)
{
if (isset($langSet[$commandId][$lang]))
{
$result[$commandId]['TITLE'] = $langSet[$commandId][$lang]['TITLE'];
$result[$commandId]['PARAMS'] = $langSet[$commandId][$lang]['PARAMS'];
}
else if (isset($langSet[$commandId][$langAlter]))
{
$result[$commandId]['TITLE'] = $langSet[$commandId][$langAlter]['TITLE'];
$result[$commandId]['PARAMS'] = $langSet[$commandId][$langAlter]['PARAMS'];
}
else if (isset($langSet[$commandId]))
{
$langSetCommand = array_values($langSet[$commandId]);
$result[$commandId]['TITLE'] = $langSetCommand[0]['TITLE'];
$result[$commandId]['PARAMS'] = $langSetCommand[0]['PARAMS'];
}
}
foreach ($result as $key => $value)
{
if (empty($value['TITLE']))
{
$result[$key]['HIDDEN'] = 'Y';
$row['METHOD_LANG_GET'] = '';
}
}
}
if (!empty($result))
{
BitrixMainTypeCollection::sortByColumn(
$result,
Array('MODULE_ID' => SORT_ASC),
'',
null,
true
);
}
$result = self::mergeWithDefaultCommands($result);
$cache->startDataCache();
$cache->endDataCache($result);
}
return $result;
}