Add ACL & helper methods

This commit is contained in:
Nicolas Le Goff
2013-08-25 00:09:28 +02:00
parent 7909bc5688
commit 78ee48803c
2 changed files with 91 additions and 0 deletions

View File

@@ -218,6 +218,11 @@ class User
*/
private $updated;
/**
* @var \ACL
*/
private $acl;
/**
* @return integer
*/
@@ -792,4 +797,54 @@ class User
$this->updated = $updated;
}
/**
* @param Application $app
*
* @return \ACL
*/
public function ACL(Application $app)
{
if (!$this->acl instanceof \ACL) {
$this->acl = new \ACL($this, $app);
}
return $this->acl;
}
/**
* @return boolean
*/
public function isTemplate()
{
return null !== $this->modelOf;
}
/**
* @return boolean
*/
public function isSpecial()
{
return in_array($this->login, array('invite', 'autoregister'));
}
/**
* @return string
*/
public function getDisplayName()
{
if ($this->isTemplate()) {
return sprintf(_('modele %s'), $this->getLogin());
}
if (trim($this->lastName) !== '' || trim($this->firstName) !== '') {
return $this->firstName . ('' !== $this->firstName && '' !== $this->lastName ? ' ' : '') . $this->lastName;
}
if (trim($this->email) !== '') {
return $this->email;
}
return _('Unnamed user');
}
}