• Модуль: documentgenerator
  • Путь к файлу: ~/bitrix/modules/documentgenerator/lib/controller/region.php
  • Класс: BitrixDocumentGeneratorControllerRegion
  • Вызов: Region::updateAction
public function updateAction($id, array $fields)
{
	$converter = new Converter(Converter::TO_UPPER | Converter::KEYS | Converter::TO_SNAKE);
	$regionData = $converter->process($fields);

	$result = RegionTable::update($id, $regionData);
	if($result->isSuccess())
	{
		$phrases = $fields['phrases'];
		if(is_array($phrases))
		{
			$phraseIds = [];
			$phraseList = RegionPhraseTable::getList(['filter' => ['=REGION_ID' => $id]]);
			while($phrase = $phraseList->fetch())
			{
				$phraseIds[$phrase['CODE']] = $phrase['ID'];
			}
			foreach($phrases as $code => $text)
			{
				$phraseData = [
					'REGION_ID' => $id,
					'CODE' => $code,
					'PHRASE' => $text,
				];
				if(isset($phraseIds[$code]))
				{
					$phraseResult = RegionPhraseTable::update($phraseIds[$code], $phraseData);
				}
				else
				{
					$phraseResult = RegionPhraseTable::add($phraseData);
				}
				if(!$phraseResult->isSuccess())
				{
					$this->errorCollection->add($phraseResult->getErrors());
				}
			}
		}
		return $this->getAction($id);
	}
	else
	{
		$this->errorCollection->add($result->getErrors());
		return null;
	}
}