CModule IncludeModule iblock не показывать бренды которым ничего не пр

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
<?
CModule::IncludeModule("iblock");
/*не показывать бренды, к которым ничего не привязано*/
CModule::IncludeModule("iblock");
$arActualBrandIds = array();
$arFilter = array(
"IBLOCK_ID" => CATALOG_IBLOCK_ID,
"ACTIVE" => "Y"
);
$rsElements = CIBlockElement::GetList(
array(),
$arFilter,
array("PROPERTY_BRAND")
);
while( $arElement = $rsElements->GetNext() ) {
$brandValue = $arElement["PROPERTY_BRAND_VALUE"];
if($brandValue && is_numeric($brandValue)){
$arActualBrandIds[] = $brandValue;
}
}
foreach($arResult["ITEMS"] as $key => $arItem){
if(!in_array($arItem["ID"], $arActualBrandIds)) {
unset($arResult["ITEMS"][$key]);
}
}
/*разбиваем по столбцам*/
$arAlphas = range('A', 'Z');
$arCyrilic = range(chr(0xC0), chr(0xDF));
foreach ($arCyrilic as $key => $letter) {
$arCyrilic[ $key ] = iconv('CP1251', 'UTF-8', $letter);
}
$arResult["LETTERS"] = array_merge(array("0-9"), $arAlphas, array("А-Я"));
$arResult["LETTERS_ANCHORS"] = array();
$arResult["ALPHABET_ITEMS"] = array();
$arResult["ALPHABET_ITEMS"]["0-9"] = array();
$arResult["LETTERS_ANCHORS"]["0-9"] = "numbers";
foreach($arAlphas as $letter) {
$arResult["ALPHABET_ITEMS"][ $letter ] = array();
$arResult["LETTERS_ANCHORS"][ $letter ] = $letter;
}
$arResult["LETTERS_ANCHORS"]["А-Я"] = "russian";
$arResult["ALPHABET_ITEMS"]["А-Я"] = array();
//в результат уже отсортирован по алфавиту компонентом
foreach( $arResult["ITEMS"] as $arItem ) {
$firstLetter = mb_substr(strtoupper($arItem["NAME"]), 0, 1, 'utf-8');
if( is_array($arResult["ALPHABET_ITEMS"][ $firstLetter ]) ) {
$itemKey = $firstLetter;
} elseif( in_array( $firstLetter, $arCyrilic ) ) {
$itemKey = "А-Я";
} else {
$itemKey = "0-9";
}
$arResult["ALPHABET_ITEMS"][ $itemKey ][] = $arItem;
}
//раскидываем по колонкам
foreach( $arResult["ALPHABET_ITEMS"] as $letter => $arItems ) {
$totalCount = count($arItems);
if( !$totalCount ) {
unset($arResult["ALPHABET_ITEMS"][ $letter ]);
continue;
}
$numberOfColumns = 4;
$minElementsPerColumn = intval($totalCount / $numberOfColumns);
$columnsWithExtraElements = $totalCount % $numberOfColumns;
$currentColumn = 0;
$columnElements = 0;
$curColumnMaxNumberOfElements = $minElementsPerColumn;
if($currentColumn < $columnsWithExtraElements) {
$curColumnMaxNumberOfElements++;
}
foreach( $arItems as $arItem ) {
if($columnElements >= $curColumnMaxNumberOfElements) {
$currentColumn++;
$columnElements = 0;
$curColumnMaxNumberOfElements = $minElementsPerColumn;
if($currentColumn < $columnsWithExtraElements) {
$curColumnMaxNumberOfElements++;
}
}
$arResult["ALPHABET_ITEMS"][$letter]["COLUMNS"][ $currentColumn ][] = $arItem;
$columnElements++;
}
}
?>