• Модуль: ldap
  • Путь к файлу: ~/bitrix/modules/ldap/classes/general/ldap.php
  • Класс: CLDAP
  • Вызов: CLDAP::QueryArray
public function QueryArray($str = '(ObjectClass=*)', $fields = false)
{
	global $APPLICATION;

	if($this->arFields['BASE_DN'] == '')
		return false;

	$arBaseDNs = explode(";", $this->arFields['BASE_DN']);
	$info = false;
	$i=0;

	if($this->arFields["CONVERT_UTF8"] == "Y")
		$str = $APPLICATION->ConvertCharset($str, SITE_CHARSET, "utf-8");

	foreach($arBaseDNs as $BaseDN)
	{
		global $APPLICATION;

		$BaseDN = trim($BaseDN);
		if($BaseDN == "")
			continue;

		if($this->arFields["CONVERT_UTF8"]=="Y")
			$BaseDN = $APPLICATION->ConvertCharset($BaseDN, SITE_CHARSET, "utf-8");

		$defaultMaxPageSizeAD = 1000;
		$pageSize = isset($this->arFields['MAX_PAGE_SIZE']) && intval($this->arFields['MAX_PAGE_SIZE'] > 0) ? intval($this->arFields['MAX_PAGE_SIZE']) : $defaultMaxPageSizeAD;
		$cookie = '';

		do
		{
			$searchAttributes = is_array($fields) ? $fields : [];
			$searchControls = null;
			if (CLdapUtil::isLdapPaginationAviable())
			{
				$searchControls = [
					['oid' => LDAP_CONTROL_PAGEDRESULTS, 'value' => ['size' => $pageSize, 'cookie' => $cookie]],
				];
			}

			$sr = @ldap_search(
				$this->conn,
				$BaseDN,
				$str,
				$searchAttributes,
				0,
				-1,
				-1,
				LDAP_DEREF_NEVER,
				$searchControls
			);

			if ($sr)
			{
				if (CLdapUtil::isLdapPaginationAviable())
				{
					ldap_parse_result(
						$this->conn,
						$sr,
						$error_code,
						$matched_dn,
						$error_message,
						$referrals,
						$controls
					);
					$cookie = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? '';
				}

				$entry = ldap_first_entry($this->conn, $sr);

				if($entry)
				{
					if(!is_array($info))
					{
						$info = Array();
						$i=0;
					}

					do
					{
						$attributes = ldap_get_attributes($this->conn, $entry);

						for($j=0; $j<$attributes['count']; $j++)
						{
							$values = @ldap_get_values_len($this->conn, $entry, $attributes[$j]);

							if($values === false)
								continue;

							$bPhotoAttr = in_array($attributes[$j], self::$PHOTO_ATTRIBS);
							$info[$i][mb_strtolower($attributes[$j])] = $bPhotoAttr ? $values : $this->WorkAttr($values);
						}
						if(!is_set($info[$i], 'dn'))
						{
							if($this->arFields["CONVERT_UTF8"]=="Y")
								$info[$i]['dn'] = $APPLICATION->ConvertCharset(ldap_get_dn($this->conn, $entry), "utf-8", SITE_CHARSET);
							else
								$info[$i]['dn'] = ldap_get_dn($this->conn, $entry);
						}
						$i++;

					}
					while($entry = ldap_next_entry($this->conn, $entry));
				}
			}
			elseif($sr === false)
			{
				$APPLICATION->ThrowException("LDAP_SEARCH_ERROR");
			}

		} while($cookie !== null && $cookie != '');
	}

	return $info;
}