public getFarmRole ( string $farmRoleId, integer $farmId = null, boolean $modify = false ) : |
||
$farmRoleId | string | Numeric identifier of the Farm role |
$farmId | integer | optional Identifier of the Farm containing Farm role |
$modify | boolean | optional Flag checking write permissions |
return | Returns the Script Entity on success |
public function getFarmRole($farmRoleId, $farmId = null, $modify = false)
{
/* @var $role FarmRole */
$role = FarmRole::findPk($farmRoleId);
if (!$role) {
throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested Farm Role either does not exist or is not owned by your environment.");
}
if (isset($farmId)) {
if ($role->farmId != $farmId) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid identifier of the farm");
}
} else {
$farmId = $role->farmId;
}
$this->getFarm($farmId, $modify);
if (!$this->hasPermissions($role, $modify)) {
//Checks entity level write access permissions
throw new ApiErrorException(403, ErrorMessage::ERR_PERMISSION_VIOLATION, "Insufficient permissions");
}
return $role;
}
/** * Gets farm role from database using User's Environment * * @param int $farmRoleId The identifier of the Farm Role * @param bool $modify optional Flag checking write permissions * * @return FarmRole|null * * @throws ApiErrorException */ public function getFarmRole($farmRoleId, $modify = false) { if (empty($this->farmRoleController)) { $this->farmRoleController = $this->getContainer()->api->controller(static::$farmRoleControllerClass); } return $this->farmRoleController->getFarmRole($farmRoleId, null, $modify); }