• Модуль: rest
  • Путь к файлу: ~/bitrix/modules/rest/classes/general/restentity.php
  • Класс: CBitrixRestEntity
  • Вызов: CBitrixRestEntity::entityItemPropertyAdd
static function entityItemPropertyAdd($params, $n, $server)
{
	if(self::checkItemPropertyParams($params))
	{
		if(!self::checkItemProperty($params['PROPERTY'], $params['ENTITY'], $server))
		{
			if(!isset($params['PROPERTY']))
			{
				throw new BitrixMainArgumentNullException('PROPERTY');
			}

			$arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
			if($arIBlock)
			{
				if(CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'iblock_edit'))
				{
					$arFields = array(
						"IBLOCK_ID" => $arIBlock['ID'],
						"CODE" => $params['PROPERTY'],
						"NAME" => $params['NAME'],
						"ACTIVE" => "Y",
						"PROPERTY_TYPE" => $params['TYPE'],
						"SORT" => $params['SORT'],
					);

					if($params['TYPE'] == 'L')
					{
						throw new BitrixMainNotSupportedException(self::ERROR_UNSUPPORTED_PROPERTY_TYPE);
					}

					$ibp = new CIBlockProperty;
					$propId = $ibp->Add($arFields);
					if($propId <= 0)
					{
						throw new RestException($ibp->LAST_ERROR, RestException::ERROR_CORE);
					}

					//$server->setStatus(CRestServer::STATUS_CREATED);
					return true;
				}
				else
				{
					throw new AccessException();
				}
			}
			else
			{
				throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
			}
		}
		else
		{
			throw new RestException ('Property already exists', self::ERROR_PROPERTY_ALREADY_EXISTS);
		}
	}
}