M
M
Maxim Volkov2019-09-26 14:26:15
1C-Bitrix
Maxim Volkov, 2019-09-26 14:26:15

Bitrix API - how to get the values ​​of a multiple property of the file type for displaying images for a gallery?

The task is to create galleries on the site using the BITRIX API. Infoblock created with multiple type property - file "MORE_PHOTO" . Each image also has a description.
Using the CIBlockElement::GetList method , I get a list of infoblock elements, but I can't get the paths to files from the MORE_PHOTO multiple property, and I don't know how to describe them.
I'm trying to use:

<?php if(CModule::IncludeModule('iblock'))
  {
    $res = CIBlockElement::GetList(
      array("SORT"=>"ASC"), 
      array("IBLOCK_ID"=>4,"ACTIVE"=>"Y"), 
      false, 
      false, 
      array("NAME","PREVIEW_TEXT", "PROPERTY_MORE_PHOTO")
    );
    while($arr = $res->GetNext())
    {		
      $arrGalleries[] = $arr;
    }
  }	
?>

However, the resulting array $arrGalleries[] receives data for each picture, for example, a fragment:
[PROPERTY_MORE_PHOTO_VALUE] => 574
[~PROPERTY_MORE_PHOTO_VALUE] => 574
[PROPERTY_MORE_PHOTO_VALUE_ID] => 298
[~PROPERTY_MORE_PHOTO_VALUE_ID] => 298

What can be done about it?
How to extract elements from an infoblock with values ​​from a multiple property, paths and descriptions for image files?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VicTHOR, 2019-09-26
@voland700

$res = CIBlockElement::GetList(
    array("SORT"=>"ASC"), 
    array("IBLOCK_ID"=>4,"ACTIVE"=>"Y"), 
    false, 
    false, 
    array("ID", "IBLOCK_ID")
);
while ($arr = $res->GetNextElement()) {
    $fields = $arr->GetFields();
    $arrGalleries[$fields['ID']] = $arr->GetProperty('MORE_PHOTO');
}

A
Alexander, 2019-09-26
Madzhugin @Suntechnic

if(CModule::IncludeModule('iblock'))
  {
    $res = CIBlockElement::GetList(
      array("SORT"=>"ASC"), 
      array("IBLOCK_ID"=>4,"ACTIVE"=>"Y"), 
      false, 
      false, 
      array("NAME","PREVIEW_TEXT", "PROPERTY_MORE_PHOTO")
    );
    while($arr = $res->GetNext())
    {
      $arr['PROPERTY_MORE_PHOTO_VALUE'] = \CFile::GetFileArray($arr['PROPERTY_MORE_PHOTO_VALUE']);
      $arrGalleries[] = $arr;
    }
  }

And also, apparently, you have IB 1.0. Go to the infoblock settings and look at the "Property values ​​are stored" value. Most likely there is "in the general table (by default)" and below there is a link "change the storage location of properties" - click it. After that, you will get rid of duplicate elements, and PROPERTY_MORE_PHOTO_VALUE will become an array, change this part accordingly:
$arr['PROPERTY_MORE_PHOTO_VALUE'] = \CFile::GetFileArray($arr['PROPERTY_MORE_PHOTO_VALUE']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question