• Модуль: pull
  • Путь к файлу: ~/bitrix/modules/pull/lib/rest.php
  • Класс: BitrixPullRest
  • Вызов: Rest::applicationEventAdd
static function applicationEventAdd($params, $n, CRestServer $server)
{
	$params = array_change_key_case($params, CASE_UPPER);

	$clientId = $server->getClientId();
	if (!$clientId)
	{
		throw new BitrixRestRestException("Get access to application config available only for application authorization.", "WRONG_AUTH_TYPE", CRestServer::STATUS_FORBIDDEN);
	}

	global $USER;

	if (self::isAdmin())
	{
		$users = Array();
		if (is_string($params['USER_ID']))
		{
			$params['USER_ID'] = CUtil::JsObjectToPhp($params['USER_ID']);
		}

		if (!isset($params['USER_ID']))
		{
			$users = [Event::SHARED_CHANNEL];
		}
		else if (is_array($params['USER_ID']))
		{
			foreach ($params['USER_ID'] as $userId)
			{
				$userId = intval($userId);
				if ($userId > 0)
				{
					$users[$userId] = $userId;
				}
			}
			$users = array_values($users);
		}
		else
		{
			$users = (int)$params['USER_ID'];
		}
	}
	else
	{
		if (isset($params['USER_ID']))
		{
			if ($params['USER_ID'] === $USER->GetId())
			{
				$users = $USER->GetId();
			}
			else
			{
				throw new BitrixRestRestException("Only admin can send notifications to other channels", "USER_ID_ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
			}
		}
		else
		{
			$users = [Event::SHARED_CHANNEL];
		}
	}

	if (isset($params['MODULE_ID']))
	{
		$moduleId = $params['MODULE_ID'];
		if (preg_match("/[^a-z0-9._]/", $moduleId))
		{
			throw new BitrixRestRestException("Module ID format error", "MODULE_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
		}
	}
	else
	{
		$moduleId = 'application';
	}

	$command = $params['COMMAND'];
	if (!preg_match("/^[dw:_|.-]+$/", $command))
	{
		throw new BitrixRestRestException("Command format error", "COMMAND_ERROR", CRestServer::STATUS_WRONG_REQUEST);
	}

	if (isset($params['PARAMS']))
	{
		if (is_string($params['PARAMS']))
		{
			$params['PARAMS'] = CUtil::JsObjectToPhp($params['PARAMS']);
		}

		$eventParams = $params['PARAMS'];
		if (!is_array($eventParams))
		{
			throw new BitrixRestRestException("Params format error", "PARAMS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
		}
	}
	else
	{
		$eventParams = [];
	}

	Event::add($users, array(
		'module_id' => $moduleId,
		'command' => $command,
		'params' => $eventParams,
	), $clientId);

	return true;
}