• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblockelement.php
  • Класс: CAllIBlockElement
  • Вызов: CAllIBlockElement::MkPropertySelect
public function MkPropertySelect($PR_ID, $db_prop, &$arJoinProps, $bWasGroup, $sGroupBy, &$sSelect, $bSort = false)
{
	global $DB;

	if($bSort && $db_prop["PROPERTY_TYPE"] != "L")
		return;

	static $arJoinEFields = false;

	//define maximum alias length
	$mal = false;

	$bSubQuery = isset($this) && is_object($this) && isset($this->subQueryProp);

	$arSelect = array();

	//Joined elements
	if(is_array($PR_ID))
	{
		if(!$arJoinEFields) $arJoinEFields = array(
			"ID" => "BE#i#.ID",
			"TIMESTAMP_X" => $DB->DateToCharFunction("BE#i#.TIMESTAMP_X"),
			"MODIFIED_BY" => "BE#i#.MODIFIED_BY",
			"DATE_CREATE" => $DB->DateToCharFunction("BE#i#.DATE_CREATE"),
			"CREATED_BY" => "BE#i#.CREATED_BY",
			"IBLOCK_ID" => "BE#i#.IBLOCK_ID",
			"ACTIVE" => "BE#i#.ACTIVE",
			"ACTIVE_FROM" => $DB->DateToCharFunction("BE#i#.ACTIVE_FROM"),
			"ACTIVE_TO" => $DB->DateToCharFunction("BE#i#.ACTIVE_TO"),
			"SORT" => "BE#i#.SORT",
			"NAME" => "BE#i#.NAME",
			"PREVIEW_PICTURE" => "BE#i#.PREVIEW_PICTURE",
			"PREVIEW_TEXT" => "BE#i#.PREVIEW_TEXT",
			"PREVIEW_TEXT_TYPE" => "BE#i#.PREVIEW_TEXT_TYPE",
			"DETAIL_PICTURE" => "BE#i#.DETAIL_PICTURE",
			"DETAIL_TEXT" => "BE#i#.DETAIL_TEXT",
			"DETAIL_TEXT_TYPE" => "BE#i#.DETAIL_TEXT_TYPE",
			"SHOW_COUNTER" => "BE#i#.SHOW_COUNTER",
			"SHOW_COUNTER_START" => $DB->DateToCharFunction("BE#i#.SHOW_COUNTER_START"),
			"CODE" => "BE#i#.CODE",
			"TAGS" => "BE#i#.TAGS",
			"XML_ID" => "BE#i#.XML_ID",
			"IBLOCK_SECTION_ID" => "BE#i#.IBLOCK_SECTION_ID",
			"IBLOCK_TYPE_ID"=>"B#i#.IBLOCK_TYPE_ID",
			"IBLOCK_CODE"=>"B#i#.CODE",
			"IBLOCK_NAME"=>"B#i#.NAME",
			"IBLOCK_EXTERNAL_ID"=>"B#i#.XML_ID",
			"DETAIL_PAGE_URL" => "
				replace(
				replace(
				replace(
				replace(
				replace(
				replace(
				replace(
				replace(
				replace(
				replace(
				replace(
				replace(
				replace(B#i#.DETAIL_PAGE_URL, '#ID#', BE#i#.ID)
				, '#ELEMENT_ID#', BE#i#.ID)
				, '#CODE#', ".$DB->IsNull("BE#i#.CODE", "''").")
				, '#ELEMENT_CODE#', ".$DB->IsNull("BE#i#.CODE", "''").")
				, '#EXTERNAL_ID#', ".$DB->IsNull("BE#i#.XML_ID", "''").")
				, '#IBLOCK_TYPE_ID#', B#i#.IBLOCK_TYPE_ID)
				, '#IBLOCK_ID#', BE#i#.IBLOCK_ID)
				, '#IBLOCK_CODE#', ".$DB->IsNull("B#i#.CODE", "''").")
				, '#IBLOCK_EXTERNAL_ID#', ".$DB->IsNull("B#i#.XML_ID", "''").")
				, '#SITE_DIR#', '".$DB->ForSQL(SITE_DIR)."')
				, '#SERVER_NAME#', '".$DB->ForSQL(SITE_SERVER_NAME)."')
				, '#SECTION_ID#', ".$DB->IsNull("BE#i#.IBLOCK_SECTION_ID", "''").")
				, '#SECTION_CODE#', ".$DB->IsNull("BS#i#.CODE", "''").")
			",
			"LIST_PAGE_URL" => "
				replace(
				replace(
				replace(
				replace(
				replace(
				replace(B#i#.LIST_PAGE_URL, '#IBLOCK_TYPE_ID#', B#i#.IBLOCK_TYPE_ID)
				, '#IBLOCK_ID#', BE#i#.IBLOCK_ID)
				, '#IBLOCK_CODE#', ".$DB->IsNull("B#i#.CODE", "''").")
				, '#IBLOCK_EXTERNAL_ID#', ".$DB->IsNull("B#i#.XML_ID", "''").")
				, '#SITE_DIR#', '".$DB->ForSQL(SITE_DIR)."')
				, '#SERVER_NAME#', '".$DB->ForSQL(SITE_SERVER_NAME)."')
			",
		);

		//Joined Elements Fields
		if(array_key_exists($PR_ID[2], $arJoinEFields))
		{

			if($db_prop["VERSION"] == 2 && $db_prop["MULTIPLE"] == "N")
			{
				//Join properties table if needed
				if(!array_key_exists($db_prop["IBLOCK_ID"], $arJoinProps["FPS"]))
					$arJoinProps["FPS"][$db_prop["IBLOCK_ID"]] = count($arJoinProps["FPS"]);
				$iPropCnt = $arJoinProps["FPS"][$db_prop["IBLOCK_ID"]];
			}
			else
			{
				//Join property metadata table
				if(!array_key_exists($db_prop["ID"], $arJoinProps["FP"]))
					$arJoinProps["FP"][$db_prop["ID"]] = array(
						"CNT" => count($arJoinProps["FP"]),
						"bFullJoin" => false,
					);
				//Join multiple values properties table if needed
				if(!array_key_exists($db_prop["ID"], $arJoinProps["FPV"]))
					$arJoinProps["FPV"][$db_prop["ID"]] = array(
						"CNT" => count($arJoinProps["FPV"]),
						"IBLOCK_ID" => $db_prop["IBLOCK_ID"],
						"MULTIPLE" => $db_prop["MULTIPLE"],
						"VERSION" => $db_prop["VERSION"],
						"ORIG_ID" => $db_prop["ORIG_ID"],
						"JOIN" => $arJoinProps["FP"][$db_prop["ID"]]["CNT"],
						"bFullJoin" => false,
					);
				$iPropCnt = $arJoinProps["FPV"][$db_prop["ID"]]["CNT"];
			}
			//Then join elements
			if(!array_key_exists($db_prop["ID"], $arJoinProps["BE"]))
				$arJoinProps["BE"][$db_prop["ID"]] = array(
					"CNT" => count($arJoinProps["BE"]),
					"MULTIPLE" => $db_prop["MULTIPLE"],
					"VERSION" => $db_prop["VERSION"],
					"ORIG_ID" => $db_prop["ORIG_ID"],
					"JOIN" => $iPropCnt,
					"bJoinIBlock" => false,
					"bJoinSection" => false,
				);
			$iElCnt = $arJoinProps["BE"][$db_prop["ID"]]["CNT"];

			//Check if b_iblock have to be joined also
			if(
				$PR_ID[2] == "LIST_PAGE_URL"
				|| $PR_ID[2] == "IBLOCK_TYPE_ID"
				|| $PR_ID[2] == "IBLOCK_CODE"
				|| $PR_ID[2] == "IBLOCK_NAME"
				|| $PR_ID[2] == "IBLOCK_EXTERNAL_ID"
			)
				$arJoinProps["BE"][$db_prop["ID"]]["bJoinIBlock"] = true;

			//Check if b_iblock_section have to be joined also
			if($PR_ID[2] == "DETAIL_PAGE_URL")
			{
				$arJoinProps["BE"][$db_prop["ID"]]["bJoinIBlock"] = true;
				$arJoinProps["BE"][$db_prop["ID"]]["bJoinSection"] = true;
			}

			$arSelect[str_replace("#i#", $iElCnt, $arJoinEFields[$PR_ID[2]])] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2], $this->arIBlockLongProps);
		}
		//Joined elements properties
		elseif(mb_substr($PR_ID[2], 0, 9) == "PROPERTY_")
		{
			$jProp_ID = mb_substr($PR_ID[2], 9);
			$db_jprop = CIBlockProperty::GetPropertyArray($jProp_ID, CIBlock::_MergeIBArrays($db_prop["LINK_IBLOCK_ID"]));
			if(is_array($db_jprop))
			{
				if($db_prop["VERSION"] == 2 && $db_prop["MULTIPLE"] == "N")
				{
					//Join properties table if needed
					if(!array_key_exists($db_prop["IBLOCK_ID"], $arJoinProps["FPS"]))
						$arJoinProps["FPS"][$db_prop["IBLOCK_ID"]] = count($arJoinProps["FPS"]);
					$iPropCnt = $arJoinProps["FPS"][$db_prop["IBLOCK_ID"]];
				}
				else
				{
					//Join property metadata table
					if(!array_key_exists($db_prop["ID"], $arJoinProps["FP"]))
						$arJoinProps["FP"][$db_prop["ID"]] = array(
							"CNT" => count($arJoinProps["FP"]),
							"bFullJoin" => false,
						);
					//Join multiple values properties table if needed
					if(!array_key_exists($db_prop["ID"], $arJoinProps["FPV"]))
						$arJoinProps["FPV"][$db_prop["ID"]] = array(
							"CNT" => count($arJoinProps["FPV"]),
							"IBLOCK_ID" => $db_prop["IBLOCK_ID"],
							"MULTIPLE" => $db_prop["MULTIPLE"],
							"VERSION" => $db_prop["VERSION"],
							"JOIN" => $arJoinProps["FP"][$db_prop["ID"]]["CNT"],
							"bFullJoin" => false,
						);
					$iPropCnt = $arJoinProps["FPV"][$db_prop["ID"]]["CNT"];
				}
				//Then join elements
				if(!array_key_exists($db_prop["ID"], $arJoinProps["BE"]))
					$arJoinProps["BE"][$db_prop["ID"]] = array(
						"CNT" => count($arJoinProps["BE"]),
						"MULTIPLE" => $db_prop["MULTIPLE"],
						"VERSION" => $db_prop["VERSION"],
						"ORIG_ID" => $db_prop["ORIG_ID"],
						"JOIN" => $iPropCnt,
						"bJoinIBlock" => false,
						"bJoinSection" => false,
					);
				$iElCnt = $arJoinProps["BE"][$db_prop["ID"]]["CNT"];

				if($db_jprop["USER_TYPE"]!="")
				{
					$arUserType = CIBlockProperty::GetUserType($db_jprop["USER_TYPE"]);
					if(array_key_exists("ConvertFromDB", $arUserType))
						$this->arIBlockConvProps["PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_VALUE"] = array(
							"ConvertFromDB" => $arUserType["ConvertFromDB"],
							"PROPERTY" => $db_jprop,
						);
				}

				$comp_prop_id = $db_jprop["ID"]."~".$db_prop["ID"];

				//Infoblock+ (property stored in separate table)
				if($db_jprop["VERSION"] == 2)
				{
					//This is single value property
					if($db_jprop["MULTIPLE"] == "N")
					{
						//For numbers we will need special processing in CIBlockResult::Fetch
						if($db_jprop["PROPERTY_TYPE"]=="N")
							$this->arIBlockNumProps["PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_VALUE"] = $db_prop;

						//Enum single property
						if($db_jprop["PROPERTY_TYPE"]=="L")
						{
							//Join properties table if needed
							if(!array_key_exists($db_jprop["IBLOCK_ID"], $arJoinProps["BE_FPS"]))
								$arJoinProps["BE_FPS"][$db_jprop["IBLOCK_ID"]] = array(
									"CNT" => count($arJoinProps["BE_FPS"]),
									"JOIN" => $iElCnt,
								);
							$ijPropCnt = $arJoinProps["BE_FPS"][$db_jprop["IBLOCK_ID"]]["CNT"];
							//Then join list values table
							if(!array_key_exists($comp_prop_id, $arJoinProps["BE_FPEN"]))
								$arJoinProps["BE_FPEN"][$comp_prop_id] = array(
									"CNT" => count($arJoinProps["BE_FPEN"]),
									"MULTIPLE" => "N",
									"VERSION" => 2,
									"ORIG_ID" => $db_jprop["ORIG_ID"],
									"JOIN" => $ijPropCnt,
									"bFullJoin" => false,
								);
							$ijFpenCnt = $arJoinProps["BE_FPEN"][$comp_prop_id]["CNT"];

							$arSelect["JFPEN".$ijFpenCnt.".VALUE"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_VALUE", $this->arIBlockLongProps);
							$arSelect["JFPEN".$ijFpenCnt.".ID"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_ENUM_ID", $this->arIBlockLongProps);
						}
						else //Just single value property for Infoblock+
						{
							//Join properties table if needed
							if(!array_key_exists($db_jprop["IBLOCK_ID"]."~".$db_prop["ID"], $arJoinProps["BE_FPS"]))
								$arJoinProps["BE_FPS"][$db_jprop["IBLOCK_ID"]."~".$db_prop["ID"]] = array(
									"CNT" => count($arJoinProps["BE_FPS"]),
									"JOIN" => $iElCnt,
								);
							$ijPropCnt = $arJoinProps["BE_FPS"][$db_jprop["IBLOCK_ID"]."~".$db_prop["ID"]]["CNT"];

							$arSelect["JFPS".$ijPropCnt.".PROPERTY_".$db_jprop["ORIG_ID"]] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_VALUE", $this->arIBlockLongProps);
							if($sGroupBy=="" && $db_jprop["WITH_DESCRIPTION"] == "Y")
								$arSelect["JFPS".$ijPropCnt.".DESCRIPTION_".$db_jprop["ORIG_ID"]] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_DESCRIPTION", $this->arIBlockLongProps);
						}

						//When there is no grouping and this is single value property for Infoblock+
						if($sGroupBy == "")
						{
							if($DB->type=="MSSQL")
								$arSelect[$DB->Concat("CAST(BE".$iElCnt.".ID AS VARCHAR)","':'","'".$db_jprop["ORIG_ID"]."'")] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_VALUE_ID", $this->arIBlockLongProps);
							else
								$arSelect[$DB->Concat("BE".$iElCnt.".ID","':'",$db_jprop["ORIG_ID"])] = CIBlockElement::MkAlias($mal, $PR_ID[2]."_".$PR_ID[1]."_VALUE_ID", $this->arIBlockLongProps);
						}
					}
					else //This is multiple value property for Infoblock+
					{
						//Join property metadata table
						if(!array_key_exists($comp_prop_id, $arJoinProps["BE_FP"]))
							$arJoinProps["BE_FP"][$comp_prop_id] = array(
								"CNT" => count($arJoinProps["BE_FP"]),
								"JOIN" => $iElCnt,
								"bFullJoin" => false,
							);
						//Join multiple values properties table if needed
						if(!array_key_exists($comp_prop_id, $arJoinProps["BE_FPV"]))
							$arJoinProps["BE_FPV"][$comp_prop_id] = array(
								"CNT" => count($arJoinProps["BE_FPV"]),
								"MULTIPLE" => "Y",
								"VERSION" => 2,
								"IBLOCK_ID" => $db_jprop["IBLOCK_ID"],
								"JOIN" => $arJoinProps["BE_FP"][$comp_prop_id]["CNT"],
								"BE_JOIN" => $iElCnt,
								"bFullJoin" => false,
							);
						$ijPropCnt = $arJoinProps["BE_FPV"][$comp_prop_id]["CNT"];

						//For enum properties
						if($db_jprop["PROPERTY_TYPE"]=="L")
						{
							//Then join list values table
							if(!array_key_exists($comp_prop_id, $arJoinProps["BE_FPEN"]))
								$arJoinProps["BE_FPEN"][$comp_prop_id] = array(
									"CNT" => count($arJoinProps["BE_FPEN"]),
									"MULTIPLE" => "Y",
									"VERSION" => 2,
									"ORIG_ID" => $db_jprop["ORIG_ID"],
									"JOIN" => $ijPropCnt,
									"bFullJoin" => false,
								);
							$ijFpenCnt = $arJoinProps["BE_FPEN"][$comp_prop_id]["CNT"];

							$arSelect["JFPEN".$ijFpenCnt.".VALUE"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_VALUE", $this->arIBlockLongProps);
							$arSelect["JFPEN".$ijFpenCnt.".ID"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_ENUM_ID", $this->arIBlockLongProps);
						}
						else
						{
							$arSelect["JFPV".$ijPropCnt.".VALUE"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_VALUE", $this->arIBlockLongProps);
						}
					}
				}//Infoblocks with common values table (VERSION==1)
				else
				{
					//Join property metadata table
					if(!array_key_exists($comp_prop_id, $arJoinProps["BE_FP"]))
						$arJoinProps["BE_FP"][$comp_prop_id] = array(
							"CNT" => count($arJoinProps["BE_FP"]),
							"JOIN" => $iElCnt,
							"bFullJoin" => false,
						);
					//Join multiple values properties table if needed
					if(!array_key_exists($comp_prop_id, $arJoinProps["BE_FPV"]))
						$arJoinProps["BE_FPV"][$comp_prop_id] = array(
							"CNT" => count($arJoinProps["BE_FPV"]),
							"MULTIPLE" => $db_jprop["MULTIPLE"],
							"VERSION" => 1,
							"IBLOCK_ID" => $db_jprop["IBLOCK_ID"],
							"JOIN" => $arJoinProps["BE_FP"][$comp_prop_id]["CNT"],
							"BE_JOIN" => $iElCnt,
							"bFullJoin" => false,
						);
					$ijPropCnt = $arJoinProps["BE_FPV"][$comp_prop_id]["CNT"];

					//For enum properties
					if($db_jprop["PROPERTY_TYPE"]=="L")
					{
						//Then join list values table
						if(!array_key_exists($comp_prop_id, $arJoinProps["BE_FPEN"]))
							$arJoinProps["BE_FPEN"][$comp_prop_id] = array(
								"CNT" => count($arJoinProps["BE_FPEN"]),
								"MULTIPLE" => $db_jprop["MULTIPLE"],
								"VERSION" => 1,
								"ORIG_ID" => $db_jprop["ORIG_ID"],
								"JOIN" => $ijPropCnt,
								"bFullJoin" => false,
							);
						$ijFpenCnt = $arJoinProps["BE_FPEN"][$comp_prop_id]["CNT"];

						$arSelect["JFPEN".$ijFpenCnt.".VALUE"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_VALUE", $this->arIBlockLongProps);
						$arSelect["JFPEN".$ijFpenCnt.".ID"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_ENUM_ID", $this->arIBlockLongProps);
					}
					else
					{
						$arSelect["JFPV".$ijPropCnt.".VALUE"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_VALUE", $this->arIBlockLongProps);
					}

					//When there is no grouping select property value id also
					if($sGroupBy == "")
						$arSelect["JFPV".$ijPropCnt.".ID"] =  CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID[1]."_".$PR_ID[2]."_VALUE_ID", $this->arIBlockLongProps);
				}
			}

		}
	}
	else
	{
		//Define special processing for CIBlockResult::Fetch
		if($db_prop["USER_TYPE"]!="")
		{
			$arUserType = CIBlockProperty::GetUserType($db_prop["USER_TYPE"]);
			if(array_key_exists("ConvertFromDB", $arUserType))
				$this->arIBlockConvProps["PROPERTY_".$PR_ID."_VALUE"] = array(
					"ConvertFromDB" => $arUserType["ConvertFromDB"],
					"PROPERTY" => $db_prop,
				);
		}

		//Infoblock+ (property stored in separate table)
		if($db_prop["VERSION"] == 2)
		{
			//This is single value property
			if($db_prop["MULTIPLE"] == "N")
			{
				//For numbers we will need special processing in CIBlockResult::Fetch
				if($db_prop["PROPERTY_TYPE"]=="N")
					$this->arIBlockNumProps["PROPERTY_".$PR_ID."_VALUE"] = $db_prop;

				//Enum single property
				if($db_prop["PROPERTY_TYPE"]=="L")
				{
					//Join properties table if needed
					if(!array_key_exists($db_prop["IBLOCK_ID"], $arJoinProps["FPS"]))
						$arJoinProps["FPS"][$db_prop["IBLOCK_ID"]] = count($arJoinProps["FPS"]);
					$iPropCnt = $arJoinProps["FPS"][$db_prop["IBLOCK_ID"]];
					//Then join list values table
					if(!array_key_exists($db_prop["ID"], $arJoinProps["FPEN"]))
						$arJoinProps["FPEN"][$db_prop["ID"]] = array(
							"CNT" => count($arJoinProps["FPEN"]),
							"MULTIPLE" => "N",
							"VERSION" => 2,
							"ORIG_ID" => $db_prop["ORIG_ID"],
							"JOIN" => $iPropCnt,
							"bFullJoin" => false,
						);
					$iFpenCnt = $arJoinProps["FPEN"][$db_prop["ID"]]["CNT"];

					if($bSort)
						$arSelect["FPEN".$iFpenCnt.".SORT"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_SORT", $this->arIBlockLongProps);
					$arSelect["FPEN".$iFpenCnt.".VALUE"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_VALUE", $this->arIBlockLongProps);
					$arSelect["FPEN".$iFpenCnt.".ID"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_ENUM_ID", $this->arIBlockLongProps);
				}
				else //Just single value property for Infoblock+
				{
					//Join properties table if needed
					if(!array_key_exists($db_prop["IBLOCK_ID"], $arJoinProps["FPS"]))
						$arJoinProps["FPS"][$db_prop["IBLOCK_ID"]] = count($arJoinProps["FPS"]);
					$iPropCnt = $arJoinProps["FPS"][$db_prop["IBLOCK_ID"]];

					$arSelect["FPS".$iPropCnt.".PROPERTY_".$db_prop["ORIG_ID"]] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_VALUE", $this->arIBlockLongProps);
					if($sGroupBy=="" && $db_prop["WITH_DESCRIPTION"] == "Y")
						$arSelect["FPS".$iPropCnt.".DESCRIPTION_".$db_prop["ORIG_ID"]] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_DESCRIPTION", $arIBlockLongProps);
				}

				//When there is no grouping and this is single value property for Infoblock+
				if($sGroupBy == "")
				{
					if($DB->type=="MSSQL")
						$arSelect[$DB->Concat("CAST(BE.ID AS VARCHAR)","':'","'".$db_prop["ORIG_ID"]."'")] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_VALUE_ID", $this->arIBlockLongProps);
					else
						$arSelect[$DB->Concat("BE.ID","':'",$db_prop["ORIG_ID"])] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_VALUE_ID", $this->arIBlockLongProps);
				}
			}
			else //This is multiple value property for Infoblock+
			{
				//There was no grouping so we can join FPS and constuct an array on CIBlockPropertyResult::Fetch
				if(!$bWasGroup && !$bSubQuery)
				{
					//Join single value properties table if needed
					if(!array_key_exists($db_prop["IBLOCK_ID"], $arJoinProps["FPS"]))
						$arJoinProps["FPS"][$db_prop["IBLOCK_ID"]] = count($arJoinProps["FPS"]);
					$iPropCnt = $arJoinProps["FPS"][$db_prop["IBLOCK_ID"]];

					$arSelect["FPS".$iPropCnt.".PROPERTY_".$db_prop["ORIG_ID"]] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_VALUE", $this->arIBlockLongProps);
					if($sGroupBy=="" && $db_prop["WITH_DESCRIPTION"] == "Y")
						$arSelect["FPS".$iPropCnt.".DESCRIPTION_".$db_prop["ORIG_ID"]] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_DESCRIPTION", $this->arIBlockLongProps);

					//And we will need extra processing in CIBlockPropertyResult::Fetch
					$this->arIBlockMultProps["PROPERTY_".$PR_ID."_VALUE"] = $db_prop;
				}
				//This is multiple value property for Infoblock+ with gouping used
				else
				{
					//Join property metadata table
					if(!array_key_exists($db_prop["ID"], $arJoinProps["FP"]))
						$arJoinProps["FP"][$db_prop["ID"]] = array(
							"CNT" => count($arJoinProps["FP"]),
							"bFullJoin" => false,
						);
					//Join multiple values properties table if needed
					if(!array_key_exists($db_prop["ID"], $arJoinProps["FPV"]))
						$arJoinProps["FPV"][$db_prop["ID"]] = array(
							"CNT" => count($arJoinProps["FPV"]),
							"IBLOCK_ID" => $db_prop["IBLOCK_ID"],
							"MULTIPLE" => "Y",
							"VERSION" => 2,
							"JOIN" => $arJoinProps["FP"][$db_prop["ID"]]["CNT"],
							"bFullJoin" => false,
						);
					$iPropCnt = $arJoinProps["FPV"][$db_prop["ID"]]["CNT"];

					//For enum properties
					if($db_prop["PROPERTY_TYPE"]=="L")
					{
						//Then join list values table
						if(!array_key_exists($db_prop["ID"], $arJoinProps["FPEN"]))
							$arJoinProps["FPEN"][$db_prop["ID"]] = array(
								"CNT" => count($arJoinProps["FPEN"]),
								"MULTIPLE" => "Y",
								"VERSION" => 2,
								"ORIG_ID" => $db_prop["ORIG_ID"],
								"JOIN" => $iPropCnt,
								"bFullJoin" => false,
							);
						$iFpenCnt = $arJoinProps["FPEN"][$db_prop["ID"]]["CNT"];

						if($bSort)
							$arSelect["FPEN".$iFpenCnt.".SORT"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_SORT", $this->arIBlockLongProps);
						$arSelect["FPEN".$iFpenCnt.".VALUE"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_VALUE", $this->arIBlockLongProps);
						$arSelect["FPEN".$iFpenCnt.".ID"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_ENUM_ID", $this->arIBlockLongProps);
					}
					else
					{
						$arSelect["FPV".$iPropCnt.".VALUE"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_VALUE", $this->arIBlockLongProps);
					}
				}
			}
		}//Infoblocks with common values table (VERSION==1)
		else
		{
			//Join property metadata table
			if(!array_key_exists($db_prop["ID"], $arJoinProps["FP"]))
				$arJoinProps["FP"][$db_prop["ID"]] = array(
					"CNT" => count($arJoinProps["FP"]),
					"bFullJoin" => false,
				);
			//Join multiple values properties table if needed
			if(!array_key_exists($db_prop["ID"], $arJoinProps["FPV"]))
				$arJoinProps["FPV"][$db_prop["ID"]] = array(
					"CNT" => count($arJoinProps["FPV"]),
					"IBLOCK_ID" => $db_prop["IBLOCK_ID"],
					"MULTIPLE" => $db_prop["MULTIPLE"],
					"VERSION" => 1,
					"JOIN" => $arJoinProps["FP"][$db_prop["ID"]]["CNT"],
					"bFullJoin" => false,
				);
			$iPropCnt = $arJoinProps["FPV"][$db_prop["ID"]]["CNT"];

			//For enum properties
			if($db_prop["PROPERTY_TYPE"]=="L")
			{
				//Then join list values table
				if(!array_key_exists($db_prop["ID"], $arJoinProps["FPEN"]))
					$arJoinProps["FPEN"][$db_prop["ID"]] = array(
						"CNT" => count($arJoinProps["FPEN"]),
						"MULTIPLE" => $db_prop["MULTIPLE"],
						"VERSION" => 1,
						"ORIG_ID" => $db_prop["ORIG_ID"],
						"JOIN" => $iPropCnt,
						"bFullJoin" => false,
					);
				$iFpenCnt = $arJoinProps["FPEN"][$db_prop["ID"]]["CNT"];

				if($bSort)
					$arSelect["FPEN".$iFpenCnt.".SORT"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_SORT", $this->arIBlockLongProps);
				$arSelect["FPEN".$iFpenCnt.".VALUE"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_VALUE", $this->arIBlockLongProps);
				$arSelect["FPEN".$iFpenCnt.".ID"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_ENUM_ID", $this->arIBlockLongProps);
			}
			else
			{
				$arSelect["FPV".$iPropCnt.".VALUE"] = CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_VALUE", $this->arIBlockLongProps);
			}

			//When there is no grouping select property value id also
			if($sGroupBy == "")
				$arSelect["FPV".$iPropCnt.".ID"] =  CIBlockElement::MkAlias($mal, "PROPERTY_".$PR_ID."_VALUE_ID", $this->arIBlockLongProps);
		}
	}

	//If this is subquery we do not need alias and any othe columns
	if($bSubQuery)
	{
		foreach($arSelect as $column => $alias)
		{
			if(preg_match('/^(FPV\d+)\.VALUE/', $column, $match))
			{
				$sSelect .= ", ".$match[1].".VALUE_NUM";
				break;
			}
			elseif(preg_match('/^(FPS\d+)\.PROPERTY_/', $column))
			{
				$sSelect .= ", ".$column;
				break;
			}
		}
	}
	else
	{
		foreach($arSelect as $column => $alias)
			$sSelect .= ", ".$column." as ".$alias;
	}
}