N
N
nautilus6442020-01-29 08:52:42
1C-Bitrix
nautilus644, 2020-01-29 08:52:42

Custom properties (text + file)?

Hello!

Couldn't find a suitable solution online. There is only one option when all fields of the property are of type String.

<?AddEventHandler("iblock","OnIBlockPropertyBuildList",array("Property_Service_List_Class","GetUserTypeDescription"));

class Property_Service_List_Class
{
   function GetUserTypeDescription()
   {
       return array(
           "PROPERTY_TYPE"   => "S",
           "USER_TYPE"    => "EServiceList",
           "DESCRIPTION"   => "Услуги",
           "GetPropertyFieldHtml" => array("Property_Service_List_Class","GetPropertyFieldHtml"),
           "GetPublicEditHTML"  => array("Property_Service_List_Class","GetPropertyFieldHtml"),
           "ConvertToDB"   => array("Property_Service_List_Class","ConvertToDB"),
           "ConvertFromDB"   => array("Property_Service_List_Class","ConvertFromDB"),
           "GetAdminListViewHTML" => array("Property_Service_List_Class","GetAdminListViewHTML"),
       );
   }
   function GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
   {

       $html = '';
       $html = "<table>";
       $html .= "<tr><th>Наименование</th><th>Цена</th><th>Время</th></tr>";
       $html .= "<tr>";
       $html .= '<td><input type="text" size="20" placeholder="Наименование" name="'.$strHTMLControlName['VALUE'].'[]" value="'.$value['VALUE'][0].'" /></td>';
       $html .= '<td><input type="text" size="20" placeholder="Цена" name="'.$strHTMLControlName['VALUE'].'[]" value="'.$value['VALUE'][1].'" /></td>';
       $html .= '<td><input type="file" size="20" placeholder="Время" name="'.$strHTMLControlName['VALUE'].'[]" value="'.$value['VALUE'][2].'" /></td>';
       $html .= '</tr>';
       $html .= "</table>";

       return  $html;

   }
   function ConvertToDB($arProperty, $value)
   {
       if($value['VALUE'][0]!='') {
           $value['VALUE'] = serialize($value['VALUE']);
       } else {
           $value['VALUE'] = null;
       }
       return $value;
   }
   function ConvertFromDB($arProperty, $value){
       if(strlen($value["VALUE"])>0) {
           $tmpArr = unserialize($value["VALUE"]);
           if(is_array($tmpArr) && count($tmpArr))
               $value["VALUE"] = $tmpArr;
       } else {
           $value["VALUE"] = null;
       }
       return $value;
   }
   function GetAdminListViewHTML($arProperty, $value, $strHTMLControlName) {
       if(is_array($value["VALUE"]) && count($value["VALUE"])) {
           $tmpArr = array();
           $tmpArr[] = "[".$value['VALUE'][0]."] - ".$value['VALUE'][1]." - ".$value['VALUE'][2]." - ".$value['VALUE'][3];

           return implode(" /\n",$tmpArr);
       }
       else
       {
           return htmlspecialcharsex($value["VALUE"]);
       }
   }

}


And how to add the ability to download a file and save it to the item's cards?
Doesn't work - the file is selected but not saved.
Is it possible to implement this at all, or does the property type for all fields have to be the same?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim, 2020-01-29
@Tomio

So in Bitrix there is a ready-made property of the "File" type.
5e31372f39336472030900.png
Or do you want to understand how custom properties work?

N
nautilus644, 2020-01-29
@nautilus644

I know what is.
I need that in one line - when editing an element - it would be possible to fill in two text fields + select a file. Save all this. The property must be plural, i.e. the user should be able to add many lines, each of which will be 2 text fields + file. And all this would be stored in the element card.

A
Alexander Tsymbal, 2020-01-29
@AlexanderTsymbal

It is, of course, possible to implement this. But you have to dig deep into the core. I don't think the game is worth the candle.
It is better to make a separate infoblock for this multiple property with many different fields, and when creating an element in the parent infoblock, create "child" elements in this separate infoblock, with reference to the parent element.
This solution is offered by the Bitrix developers themselves. After all, their online store is built on the principle of "Product -> Product offers". The first infoblock is the parent one, the second one is the child one. Each product can have a huge number of product offers with the necessary parameters.
Yes, these are additional queries to the database, slowing down the speed.
If everything is done correctly, then in conjunction with caching everything will work well and quickly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question