Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/grain.iiko/lib/ |
Upload File : |
<?php namespace Grain\Iiko; use \Bitrix\Main\Localization\Loc; use \Bitrix\Main\Web\Json; Loc::loadMessages(__FILE__); class ModifierProperty { public static function GetUserTypeDescription() { return array( "PROPERTY_TYPE" =>"S", "USER_TYPE" =>"grain_iiko_modifier", "DESCRIPTION" => Loc::getMessage("GRAIN_IIKO_MODIFIER_PROPERTY_NAME"), "GetPublicViewHTML" =>array('\\Grain\\Iiko\\ModifierProperty',"GetPublicViewHTML"), "GetAdminListViewHTML" =>array('\\Grain\\Iiko\\ModifierProperty',"GetAdminListViewHTML"), "GetPropertyFieldHtml" =>array('\\Grain\\Iiko\\ModifierProperty',"GetPropertyFieldHtml"), "GetPropertyFieldHtmlMulty" => array('\\Grain\\Iiko\\ModifierProperty','GetPropertyFieldHtmlMulty'), "CheckFields" =>array('\\Grain\\Iiko\\ModifierProperty',"CheckFields"), "PrepareSettings" => array('\\Grain\\Iiko\\ModifierProperty', "PrepareSettings"), "GetSettingsHTML" => array('\\Grain\\Iiko\\ModifierProperty', "GetSettingsHTML"), "GetSearchContent" => array('\\Grain\\Iiko\\ModifierProperty', "GetSearchContent"), //"ConvertToDB" =>array('\\Grain\\Iiko\\ModifierProperty',"ConvertToDB"), //"ConvertFromDB" =>array('\\Grain\\Iiko\\ModifierProperty',"ConvertFromDB"), ); } public static function GetPublicViewHTML($arProperty, $value, $strHTMLControlName) { return ModifierPropertyBase::getViewHTML($arProperty, $value?$value["VALUE"]:null, $strHTMLControlName["VALUE"]); } public static function GetAdminListViewHTML($arProperty, $value, $strHTMLControlName) { return ModifierPropertyBase::getViewHTML($arProperty, $value?$value["VALUE"]:null, $strHTMLControlName["VALUE"]); } public static function GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName) { return ModifierPropertyBase::getEditFormHTML($arProperty, false, $value["VALUE"], $strHTMLControlName["VALUE"]);; } public static function GetPropertyFieldHtmlMulty($arProperty, $arValues, $strHTMLControlName) { $values = Array(); foreach($arValues as $intPropertyValueID => $arOneValue) $values[$intPropertyValueID] = array_key_exists("VALUE",$arOneValue)?$arOneValue["VALUE"]:$arOneValue; return ModifierPropertyBase::getEditFormHTML($arProperty, true, $values, $strHTMLControlName["VALUE"]); } public static function CheckFields($arProperty, $value) { return true; } public static function PrepareSettings($arProperty) { return array(); } public static function GetSettingsHTML($arProperty, $strHTMLControlName, $arPropertyFields) { return ''; } public static function GetSearchContent($arProperty, $value, $strHTMLControlName) { return ""; } /* public static function ConvertToDB($arProperty, $value) { if (is_array($value['VALUE']) && count($value['VALUE'])>0) { $value['VALUE'] = Json::encode($value['VALUE']); } else $value['VALUE']=''; return $value; } public static function ConvertFromDB($arProperty, $value) { if (is_string($value['VALUE']) && strlen($value['VALUE']) > 0) { try { $value['VALUE'] = Json::decode($value['VALUE']); } catch (\Exception $e) { $value['VALUE']=""; //$e->getMessage(); } } $value['VALUE'] = $value['VALUE'] ? $value['VALUE'] : array(); return $value; } */ } class ModifierPropertyBase { public static function getEditFormHTML($property, $multiple=false, $values, $name) { if(!$multiple) return; ob_start(); $jsId = md5($property['ID'].'_'.rand(1,10000000)); ?><div id="<?=$jsId?>_view"><?php $i=0; foreach($values as $valueId=>$value) { ?><?php if($i>0):?><br/><?php endif?><?=self::getViewHTML($property, $value, $name)?><?php $i++; } ?></div><?php ?><div id="<?=$jsId?>_edit" style="display: none;"><?php foreach($values as $valueId=>$value) { ?> <div> <textarea rows="10" cols="40" name="<?=$name?>[<?=$valueId?>]"><?=htmlspecialchars($value)?></textarea> </div> <?php } ?> </div><?php ?><input id="<?=$jsId?>_button_add" style="display: none;" type="button" value="<?=Loc::getMessage("GRAIN_IIKO_MODIFIER_PROPERTY_ADD")?>" onclick="if(typeof window.grain_iiko_<?=$jsId?>_count == 'undefined') window.grain_iiko_<?=$jsId?>_count = 0; else window.grain_iiko_<?=$jsId?>_count++; var newDiv = document.createElement('div'); var newTextarea = document.createElement('textarea'); newTextarea.setAttribute('name','<?=$name?>[n'+window.grain_iiko_<?=$jsId?>_count+']'); newTextarea.setAttribute('rows','10'); newTextarea.setAttribute('cols','40');newDiv.append(newTextarea); document.getElementById('<?=$jsId?>_edit').append(newDiv); "><?php ?><a id="<?=$jsId?>_button_edit" href="#" onclick="document.getElementById('<?=$jsId?>_button_edit').style.display='none';document.getElementById('<?=$jsId?>_view').style.display='none';document.getElementById('<?=$jsId?>_edit').style.display='';document.getElementById('<?=$jsId?>_button_add').style.display='';return false;"><?=Loc::getMessage("GRAIN_IIKO_MODIFIER_PROPERTY_EDIT")?></a><?php $s .= ob_get_contents(); ob_end_clean(); return $s; } public static function getViewHTML($property, $value, $name) { $s=""; if(!$value) return $s; $error = false; try { $modifier = \Bitrix\Main\Web\Json::decode(trim($value)); } catch (\Exception $e) { $error = true; //$e->getMessage(); } if(!$error) { if(is_array($modifier['m'])) // modifier { $s .= $modifier['m']['name']; if($modifier['groupId']) $s .= ' ['.($modifier['groupName']?$modifier['groupName']:$modifier['groupId']).']'; if($modifier['minAmount'] || $modifier['maxAmount']) $s .= ' ('.$modifier['minAmount'].'-'. $modifier['maxAmount'].($modifier['defaultAmount']>0?', '.Loc::getMessage('GRAIN_IIKO_MODIFIER_PROPERTY_DEFAULT_AMOUNT',array('#AMOUNT#'=>$modifier['defaultAmount'])):'').')'; if($modifier['required']) $s .= '<span style="color: #e70000">*</span>'; } elseif(is_array($modifier['s'])) // size { $s .= $modifier['s']['name']; if($modifier['price']['currentPrice']) $s .= ': '.$modifier['price']['currentPrice']; if($modifier['s']['isDefault']) $s .= ' ('.Loc::getMessage('GRAIN_IIKO_MODIFIER_PROPERTY_DEFAULT').')'; } } else { $s=Loc::getMessage('GRAIN_IIKO_MODIFIER_PROPERTY_WRONG_JSON'); } return $s; } } ?>