HasAccess trait
Phproberto\Joomla\Entity\Core\Traits\HasAccess
Trait for classes that have an
access
column to specify the entity access view level.
Index
Requirements
Class expects that the entity database row includes an access
column. If your entity uses a different column to store the access you can include override the getColumnAccess()
method like:
/**
* Get the name of the column that stores access.
*
* @return string
*/
protected function getColumnAccess()
{
return 'access_level';
}
Usage
To start using this trait you have to include in your class the line:
use Phproberto\Joomla\Entity\Core\Traits\HasAccess;
And then include the use
statement inside the class like:
class Article extends Entity
{
use HasAccess;
}
Methods
When implementing this trait you can start using following methods in your entity:
access()
Get access level required for this entity.
Parameters:
None
Returns:
integer
Examples:
if (0 === $article->access())
{
// 0 is usually public access level but this is a shit check
}
canAccess($reload = false)
Check if current/active user can access this entity.
Parameters:
boolean
$reload (optional): Force to recheck access for current user. Useful in case you have done some changes to the entity.
Returns:
boolean
Examples:
// Use a different link based on access
$link = $article->canAccess() ? $article->getLink() : JRoute::_('index.php?option=com_users&view=login');
// Do something based on the access
if ($article->canAccess())
{
// Show/do something
}