CBPHelper::usersStringToArray

  1. Bitrix24 API (v. 23.675.0)
  2. bizproc
  3. CBPHelper
  4. usersStringToArray
  • Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/classes/general/helper.php
  • Класс: CBPHelper
  • Вызов: CBPHelper::usersStringToArray
static function usersStringToArray($strUsers, $documentType, &$arErrors, $callbackFunction = null)
{
	$arErrors = [];

	$strUsers = trim($strUsers);
	if ($strUsers == '')
	{
		return ($callbackFunction != null) ? [[], []] : [];
	}

	if (CBPActivity::isExpression($strUsers))
	{
		return ($callbackFunction != null) ? [[$strUsers], []] : [$strUsers];
	}

	$arUsers = [];
	$strUsers = str_replace(";", ",", $strUsers);
	$arUsersTmp = explode(",", $strUsers);
	foreach ($arUsersTmp as $user)
	{
		$user = trim($user);
		if ($user <> '')
		{
			$arUsers[] = $user;
		}
	}

	$arAllowableUserGroups = null;

	$arResult = $arResultAlt = [];
	foreach ($arUsers as $user)
	{
		$bCorrectUser = false;
		$bNotFoundUser = true;
		if (CBPActivity::isExpression($user))
		{
			$bCorrectUser = true;
			$arResult[] = $user;
		}
		else
		{
			if ($arAllowableUserGroups == null)
			{
				$arAllowableUserGroups = [];
				$arAllowableUserGroupsTmp = CBPDocument::GetAllowableUserGroups($documentType);
				foreach ($arAllowableUserGroupsTmp as $k1 => $v1)
				{
					$arAllowableUserGroups[mb_strtolower($k1)] = mb_strtolower($v1);
				}
			}

			if (array_key_exists(mb_strtolower($user), $arAllowableUserGroups))
			{
				$bCorrectUser = true;
				$arResult[] = $user;
			}
			elseif (($k1 = array_search(mb_strtolower($user), $arAllowableUserGroups)) !== false)
			{
				$bCorrectUser = true;
				$arResult[] = $k1;
			}
			elseif (preg_match('#[([A-Z]{1,}[0-9A-Z_]+)]$#i', $user, $arMatches))
			{
				$bCorrectUser = true;
				$arResult[] = 'group_' . mb_strtolower($arMatches[1]);
			}
			else
			{
				$ar = self::SearchUserByName($user);
				$cnt = count($ar);
				if ($cnt == 1)
				{
					$bCorrectUser = true;
					$arResult[] = 'user_' . $ar[0];
				}
				elseif ($cnt > 1)
				{
					$bNotFoundUser = false;
					$arErrors[] = [
						'code' => 'Ambiguous',
						'message' => str_replace(
							'#USER#',
							htmlspecialcharsbx($user),
							GetMessage('BPCGHLP_AMBIGUOUS_USER')
						),
					];
				}
				elseif ($callbackFunction != null)
				{
					$s = call_user_func_array($callbackFunction, [$user]);
					if ($s != null)
					{
						$arResultAlt[] = $s;
						$bCorrectUser = true;
					}
				}
			}
		}

		if (!$bCorrectUser)
		{
			if ($bNotFoundUser)
			{
				$arErrors[] = [
					'code' => 'NotFound',
					'message' => str_replace(
						'#USER#',
						htmlspecialcharsbx($user),
						GetMessage('BPCGHLP_INVALID_USER')
					),
				];
			}
		}
	}

	return ($callbackFunction != null) ? [$arResult, $arResultAlt] : $arResult;
}

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