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/sproduction.datasync/lib/ |
Upload File : |
<?php /** * Utilities * * @mail support@s-production.online * @link s-production.online */ namespace SProduction\Datasync; use Bitrix\Main, Bitrix\Main\Type, Bitrix\Main\Entity, Bitrix\Main\Localization\Loc, Bitrix\Main\SiteTable, Bitrix\Sale; class Utilities { const MODULE_ID = 'sproduction.datasync'; /** * Convert encoding to UTF-8 (if needed) */ public static function convEncToUtf($value) { if ( ! \SProdDatasync::isUtf()) { $value = \Bitrix\Main\Text\Encoding::convertEncoding($value, "Windows-1251", "UTF-8"); } return $value; } /** * Convert encoding to WINDOWS-1251 (if needed) */ public static function convEncToWin($value) { if ( ! \SProdDatasync::isUtf()) { $value = \Bitrix\Main\Text\Encoding::convertEncoding($value, "UTF-8", "Windows-1251"); } return $value; } /** * Convert encoding for portal encoding */ public static function convEncForDeal($value) { return self::convEncToUtf($value); } /** * Convert encoding for site encoding */ public static function convEncForOrder($value) { return self::convEncToWin($value); } /** * Get formatted field for send file to CRM entity */ public static function getFileFieldForCrm($file_path) { $field = []; $name = pathinfo($file_path, PATHINFO_BASENAME); $data = file_get_contents($file_path); $field['fileData'] = [ $name, base64_encode($data) ]; $field['fileId'] = $file_path; return $field; } /** * Get parent iblock id */ public static function getParentCatalogIblockId($iblock_id) { $catalog_iblocks = \Bitrix\Catalog\CatalogIblockTable::getList([ 'filter' => ['IBLOCK_ID' => $iblock_id] ])->fetch(); return $catalog_iblocks['PRODUCT_IBLOCK_ID']; } /** * Convert camel case to snake case */ public static function convertCamelCaseToUpperSnakeCase($text) { $converted_text = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $text)); $converted_text = strtoupper(ucwords($converted_text, '_')); return $converted_text; } /** * Prepare image field for send to CRM */ public static function getImageFieldForCrm($file_path) { $field = []; $name = pathinfo($file_path, PATHINFO_BASENAME); $data = file_get_contents($file_path); $field['fileData'] = [ $name, base64_encode($data) ]; //$field['fileId'] = $file_path; return $field; } }