- Модуль: documentgenerator
- Путь к файлу: ~/bitrix/modules/documentgenerator/lib/controller/numerator.php
- Класс: BitrixDocumentGeneratorControllerNumerator
- Вызов: Numerator::addAction
public function addAction(array $fields, CRestServer $restServer = null)
{
$emptyFields = $this->checkArrayRequiredParams($fields, ['name', 'template']);
if(!isset($fields['settings']) || !is_array($fields['settings']))
{
$fields['settings'] = [];
}
if(!empty($emptyFields))
{
$this->errorCollection[] = new Error('Empty required fields: '.implode(', ', $emptyFields));
return null;
}
$numerator = BitrixMainNumeratorNumerator::create();
$numerator->setConfig(array_merge($fields['settings'], [
$numerator::getType() => [
'name' => $fields['name'],
'template' => $fields['template'],
'type' => Driver::NUMERATOR_TYPE,
],
]));
$saveResult = $numerator->save();
if($saveResult->isSuccess())
{
if($restServer)
{
$restNumeratorIds = $this->getRestNumeratorIds();
$restNumeratorIds[] = $saveResult->getId();
$this->setRestNumeratorIds($restNumeratorIds);
}
return $this->getAction($numerator);
}
else
{
$this->errorCollection = $saveResult->getErrorCollection();
return null;
}
}