• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/integration/ui/entityselector/botprovider.php
  • Класс: BitrixImIntegrationUIEntitySelectorBotProvider
  • Вызов: BotProvider::fillDialog
public function fillDialog(Dialog $dialog): void
{
	if (!$this->shouldFillDialog())
	{
		return;
	}

	if (!$this->getOption('fillDialogWithDefaultValues', true))
	{
		$recentBots = new EO_User_Collection();
		$recentItems = $dialog->getRecentItems()->getEntityItems('im-bot');
		$recentIds = array_map('intval', array_keys($recentItems));
		$this->fillRecentBots($recentBots, $recentIds, new EO_User_Collection());

		$dialog->addRecentItems($this->makeBotItems($recentBots));

		return;
	}

	$maxBotsInRecentTab = 50;

	// Preload first 50 users ('doSearch' method has to have the same filter).
	$preloadedBots = $this->getBotCollection([
		'order' => ['ID' => 'DESC'],
		'limit' => $maxBotsInRecentTab
	]);

	if (count($preloadedBots) < $maxBotsInRecentTab)
	{
		// Turn off the user search
		$entity = $dialog->getEntity('im-bot');
		if ($entity)
		{
			$entity->setDynamicSearch(false);
		}
	}

	$recentBots = new EO_User_Collection();

	// Recent Items
	$recentItems = $dialog->getRecentItems()->getEntityItems('im-bot');
	$recentIds = array_map('intval', array_keys($recentItems));
	$this->fillRecentBots($recentBots, $recentIds, $preloadedBots);

	// Global Recent Items
	if (count($recentBots) < $maxBotsInRecentTab)
	{
		$recentGlobalItems = $dialog->getGlobalRecentItems()->getEntityItems('im-bot');
		$recentGlobalIds = [];

		if (!empty($recentGlobalItems))
		{
			$recentGlobalIds = array_map('intval', array_keys($recentGlobalItems));
			$recentGlobalIds = array_values(array_diff($recentGlobalIds, $recentBots->getIdList()));
			$recentGlobalIds = array_slice($recentGlobalIds, 0, $maxBotsInRecentTab - $recentBots->count());
		}

		$this->fillRecentBots($recentBots, $recentGlobalIds, $preloadedBots);
	}

	// The rest of preloaded users
	foreach ($preloadedBots as $preloadedBot)
	{
		$recentBots->add($preloadedBot);
	}

	$dialog->addRecentItems($this->makeBotItems($recentBots));
}