CBPHelper::extractUsersFromExtendedGroup

  1. Bitrix24 API (v. 23.675.0)
  2. bizproc
  3. CBPHelper
  4. extractUsersFromExtendedGroup
  • Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/classes/general/helper.php
  • Класс: CBPHelper
  • Вызов: CBPHelper::extractUsersFromExtendedGroup
static function extractUsersFromExtendedGroup($code)
{
	if (mb_strpos($code, 'group_') !== 0)
	{
		return false;
	}
	$code = mb_strtoupper(mb_substr($code, mb_strlen('group_')));

	if (mb_strpos($code, 'G') === 0)
	{
		$group = (int)mb_substr($code, 1);
		if ($group <= 0)
		{
			return [];
		}
		$result = [];

		$iterator = CUser::GetList(
			"ID",
			"ASC",
			[
				"GROUPS_ID" => $group,
				"ACTIVE" => "Y",
			],
			['FIELDS' => ['ID']]
		);
		while ($user = $iterator->fetch())
		{
			$result[] = $user['ID'];
		}

		return $result;
	}

	if (preg_match('/^(U|IU|SU)([0-9]+)$/i', $code, $match))
	{
		return array($match[2]);
	}

	if ($code == 'UA' && CModule::IncludeModule('intranet'))
	{
		$result = [];
		$iterator = CUser::GetList("id", "asc",
			array('ACTIVE' => 'Y', '>UF_DEPARTMENT' => 0),
			array('FIELDS' => array('ID'))
		);
		while($user = $iterator->fetch())
		{
			$result[] = $user['ID'];
		}
		return $result;
	}

	if (preg_match('/^(D|DR)([0-9]+)$/', $code, $match) && CModule::IncludeModule('intranet'))
	{
		$recursive = $match[1] == 'DR';
		$id = $match[2];
		$iblockId = COption::GetOptionInt('intranet', 'iblock_structure');
		$departmentIds = array($id);

		if ($recursive)
		{
			//TODO: replace with CIntranetUtils::getSubStructure($id)
			$iterator = CIBlockSection::GetList(
				array('ID' => 'ASC'),
				array('=IBLOCK_ID' => $iblockId, 'ID'=> $id),
				false,
				array('ID', 'LEFT_MARGIN', 'RIGHT_MARGIN', 'DEPTH_LEVEL')
			);
			$section = $iterator->fetch();
			$filter = array (
				'=IBLOCK_ID' => $iblockId,
				">LEFT_MARGIN" => $section["LEFT_MARGIN"],
				" $section["RIGHT_MARGIN"],
				">DEPTH_LEVEL" => $section['DEPTH_LEVEL'],
			);
			$iterator = CIBlockSection::GetList(array("left_margin"=>"asc"), $filter, false, array('ID'));
			while($section = $iterator->fetch())
			{
				$departmentIds[] =  $section['ID'];
			}
			unset($iterator, $section, $filter);
		}
		$result = array();
		$iterator = CUser::GetList("id", "asc",
			array('ACTIVE' => 'Y', 'UF_DEPARTMENT' => $departmentIds),
			array('FIELDS' => array('ID'))
		);
		while($user = $iterator->fetch())
		{
			$result[] = $user['ID'];
		}
		return $result;
	}
	if ($code == 'Dextranet' && CModule::IncludeModule('extranet'))
	{
		$result = array();
		$iterator = CUser::GetList("id", "asc",
			array(COption::GetOptionString("extranet", "extranet_public_uf_code", "UF_PUBLIC") => "1",
				"!UF_DEPARTMENT" => false,
				"GROUPS_ID" => array(CExtranet::GetExtranetUserGroupID())
			),
			array('FIELDS' => array('ID'))
		);
		while($user = $iterator->fetch())
		{
			$result[] = $user['ID'];
		}
		return $result;
	}
	if (preg_match('/^SG([0-9]+)_?([AEK])?$/', $code, $match) && CModule::IncludeModule('socialnetwork'))
	{
		$groupId = (int)$match[1];
		$role = isset($match[2])? $match[2] : 'K';

		$iterator = CSocNetUserToGroup::GetList(
			array("USER_ID" => "ASC"),
			array(
				"=GROUP_ID" => $groupId,
				"<=ROLE" => $role,
				"USER_ACTIVE" => "Y"
			),
			false,
			false,
			array("USER_ID")
		);
		$result = array();
		while($user = $iterator->fetch())
		{
			$result[] = $user['USER_ID'];
		}
		return $result;
	}

	return false;
}

Добавить комментарий