protected function _scope($from, $to, $action)
{
if ($action == self::ACT_CONVERT_TO_OBJECT) {
$to->scope = $from->getScope();
} else {
if ($action == self::ACT_CONVERT_TO_ENTITY) {
if (empty($from->scope)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid scope value");
}
switch ($from->scope) {
case ScopeInterface::SCOPE_SCALR:
$to->accountId = null;
$to->envId = null;
break;
case ScopeInterface::SCOPE_ACCOUNT:
$to->accountId = $this->controller->getUser()->getAccountId();
$to->envId = null;
break;
case ScopeInterface::SCOPE_ENVIRONMENT:
$to->accountId = $this->controller->getUser()->getAccountId();
$to->envId = $this->controller->getEnvironment()->id;
break;
default:
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Unexpected scope value");
}
} else {
if ($action == self::ACT_GET_FILTER_CRITERIA) {
if (empty($from->scope)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid scope value");
}
switch ($from->scope) {
case ScopeInterface::SCOPE_SCALR:
return [['$or' => [['envId' => null], ['envId' => 0]]], ['accountId' => null]];
case ScopeInterface::SCOPE_ACCOUNT:
return [['accountId' => $this->controller->getUser()->getAccountId()], ['envId' => null]];
case ScopeInterface::SCOPE_ENVIRONMENT:
return [['envId' => $this->controller->getEnvironment()->id]];
default:
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Unexpected scope value");
}
}
}
}
}