• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/controller/ads/leadads/account.php
  • Класс: Bitrix\Crm\Controller\Ads\LeadAds\Account
  • Вызов: Account::getProfileListAction
public function getProfileListAction(string $type): AjaxJson
{
	$errorCollection = new ErrorCollection;

	if (!$service = $this->getService())
	{
		$errorCollection[] = new Error("Service not available.");

		return AjaxJson::createError($errorCollection);
	}

	if (!$service instanceof Retargeting\IMultiClientService || $service::canUseMultipleClients())
	{
		return $this->getProfileAction($type);
	}

	$service = $this->getService();
	$closure = static function(array $item) use ($type,$service) {
		/**@var $service Retargeting\IMultiClientService|Service*/
		if (!$service = clone $service)
		{
			return null;
		}

		$service->setClientId($item['proxy_client_id']);

		if (!$account = $service->getAccount($type))
		{
			return null;
		}

		$account->getRequest()->setAuthAdapter(
			$authAdapter = Retargeting\AuthAdapter::create($type,$service)
		);

		($profile = $account->getProfileCached()->getData())
			? $profile['CLIENT_ID'] = $item['proxy_client_id']
			: $authAdapter->removeAuth();

		return $profile?: null;
	};

	$profiles = array_filter(
		array_map($closure, $service::getAuthAdapter($type)->getClientList())
	);

	return AjaxJson::createSuccess(
		array(
			"profiles" => array_values($profiles)
		)
	);


}