public static function getAssetRules($asset, $recursive = false)
	{
		// Build the database query to get the rules for the asset.
		$model = Asset::blank();

		$db = App::get('db');
		$query = $db->getQuery()
			->select($recursive ? 'b.rules' : 'a.rules');

		$query->from($model->getTableName(), 'a');

		// If the asset identifier is numeric assume it is a primary key, else lookup by name.
		if (is_numeric($asset))
		{
			$query->whereEquals('a.id', (int) $asset);
		}
		else
		{
			$query->whereEquals('a.name', $asset);
		}

		// If we want the rules cascading up to the global asset node we need a self-join.
		if ($recursive)
		{
			$query->joinRaw($model->getTableName() . ' AS b', 'b.lft <= a.lft AND b.rgt >= a.rgt', 'left');
			$query->order('b.lft', 'asc');
		}

		$query->group($recursive ? 'b.id, b.rules, b.lft' : 'a.id, a.rules, a.lft');

		$db->setQuery($query->toString());
		$result = $db->loadColumn();

		//$result = $query->rows()->fieldsByKey('rules');

		// Get the root even if the asset is not found and in recursive mode
		if (empty($result) && $recursive)
		{
			$result = Asset::oneOrFail(Asset::getRootId());
			$result = array($result->get('rules'));
		}

		// Instantiate and return the Rules object for the asset rules.
		$rules = new Rules;
		$rules->mergeCollection($result);

		return $rules;
	}
public static function getAssetRules($asset, $recursive = false)
	{
		// Build the database query to get the rules for the asset.
		$model = Asset::blank();

		$db = App::get('db');
		$query = $db->getQuery()
			->select($recursive ? 'b.rules' : 'a.rules');

		$query->from($model->getTableName(), 'a');

		// If the asset identifier is numeric assume it is a primary key, else lookup by name.
		if (is_numeric($asset))
		{
			$query->whereEquals('a.id', (int) $asset);
		}
		else
		{
			$query->whereEquals('a.name', $asset);
		}

		// If we want the rules cascading up to the global asset node we need a self-join.
		if ($recursive)
		{
			$query->joinRaw($model->getTableName() . ' AS b', 'b.lft <= a.lft AND b.rgt >= a.rgt', 'left');
			$query->order('b.lft', 'asc');
		}

		$query->group($recursive ? 'b.id, b.rules, b.lft' : 'a.id, a.rules, a.lft');

		$db->setQuery($query->toString());
		$result = $db->loadColumn();

		//$result = $query->rows()->fieldsByKey('rules');

		// Get the root even if the asset is not found and in recursive mode
		if (empty($result) && $recursive)
		{
			$result = Asset::oneOrFail(Asset::getRootId());
			$result = array($result->get('rules'));
		}

		// Instantiate and return the Rules object for the asset rules.
		$rules = new Rules;
		$rules->mergeCollection($result);

		return $rules;
	}
public static function getAssetRules ( $ asset , $ recursive = false ) { // Build the database query to get the rules for the asset. $ model = Asset :: blank ( ) ; $ db = App :: get ( 'db' ) ; $ query = $ db -> getQuery ( ) -> select ( $ recursive ? 'b.rules' : 'a.rules' ) ; $ query -> from ( $ model -> getTableName ( ) , 'a' ) ; // If the asset identifier is numeric assume it is a primary key, else lookup by name. if ( is_numeric ( $ asset ) ) { $ query -> whereEquals ( 'a.id' , ( int ) $ asset ) ; } else { $ query -> whereEquals ( 'a.name' , $ asset ) ; } // If we want the rules cascading up to the global asset node we need a self-join. if ( $ recursive ) { $ query -> joinRaw ( $ model -> getTableName ( ) . ' AS b' , 'b.lft <= a.lft AND b.rgt >= a.rgt' , 'left' ) ; $ query -> order ( 'b.lft' , 'asc' ) ; } $ query -> group ( $ recursive ? 'b.id, b.rules, b.lft' : 'a.id, a.rules, a.lft' ) ; $ db -> setQuery ( $ query -> toString ( ) ) ; $ result = $ db -> loadColumn ( ) ; //$result = $query->rows()->fieldsByKey('rules'); // Get the root even if the asset is not found and in recursive mode if ( empty ( $ result ) && $ recursive ) { $ result = Asset :: oneOrFail ( Asset :: getRootId ( ) ) ; $ result = array ( $ result -> get ( 'rules' ) ) ; } // Instantiate and return the Rules object for the asset rules. $ rules = new Rules ; $ rules -> mergeCollection ( $ result ) ; return $ rules ; }
Method to return the Rules object for an asset.  The returned object can optionally hold
only the rules explicitly set for the asset or the summation of all inherited rules from
parent assets and explicit rules.

@param   mixed    $asset      Integer asset id or the name of the asset as a string.
@param   boolean  $recursive  True to return the rules object with inherited rules.
@return  object   Rules object for the asset.
Method to return the Rules object for an asset . The returned object can optionally hold only the rules explicitly set for the asset or the summation of all inherited rules from parent assets and explicit rules .