A
A
Artem2020-12-09 11:31:21
1C-Bitrix
Artem, 2020-12-09 11:31:21

How to remove duplicates when displaying the properties of elements on the Bitrix website?

I made a table on the site, and added filtering by the necessary properties. But there are duplicates. Screen under the spoiler The

4b33055016d1a0fe9c7ae9bad33b13f1-full.png

question is what needs to be added to remove duplicates, I can’t figure something out. Can anyone tell
me the code used:

<select class="drop" id="regionDropdown">
            <option value="All">Показать все</option>
            <?foreach($arResult["ITEMS"] as $arItem):?>
            <?if(!empty($arItem['DISPLAY_PROPERTIES']['FILM_TYPES']['VALUE'])):?>
            <option value="<?=$arItem['DISPLAY_PROPERTIES']['FILM_TYPES']['DISPLAY_VALUE'];?>"><? endif; ?><?=$arItem['DISPLAY_PROPERTIES']['FILM_TYPES']['DISPLAY_VALUE'];?></option>
            <? endif; ?>
            <? endforeach; ?>
         </select>


I would be very grateful if someone could share their knowledge :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-12-09
@avgustov

In result_modifier.php

if($arResult['ITEMS']) {
  $arResult['FILE_TYPES'] = $filmTypes = [];
  
  foreach($arResult['ITEMS'] as $key => $arItem) {
    $filmTypesProp = isset($arItem['DISPLAY_PROPERTIES']['FILM_TYPES']) ? $arItem['DISPLAY_PROPERTIES']['FILM_TYPES'] : false;
    $value = $filmTypesProp && $filmTypesProp['VALUE'] ? $filmTypesProp['VALUE'] : false;
    $displayValue = $filmTypesProp && $filmTypesProp['DISPLAY_VALUE'] ? $filmTypesProp['DISPLAY_VALUE'] : false;
    
    if($value && $displayValue) {
      $filmTypes['VALUE'][] = $value;
      $filmTypes['DISPLAY_VALUE'][] = $displayValue;
    }
  }
  
  $arResult['FILE_TYPES'] = [
    'VALUE' => array_values(array_unique($filmTypes['VALUE'])),
    'DISPLAY_VALUE' => array_values(array_unique($filmTypes['DISPLAY_VALUE'])),
  ];
}

Where do you output select
<?if(isset($arResult['FILE_TYPES']) && $arResult['FILE_TYPES']):?>
  <select class="drop" id="regionDropdown">
    <option value="All">Показать все</option>
    <?foreach($arResult['FILE_TYPES']['DISPLAY_VALUE'] as $value):?>
      <option value="<?=$value;?>"><?=$value;?></option>
    <?endforeach;?>
   </select>
<?endif;?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question