• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/integration/main/uiselector/entities.php
  • Класс: BitrixSocialnetworkIntegrationMainUISelectorEntities
  • Вызов: Entities::getData
static function getData($options = array())
{
	$result = array(
		'ITEMS' => array(),
		'ITEMS_LAST' => array(),
		'DEST_SORT' => array(),
		'ADDITIONAL_INFO' => array()
	);

	$filterParams = array(
		"DEST_CONTEXT" => $options["context"],
		"ALLOW_EMAIL_INVITATION" => (isset($options["allowEmailInvitation"]) && $options["allowEmailInvitation"] == "Y")
	);

	if (!empty($options['contextCode']))
	{
		$filterParams["CODE_TYPE"] = $options['contextCode'];
	}

	$dataAdditional = array();
	$destSortData = CSocNetLogDestination::getDestinationSort($filterParams, $dataAdditional);
	$result["DEST_SORT"] = $destSortData;
	$lastItems = $items = array();
	CSocNetLogDestination::fillLastDestination(
		$destSortData,
		$lastItems,
		array(
			"EMAILS" => (
				(
					isset($options["allowAddUser"])
					&& $options["allowAddUser"] == 'Y'
				)
				|| (
					isset($options["allowSearchEmailUsers"])
					&& $options["allowSearchEmailUsers"] == 'Y'
				)
				|| (
					isset($options["allowEmailInvitation"])
					&& $options["allowEmailInvitation"] == 'Y'
				)
					? 'Y'
					: 'N'
			),
			"DATA_ADDITIONAL" => $dataAdditional
		)
	);

	if (
		!Handler::isExtranetUser()
		&& BitrixSocialnetworkComponentHelper::getAllowToAllDestination()
		&& (!isset($options["enableAll"]) || $options["enableAll"] != 'N')
	)
	{
		$lastItems['GROUPS'] = array(
			'UA' => true
		);
		$items['GROUPS'] = array(
			'UA' => array(
				'id' => 'UA',
				'name' => (
					ModuleManager::isModuleInstalled('intranet')
						? Loc::getMessage("MPF_DESTINATION_3")
						: Loc::getMessage("MPF_DESTINATION_4")
				)
			)
		);
	}

	$result["ITEMS_LAST"] = $lastItems;

	if ($options["enableSonetgroups"] != 'N')
	{
		$limitReached = false;
		$sonetGroupsList = BitrixSocialnetworkComponentHelper::getSonetGroupAvailable(array(
			'limit' => 100
		), $limitReached);

		$result["SONETGROUPS_LIMITED"] = ($limitReached ? 'Y' : 'N');

		if(
			!empty($lastItems['SONETGROUPS'])
			&& !empty($sonetGroupsList)
		)
		{
			$lastSonetGroupsList = array();
			foreach ($lastItems['SONETGROUPS'] as $value)
			{
				if (!array_key_exists($value, $sonetGroupsList))
				{
					$lastSonetGroupsList[] = intval(mb_substr($value, 2));
				}
			}
			if (!empty($lastSonetGroupsList))
			{
				$sonetGroupsAdditionalList = CSocNetLogDestination::getSocnetGroup(array(
					'features' => array("blog", array("premoderate_post", "moderate_post", "write_post", "full_post")),
					'id' => $lastSonetGroupsList
				));
				if (!empty($sonetGroupsAdditionalList))
				{
					$sonetGroupsList = array_merge($sonetGroupsList, $sonetGroupsAdditionalList);
				}
			}
		}
		$items['SONETGROUPS'] = $sonetGroupsList;
	}

	if (Handler::isExtranetUser())
	{
		$result['EXTRANET_USER'] = 'Y';
		$items['USERS'] = CSocNetLogDestination::getExtranetUser();
	}
	else
	{
		$lastUserList = array();
		if(!empty($lastItems['USERS']))
		{
			foreach ($lastItems['USERS'] as $value)
			{
				$lastUserList[] = str_replace('U', '', $value);
			}
		}

		$result['EXTRANET_USER'] = 'N';
		if (!empty($lastUserList))
		{
			$items['USERS'] = CSocNetLogDestination::getUsers(array(
				'id' => $lastUserList,
				'CRM_ENTITY' => ModuleManager::isModuleInstalled('crm')
			));
			if (
				isset($options['extranetContext'])
				&& in_array($options['extranetContext'], array(self::EXTRANET_CONTEXT_INTERNAL, self::EXTRANET_CONTEXT_EXTERNAL))
			)
			{
				foreach($items['USERS'] as $key => $value)
				{
					if (isset($value["isExtranet"]))
					{
						if (
							(
								$value["isExtranet"] == 'Y'
								&& $options['extranetContext'] == self::EXTRANET_CONTEXT_INTERNAL
							)
							|| (
								$value["isExtranet"] == 'N'
								&& $options['extranetContext'] == self::EXTRANET_CONTEXT_EXTERNAL
							)
						)
						{
							unset($items['USERS'][$key]);
						}
					}
				}
			}
		}

		if (
			(
				isset($options["allowAddUser"])
				&& $options["allowAddUser"] == 'Y'
			)
			|| (
				isset($options["allowSearchEmailUsers"])
				&& $options["allowSearchEmailUsers"] == 'Y'
			)
			|| (
				isset($options["allowEmailInvitation"])
				&& $options["allowEmailInvitation"] == 'Y'
			)
		)
		{
			$items['LAST'] = $result["ITEMS_LAST"];
			CSocNetLogDestination::fillEmails($items);
			$result["ITEMS_LAST"] = $items['LAST'];
			unset($items['LAST']);
		}
	}

	if (
		$options["enableDepartments"] == "Y"
		&& ModuleManager::isModuleInstalled('intranet')
		&& !Handler::isExtranetUser()
	)
	{
		$structure = CSocNetLogDestination::getStucture(array("LAZY_LOAD" => true));
		$items['DEPARTMENT'] = $structure['department'];
		$items['DEPARTMENT_RELATION'] = $structure['department_relation'];
		$result['ADDITIONAL_INFO']['DEPARTMENT'] = array(
			'PREFIX' => 'DR',
			'TYPE' => 'tree'
		);
	}

	$result["ITEMS"] = $items;

	$lastItems = array();
	foreach($result["ITEMS_LAST"] as $group => $items)
	{
		$i = 0;
		foreach($result["ITEMS_LAST"][$group] as $key => $value)
		{
			$lastItems[$group][$key] = ++$i;
		}
	}
	$result["ITEMS_LAST"] = $lastItems;

	return $result;
}