Korusol
8/30/2016 - 7:34 AM

автотранслит символьного кода

автотранслит символьного кода

<?php
if(!CModule::IncludeModule("iblock"))
{
	echo "Error with iblock module!";
	die;
}
$arParams['IBLOCK_ID'] = 59;
$arParams['LIST_CNT'] = 59;
$arParams['TYPE_WORK'] = 'element'; // {section | element}


$arOrder = array(
	"sort" => "inc",
);

$arFilter = array(
	"IBLOCK_ID" => $arParams['IBLOCK_ID'],
	"CODE" => false
);

$arTransParams = array(
	"max_len" => 100,
	"change_case" => 'L',
	"replace_space" => '-',
	"replace_other" => '',
	"delete_repeat_replace" => true
);

if($arParams['TYPE_WORK'] == 'section'){
	//for SECTIONS
	$db_elemens = CIBlockSection::GetList($arOrder, $arFilter, false);
	$db_elemens->NavStart($arParams['LIST_CNT']);
	echo '<pre>';
	while($ar_res = $db_elemens->GetNext())
	{
		$transName = CUtil::translit(htmlspecialchars_decode($ar_res["NAME"]), "ru", $arTransParams);
		$arPropArray = Array( "CODE" => $transName );

		$el = new CIBlockSection;
		$res = $el->Update($ar_res["ID"], $arPropArray);
		echo "result for <b>".$ar_res["NAME"]."</b> is <b>".$transName.'</b>'.($res?" and OK":" and failed")."\r\n";
	}
	echo '</pre>';
}elseif($arParams['TYPE_WORK'] == 'element'){
	// for ELEMENTS
	$db_elemens = CIBlockElement::GetList($arOrder, $arFilter, false, array("nTopCount" => $arParams['LIST_CNT']));

	$i = 0;
	echo '<pre>';
	while($obElement = $db_elemens->GetNextElement())
	{
		$ar_res = $obElement->GetFields();

		$transName = CUtil::translit(htmlspecialchars_decode($ar_res["NAME"]), "ru", $arTransParams);
		$arPropArray = Array( "CODE" => $transName, );

		$el = new CIBlockElement;
		$res = $el->Update($ar_res["ID"], $arPropArray);
		echo "result for <b>".$ar_res["NAME"]."</b> is <b>".$transName.'</b>'.($res?" and OK":" and failed")."\r\n";
	}
	echo '</pre>';
}