CCrmMeasureRestProxy::innerAdd

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmMeasureRestProxy
  4. innerAdd
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmMeasureRestProxy
  • Вызов: CCrmMeasureRestProxy::innerAdd
protected function innerAdd(&$fields, &$errors, array $params = null)
{
	/** @global CMain $APPLICATION */
	global $APPLICATION;

	if (!CModule::IncludeModule('catalog'))
	{
		$errors[] = 'The Commercial Catalog module is not installed.';
		return false;
	}

	$userPermissions = CCrmAuthorizationHelper::GetUserPermissions();
	if (!CCrmAuthorizationHelper::CheckConfigurationUpdatePermission($userPermissions))
	{
		$errors[] = 'Access denied.';
		return false;
	}
	unset($userPermissions);

	$code = isset($fields['CODE']) ? trim($fields['CODE']) : '';
	if($code === '')
	{
		$errors[] = 'Please specify a code for the unit of measurement. The code should be a positive integer number.';
		return false;
	}
	elseif(preg_match('/^[0-9]+$/', $code) !== 1)
	{
		$errors[] = 'The CODE of unit of measurement can include only numbers.';
		return false;
	}
	else
	{
		$code = (int)$code;
	}

	$title = isset($fields['MEASURE_TITLE']) ? trim($fields['MEASURE_TITLE']) : '';
	if($title == '')
	{
		$errors[] = 'Please provide the name for the unit of measurement.';
		return false;
	}

	$result = CCatalogMeasure::getList(array(), array('=CODE' => $code));
	if(is_array($result->Fetch()))
	{
		$errors[] = 'A unit of measurement with the CODE "'.$code.'" already exists.';
		return false;
	}
	else
	{
		$result = CCatalogMeasure::add($fields);
		if($result <= 0)
		{
			if($exception = $APPLICATION->GetException())
				$errors[] = $exception->GetString();
			else
				$errors[] = 'Unknown error when creating unit of measurement.';
			return false;
		}
	}

	return $result;
}

Добавить комментарий