Last active
September 10, 2015 12:10
-
-
Save di7spider/c541b4d67a0fdc2fd5a0 to your computer and use it in GitHub Desktop.
1C Bitrix :: Генерация символьных кодов (UF_CODE) на основе имени (UF_NAME) для H-Инфоблоков
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
include $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php'; | |
use | |
\Bitrix\Highloadblock\HighloadBlockTable as HighloadBlockTable; | |
array_map('\Bitrix\Main\Loader::includeModule', | |
Array( | |
'iblock', | |
'highloadblock' | |
) | |
); | |
$interateTables = HighloadBlockTable::getList( | |
Array() | |
); | |
while($ar = $interateTables-> fetch() ){ | |
$arListAllHB[ $ar['ID'] ] = $ar; | |
} | |
$db = CUserTypeEntity::GetList( | |
array(), | |
array() | |
); | |
$fields = Array( | |
'UF_CODE', | |
'UF_NAME' | |
); | |
while( $ar = $db-> GetNext(true, false) ){ | |
if( in_array($ar['FIELD_NAME'], $fields) && | |
preg_match('/HLBLOCK_(\d+)/', $ar['ENTITY_ID'], $detect) ){ | |
$arListHB[ $ar['FIELD_NAME'] ][ (int) $detect[1] ] = true; | |
} | |
} | |
foreach($arListAllHB as $ID => $params){ | |
foreach($fields as $name){ | |
if( !$arListHB[$name][$ID] ){ | |
$db = new CUserTypeEntity; | |
$db-> Add( | |
Array( | |
'ENTITY_ID' => 'HLBLOCK_'.$ID, | |
'FIELD_NAME' => $name, | |
'SORT' => 10, | |
'USER_TYPE_ID' => 'string' | |
) | |
); | |
} | |
} | |
$hlentity = HighloadBlockTable::compileEntity($params); | |
$HB = $params['NAME']."Table"; | |
$interate = $HB::getList( | |
Array( | |
'select' => array_merge( | |
Array( | |
'ID' | |
), | |
$fields | |
) | |
) | |
); | |
while( $ar = $interate-> fetch() ){ | |
$code = trim($ar['UF_CODE']); | |
if( empty($code) && !empty($ar['UF_NAME']) ){ | |
$code = strtolower( | |
trim( | |
CUtil::translit( | |
$ar['UF_NAME'], | |
"ru", | |
array( | |
"max_len" => 40, | |
"change_case" => true, | |
"replace_space" => '_', | |
"replace_other" => '_', | |
"delete_repeat_replace" => true, | |
) | |
), | |
"_" | |
) | |
); | |
$HB::update( | |
$ar['ID'], | |
Array( | |
'UF_CODE' => $code | |
) | |
); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment