*/
class UserStatus extends UserAbstract
{
/**
* @var bool
*/
protected $displayConnectionLink = true;
/**
* Retourne l'instance de ce view helper.
*
* @param boolean $displayConnectionLink Inclure ou pas le lien de connexion/déconnexion ?
* @return UserStatus
*/
public function __invoke($displayConnectionLink = true)
{
$this->setDisplayConnectionLink($displayConnectionLink);
return $this;
}
/**
* Indique si le lien de connexion/déconnexion est affiché ou non
*
* @return boolean
*/
public function getDisplayConnectionLink()
{
return $this->displayConnectionLink;
}
/**
* Affiche ou non le lien de connexion/déconnexion
*
* @param boolean $displayConnectionLink
* @return UserStatus
*/
public function setDisplayConnectionLink($displayConnectionLink)
{
$this->displayConnectionLink = $displayConnectionLink;
return $this;
}
/**
* Retourne le code HTML généré par cette aide de vue.
*
* @return string
*/
public function __toString()
{
$out = $this->createStatusContainer();
if ($this->getDisplayConnectionLink()) {
$out .= " | " . $this->getView()->userConnection();
}
return $out;
}
/**
*
* @return string
*/
protected function createStatusContainer()
{
$template = '%s';
if (($identity = $this->getIdentity())) {
if (method_exists($identity, '__toString')) {
$name = "" . $identity;
}
elseif (method_exists($identity, 'getDisplayName')) {
$name = $identity->getDisplayName();
}
elseif (method_exists($identity, 'getUsername')) {
$name = $identity->getUsername();
}
elseif (method_exists($identity, 'getId')) {
$name = $identity->getId();
}
else {
$name = sprintf('???',
is_object($identity) ? " (classe " . get_class($identity) . ")" : null);
}
}
if (!isset($name) || !$name) {
$name = $this->getView()->translate("Aucun");
}
$out = sprintf($template, $name);
return $out;
}
}