public function MkPropertyOrder($by, $order, $bSort, $db_prop, &$arJoinProps, &$arSqlOrder)
{
if($bSort && $db_prop["PROPERTY_TYPE"] != "L")
return;
global $DB;
static $arJoinEFields = false;
//Tables counters
if($db_prop["VERSION"] == 2 && $db_prop["MULTIPLE"]=="N")
{
if(!array_key_exists($db_prop["IBLOCK_ID"], $arJoinProps["FPS"]))
$iPropCnt = count($arJoinProps["FPS"]);
else
$iPropCnt = $arJoinProps["FPS"][$db_prop["IBLOCK_ID"]];
}
else
{
if(!array_key_exists($db_prop["ID"], $arJoinProps["FPV"]))
$iPropCnt = count($arJoinProps["FPV"]);
else
$iPropCnt = $arJoinProps["FPV"][$db_prop["ID"]]["CNT"];
}
if($db_prop["PROPERTY_TYPE"] == "L")
{
if(!array_key_exists($db_prop["ID"], $arJoinProps["FPEN"]))
$iFpenCnt = count($arJoinProps["FPEN"]);
else
$iFpenCnt = $arJoinProps["FPEN"][$db_prop["ID"]]["CNT"];
}
else
{
$iFpenCnt = -1;
}
$iElCnt = -1;
$db_jprop = false;
$ijPropCnt = -1;
$ijFpenCnt = -1;
if(is_array($by))
{
if(!$arJoinEFields) $arJoinEFields = array(
"ID" => "BE#i#.ID",
"TIMESTAMP_X" => "BE#i#.TIMESTAMP_X",
"MODIFIED_BY" => "BE#i#.MODIFIED_BY",
"CREATED" => "BE#i#.DATE_CREATE",
"CREATED_DATE" => $DB->DateFormatToDB("YYYY.MM.DD", "BE#i#.DATE_CREATE"),
"CREATED_BY" => "BE#i#.CREATED_BY",
"IBLOCK_ID" => "BE#i#.IBLOCK_ID",
"ACTIVE" => "BE#i#.ACTIVE",
"ACTIVE_FROM" => "BE#i#.ACTIVE_FROM",
"ACTIVE_TO" => "BE#i#.ACTIVE_TO",
"SORT" => "BE#i#.SORT",
"NAME" => "BE#i#.NAME",
"SHOW_COUNTER" => "BE#i#.SHOW_COUNTER",
"SHOW_COUNTER_START" => "BE#i#.SHOW_COUNTER_START",
"CODE" => "BE#i#.CODE",
"TAGS" => "BE#i#.TAGS",
"XML_ID" => "BE#i#.XML_ID",
"STATUS" => "BE#i#.WF_STATUS_ID",
);
//Joined Elements Field
if(array_key_exists($by[2], $arJoinEFields))
{
//Then join elements
if(!array_key_exists($db_prop["ID"], $arJoinProps["BE"]))
$iElCnt = count($arJoinProps["BE"]);
else
$iElCnt = $arJoinProps["BE"][$db_prop["ID"]]["CNT"];
$arSqlOrder[$by[0]] = CIBlock::_Order(str_replace("#i#", $iElCnt, $arJoinEFields[$by[2]]), $order, "desc");
}
elseif(mb_substr($by[2], 0, 9) == "PROPERTY_")
{
$jProp_ID = mb_substr($by[2], 9);
$db_jprop = CIBlockProperty::GetPropertyArray($jProp_ID, CIBlock::_MergeIBArrays($db_prop["LINK_IBLOCK_ID"]));
if(is_array($db_jprop))
{
//join elements
if(!array_key_exists($db_prop["ID"], $arJoinProps["BE"]))
$iElCnt = count($arJoinProps["BE"]);
else
$iElCnt = $arJoinProps["BE"][$db_prop["ID"]]["CNT"];
if($db_jprop["VERSION"] == 2 && $db_jprop["MULTIPLE"]=="N")
{
if(!array_key_exists($db_jprop["IBLOCK_ID"], $arJoinProps["BE_FPS"]))
$ijPropCnt = count($arJoinProps["BE_FPS"]);
else
$ijPropCnt = $arJoinProps["BE_FPS"][$db_jprop["IBLOCK_ID"]]["CNT"];
}
else
{
if(!array_key_exists($db_jprop["ID"], $arJoinProps["BE_FPV"]))
$ijPropCnt = count($arJoinProps["BE_FPV"]);
else
$ijPropCnt = $arJoinProps["BE_FPV"][$db_jprop["ID"]]["CNT"];
}
if($db_jprop["PROPERTY_TYPE"] == "L")
{
if(!array_key_exists($db_jprop["ID"], $arJoinProps["BE_FPEN"]))
$ijFpenCnt = count($arJoinProps["BE_FPEN"]);
else
$ijFpenCnt = $arJoinProps["BE_FPEN"][$db_jprop["ID"]]["CNT"];
}
if($db_jprop["PROPERTY_TYPE"]=="L" && $bSort)
$arSqlOrder["PROPERTY_".$by[1]."_".$by[2]] = CIBlock::_Order("JFPEN".$ijFpenCnt.".SORT", $order, "desc");
elseif($db_jprop["PROPERTY_TYPE"]=="L")
$arSqlOrder["PROPERTY_".$by[1]."_".$by[2]] = CIBlock::_Order("JFPEN".$ijFpenCnt.".VALUE", $order, "desc");
elseif($db_jprop["VERSION"]==2 && $db_jprop["MULTIPLE"]=="N")
$arSqlOrder["PROPERTY_".$by[1]."_".$by[2]] = CIBlock::_Order("JFPS".$ijPropCnt.".PROPERTY_".$db_jprop["ORIG_ID"], $order, "desc");
elseif($db_jprop["PROPERTY_TYPE"]=="N")
$arSqlOrder["PROPERTY_".$by[1]."_".$by[2]] = CIBlock::_Order("JFPV".$ijPropCnt.".VALUE_NUM", $order, "desc");
else
$arSqlOrder["PROPERTY_".$by[1]."_".$by[2]] = CIBlock::_Order("JFPV".$ijPropCnt.".VALUE", $order, "desc");
}
}
}
else
{
if($db_prop["PROPERTY_TYPE"]=="L" && $bSort)
$arSqlOrder[$by] = CIBlock::_Order("FPEN".$iFpenCnt.".SORT", $order, "desc");
elseif($db_prop["PROPERTY_TYPE"]=="L")
$arSqlOrder[$by] = CIBlock::_Order("FPEN".$iFpenCnt.".VALUE", $order, "desc");
elseif($db_prop["VERSION"]==2 && $db_prop["MULTIPLE"]=="N")
$arSqlOrder[$by] = CIBlock::_Order("FPS".$iPropCnt.".PROPERTY_".$db_prop["ORIG_ID"], $order, "desc");
elseif($db_prop["PROPERTY_TYPE"]=="N")
$arSqlOrder[$by] = CIBlock::_Order("FPV".$iPropCnt.".VALUE_NUM", $order, "desc");
else
$arSqlOrder[$by] = CIBlock::_Order("FPV".$iPropCnt.".VALUE", $order, "desc");
}
//Pass join "commands" up there
if($db_prop["VERSION"] == 2 && $db_prop["MULTIPLE"]=="N")
{
if(!array_key_exists($db_prop["IBLOCK_ID"], $arJoinProps["FPS"]))
$arJoinProps["FPS"][$db_prop["IBLOCK_ID"]] = $iPropCnt;
}
else
{
if(!array_key_exists($db_prop["ID"], $arJoinProps["FP"]))
$arJoinProps["FP"][$db_prop["ID"]] = array(
"CNT" => count($arJoinProps["FP"]),
"bFullJoin" => false,
);
if(!array_key_exists($db_prop["ID"], $arJoinProps["FPV"]))
$arJoinProps["FPV"][$db_prop["ID"]] = array(
"CNT" => $iPropCnt,
"IBLOCK_ID" => $db_prop["IBLOCK_ID"],
"MULTIPLE" => $db_prop["MULTIPLE"],
"VERSION" => $db_prop["VERSION"],
"JOIN" => $arJoinProps["FP"][$db_prop["ID"]]["CNT"],
"bFullJoin" => false,
);
}
if($iFpenCnt >= 0 && !array_key_exists($db_prop["ID"], $arJoinProps["FPEN"]))
$arJoinProps["FPEN"][$db_prop["ID"]] = array(
"CNT" => $iFpenCnt,
"MULTIPLE" => $db_prop["MULTIPLE"],
"VERSION" => $db_prop["VERSION"],
"ORIG_ID" => $db_prop["ORIG_ID"],
"JOIN" => $iPropCnt,
"bFullJoin" => false,
);
if($iElCnt >= 0)
{
if(!array_key_exists($db_prop["ID"], $arJoinProps["BE"]))
$arJoinProps["BE"][$db_prop["ID"]] = array(
"CNT" => $iElCnt,
"MULTIPLE" => $db_prop["MULTIPLE"],
"VERSION" => $db_prop["VERSION"],
"ORIG_ID" => $db_prop["ORIG_ID"],
"JOIN" => $iPropCnt,
"bJoinIBlock" => false,
"bJoinSection" => false,
);
if(is_array($db_jprop))
{
if($db_jprop["VERSION"] == 2 && $db_jprop["MULTIPLE"]=="N")
{
if(!array_key_exists($db_jprop["IBLOCK_ID"], $arJoinProps["BE_FPS"]))
$arJoinProps["BE_FPS"][$db_jprop["IBLOCK_ID"]] = array(
"CNT" => $ijPropCnt,
"JOIN" => $iElCnt,
);
}
else
{
if(!array_key_exists($db_jprop["ID"], $arJoinProps["BE_FP"]))
$arJoinProps["BE_FP"][$db_jprop["ID"]] = array(
"CNT" => count($arJoinProps["BE_FP"]),
"JOIN" => $iElCnt,
"bFullJoin" => false,
);
if(!array_key_exists($db_jprop["ID"], $arJoinProps["BE_FPV"]))
$arJoinProps["BE_FPV"][$db_jprop["ID"]] = array(
"CNT" => $ijPropCnt,
"IBLOCK_ID" => $db_jprop["IBLOCK_ID"],
"MULTIPLE" => $db_jprop["MULTIPLE"],
"VERSION" => $db_jprop["VERSION"],
"JOIN" => $arJoinProps["BE_FP"][$db_jprop["ID"]]["CNT"],
"BE_JOIN" => $iElCnt,
"bFullJoin" => false,
);
}
if($ijFpenCnt >= 0 && !array_key_exists($db_jprop["ID"], $arJoinProps["BE_FPEN"]))
$arJoinProps["BE_FPEN"][$db_jprop["ID"]] = array(
"CNT" => $ijFpenCnt,
"MULTIPLE" => $db_jprop["MULTIPLE"],
"VERSION" => $db_jprop["VERSION"],
"ORIG_ID" => $db_jprop["ORIG_ID"],
"JOIN" => $ijPropCnt,
"bFullJoin" => false,
);
}
}
}