diff --git a/src/UnicaenAuth/View/Helper/UserAbstract.php b/src/UnicaenAuth/View/Helper/UserAbstract.php index 94cd8f4860b65f82d0d05b157e0704a9d27ccea4..e30f826f8dbfe7b49cd4c8b64cfabbd4e5fe4d9c 100644 --- a/src/UnicaenAuth/View/Helper/UserAbstract.php +++ b/src/UnicaenAuth/View/Helper/UserAbstract.php @@ -2,8 +2,8 @@ namespace UnicaenAuth\View\Helper; use Zend\I18n\View\Helper\AbstractTranslatorHelper; -use Zend\Authentication\AuthenticationService; use Zend\View\Exception\InvalidArgumentException; +use UnicaenAuth\Service\UserContext; /** * Classe mère des aides de vue concernant l'utilisateur connecté. @@ -12,39 +12,39 @@ use Zend\View\Exception\InvalidArgumentException; */ abstract class UserAbstract extends AbstractTranslatorHelper { - protected $authService; + protected $userContext; /** * Constructeur. * - * @param AuthenticationService $authService + * @param UserContext $userContext */ - public function __construct(AuthenticationService $authService = null) + public function __construct(UserContext $userContext = null) { - if (null !== $authService) { - $this->setAuthService($authService); + if (null !== $userContext) { + $this->setUserContext($userContext); } } /** - * Get Authentication Service. + * Get UserContext Service. * - * @return \Zend\Authentication\AuthenticationService + * @return UserContext */ - public function getAuthService() + public function getUserContext() { - return $this->authService; + return $this->userContext; } /** - * Set Authentication Service. + * Set UserContext. * - * @param \Zend\Authentication\AuthenticationService $authService + * @param UserContext $userContext * @return UserAbstract */ - public function setAuthService($authService) + public function setUserContext($userContext) { - $this->authService = $authService; + $this->userContext = $userContext; return $this; } @@ -56,12 +56,10 @@ abstract class UserAbstract extends AbstractTranslatorHelper */ public function getIdentity($preferedKey = null) { - if (!$this->getAuthService() || !$this->getAuthService()->hasIdentity()) { + if (!($identity = $this->getUserContext()->getIdentity())) { return null; } - $identity = $this->getAuthService()->getIdentity(); - if (is_array($identity)) { $keys = array('ldap', 'db'); if ($preferedKey) { diff --git a/src/UnicaenAuth/View/Helper/UserConnectionFactory.php b/src/UnicaenAuth/View/Helper/UserConnectionFactory.php index 0fb15018eddba2978e2c70e95c6479663a04cc88..ae064c469f1a5b95ca6d3e5fbd5dc49f71fb0cc7 100644 --- a/src/UnicaenAuth/View/Helper/UserConnectionFactory.php +++ b/src/UnicaenAuth/View/Helper/UserConnectionFactory.php @@ -20,8 +20,8 @@ class UserConnectionFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $helperPluginManager) { - $authService = $helperPluginManager->getServiceLocator()->get('zfcuser_auth_service'); + $authUserContext = $helperPluginManager->getServiceLocator()->get('authUserContext'); - return new UserConnection($authService); + return new UserConnection($authUserContext); } } \ No newline at end of file diff --git a/src/UnicaenAuth/View/Helper/UserCurrent.php b/src/UnicaenAuth/View/Helper/UserCurrent.php index af4b8f8a5855587b39fc6d7368652b264ebfc8a5..6b495ffcd301239561e93b0819ef0ec73d0d6ee7 100644 --- a/src/UnicaenAuth/View/Helper/UserCurrent.php +++ b/src/UnicaenAuth/View/Helper/UserCurrent.php @@ -37,13 +37,18 @@ class UserCurrent extends UserAbstract */ public function __toString() { - $id = 'user-current-info'; - $userStatusHelper = $this->getView()->plugin('userStatus'); /* @var $userStatusHelper \UnicaenAuth\View\Helper\UserStatus */ - $status = $userStatusHelper(false); - + $id = 'user-current-info'; + $userStatusHelper = $this->getView()->plugin('userStatus'); /* @var $userStatusHelper \UnicaenAuth\View\Helper\UserStatus */ + $status = $userStatusHelper(false); + $userProfileSelectable = true; + + if ($userProfileSelectable) { + $status .= sprintf(", <small>%s</small>", $this->getUserContext()->getSelectedIdentityRole()); + } + if ($this->getIdentity()) { $userProfileHelper = $this->getView()->plugin('userProfile'); /* @var $userProfileHelper \UnicaenAuth\View\Helper\UserProfile */ - $userProfileHelper->setUserProfileSelectable(); + $userProfileHelper->setUserProfileSelectable($userProfileSelectable); $userInfoHelper = $this->getView()->plugin('userInfo'); /* @var $userInfoHelper \UnicaenAuth\View\Helper\UserInfo */ diff --git a/src/UnicaenAuth/View/Helper/UserCurrentFactory.php b/src/UnicaenAuth/View/Helper/UserCurrentFactory.php index 24f38cb2a1951841aa8ae4e46108f956350c97d2..e8642f6f4dc54b3d312da25e1aff594806e8070c 100644 --- a/src/UnicaenAuth/View/Helper/UserCurrentFactory.php +++ b/src/UnicaenAuth/View/Helper/UserCurrentFactory.php @@ -20,8 +20,8 @@ class UserCurrentFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $helperPluginManager) { - $authService = $helperPluginManager->getServiceLocator()->get('zfcuser_auth_service'); + $authUserContext = $helperPluginManager->getServiceLocator()->get('authUserContext'); - return new UserCurrent($authService); + return new UserCurrent($authUserContext); } } \ No newline at end of file diff --git a/src/UnicaenAuth/View/Helper/UserInfoFactory.php b/src/UnicaenAuth/View/Helper/UserInfoFactory.php index 230bcd93991692fcfae99548d94cb3ff1040e030..5852ec572cf22aa789b1ec0023a562f824311162 100644 --- a/src/UnicaenAuth/View/Helper/UserInfoFactory.php +++ b/src/UnicaenAuth/View/Helper/UserInfoFactory.php @@ -20,11 +20,11 @@ class UserInfoFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $helperPluginManager) { - $serviceLocator = $helperPluginManager->getServiceLocator(); - $authService = $serviceLocator->get('zfcuser_auth_service'); - $mapper = $serviceLocator->get('ldap_structure_mapper'); + $serviceLocator = $helperPluginManager->getServiceLocator(); + $authUserContext = $serviceLocator->get('authUserContext'); + $mapper = $serviceLocator->get('ldap_structure_mapper'); - $helper = new UserInfo($authService); + $helper = new UserInfo($authUserContext); $helper->setMapperStructure($mapper); return $helper; diff --git a/src/UnicaenAuth/View/Helper/UserProfile.php b/src/UnicaenAuth/View/Helper/UserProfile.php index 7564ec1cfa40773041456d0819b57e2af5e5d7f4..6d461db2f83a3dac6307b9589c0b42d8e76923aa 100644 --- a/src/UnicaenAuth/View/Helper/UserProfile.php +++ b/src/UnicaenAuth/View/Helper/UserProfile.php @@ -10,11 +10,6 @@ use Zend\Permissions\Acl\Role\RoleInterface; */ class UserProfile extends UserAbstract { - /** - * @var \UnicaenAuth\Service\UserContext - */ - protected $userContextService; - /** * @var bool */ @@ -93,7 +88,7 @@ class UserProfile extends UserAbstract protected function getIdentityRoles() { if (null === $this->identityRoles) { - $this->identityRoles = $this->getUserContextService()->getIdentityRoles(); + $this->identityRoles = $this->getUserContext()->getIdentityRoles(); } return $this->identityRoles; } @@ -128,26 +123,6 @@ class UserProfile extends UserAbstract return $roles; } - /** - * - * @return \UnicaenAuth\Service\UserContext - */ - public function getUserContextService() - { - return $this->userContextService; - } - - /** - * - * @param \UnicaenAuth\Service\UserContext $userContextService - * @return self - */ - public function setUserContextService(\UnicaenAuth\Service\UserContext $userContextService = null) - { - $this->userContextService = $userContextService; - return $this; - } - /** * Spécifie s'il faut afficher les profils * de l'utilisateur sous forme d'une liste déroulante ou de boutons radios, permettant @@ -161,6 +136,4 @@ class UserProfile extends UserAbstract $this->userProfileSelectable = $userProfileSelectable; return $this; } - - } \ No newline at end of file diff --git a/src/UnicaenAuth/View/Helper/UserProfileFactory.php b/src/UnicaenAuth/View/Helper/UserProfileFactory.php index 225ad963e9c073d84d22537b2d4d9acb2d9bc81c..05e7015f353415b70948824e47f566e00d4a14bf 100644 --- a/src/UnicaenAuth/View/Helper/UserProfileFactory.php +++ b/src/UnicaenAuth/View/Helper/UserProfileFactory.php @@ -20,13 +20,9 @@ class UserProfileFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $helperPluginManager) { - $serviceLocator = $helperPluginManager->getServiceLocator(); - $authService = $serviceLocator->get('zfcuser_auth_service'); - $userContextService = $serviceLocator->get('AuthUserContext'); + $serviceLocator = $helperPluginManager->getServiceLocator(); + $authUserContext = $serviceLocator->get('authUserContext'); - $helper = new UserProfile($authService); - $helper->setUserContextService($userContextService); - - return $helper; + return new UserProfile($authUserContext); } } \ No newline at end of file diff --git a/src/UnicaenAuth/View/Helper/UserProfileSelect.php b/src/UnicaenAuth/View/Helper/UserProfileSelect.php index 94e076582fd49e71bd3e60eee2b085684d869cc4..4d015cc746795cd70b84629a9269c150da309b98 100644 --- a/src/UnicaenAuth/View/Helper/UserProfileSelect.php +++ b/src/UnicaenAuth/View/Helper/UserProfileSelect.php @@ -108,7 +108,7 @@ EOS; */ protected function getSelectedIdentityRole() { - $role = $this->getUserContextService()->getSelectedIdentityRole(); + $role = $this->getUserContext()->getSelectedIdentityRole(); if ($role instanceof RoleInterface) { return $role->getRoleId(); } @@ -144,33 +144,13 @@ EOS; return $roles; } - /** - * - * @return \UnicaenAuth\Service\UserContext - */ - public function getUserContextService() - { - return $this->userContextService; - } - - /** - * - * @param \UnicaenAuth\Service\UserContext $userContextService - * @return self - */ - public function setUserContextService(\UnicaenAuth\Service\UserContext $userContextService = null) - { - $this->userContextService = $userContextService; - return $this; - } - /** * * @return array */ protected function getSelectableRoles() { - return $this->getUserContextService()->getSelectableIdentityRoles(); + return $this->getUserContext()->getSelectableIdentityRoles(); } public function setFormClass($formClass) diff --git a/src/UnicaenAuth/View/Helper/UserProfileSelectFactory.php b/src/UnicaenAuth/View/Helper/UserProfileSelectFactory.php index 76072f0734b06422b93546a4f43d006c8dbdc6e0..ab6fe27fba1a45be423fe9e5c22834a76c60c9bb 100644 --- a/src/UnicaenAuth/View/Helper/UserProfileSelectFactory.php +++ b/src/UnicaenAuth/View/Helper/UserProfileSelectFactory.php @@ -20,12 +20,8 @@ class UserProfileSelectFactory extends \UnicaenApp\View\Helper\UserProfileSelect public function createService(ServiceLocatorInterface $helperPluginManager) { $serviceLocator = $helperPluginManager->getServiceLocator(); - $authService = $serviceLocator->get('zfcuser_auth_service'); $userContextService = $serviceLocator->get('AuthUserContext'); - $helper = new UserProfileSelect($authService); - $helper->setUserContextService($userContextService); - - return $helper; + return new UserProfileSelect($userContextService); } } \ No newline at end of file diff --git a/src/UnicaenAuth/View/Helper/UserStatus.php b/src/UnicaenAuth/View/Helper/UserStatus.php index 209fc5739fe9d34f729502bb5caacc8b0ec21b8d..9257161a8626430926e12ee4e36433a0a0602ad8 100644 --- a/src/UnicaenAuth/View/Helper/UserStatus.php +++ b/src/UnicaenAuth/View/Helper/UserStatus.php @@ -84,7 +84,7 @@ class UserStatus extends UserAbstract } } - $out = sprintf('<strong>%s</strong>', $name); + $out = sprintf('<span class="glyphicon glyphicon-user"></span> <strong>%s</strong>', $name); return $out; } diff --git a/src/UnicaenAuth/View/Helper/UserStatusFactory.php b/src/UnicaenAuth/View/Helper/UserStatusFactory.php index 8c4001a9ac830249260477ba349fab11488324b1..7427c95dec90ba09c914514d2c9475487731ecef 100644 --- a/src/UnicaenAuth/View/Helper/UserStatusFactory.php +++ b/src/UnicaenAuth/View/Helper/UserStatusFactory.php @@ -20,8 +20,8 @@ class UserStatusFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $helperPluginManager) { - $authService = $helperPluginManager->getServiceLocator()->get('zfcuser_auth_service'); + $userContext = $helperPluginManager->getServiceLocator()->get('authUserContext'); - return new UserStatus($authService); + return new UserStatus($userContext); } } \ No newline at end of file