Rev 1 | Rev 17002 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpdeclare(strict_types=1);namespace LeadersLinked\Plugin;use Laminas\Mvc\Controller\Plugin\AbstractPlugin;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Authentication\AuthenticationService;use LeadersLinked\Model\Device;use LeadersLinked\Mapper\DeviceMapper;use LeadersLinked\Model\UserType;use LeadersLinked\Mapper\CompanyMapper;class CurrentUserPlugin extends AbstractPlugin{/**** @var AuthenticationService*/protected $auth;/**** @var boolean*/protected $hasIdentity;/**** @var boolean*/protected $hasImpersonate;/**** @return \LeadersLinked\Model\User*/protected $user;/**** @return \LeadersLinked\Model\User*/protected $impersonateUser;/***** @var \LeadersLinked\Model\Company*/protected $company;/**** @param AdapterInterface $adapter*/public function __construct($adapter){$this->auth = new \Laminas\Authentication\AuthenticationService();$this->impersonateUser = null;$this->hasIdentity = false;$this->hasImpersonate = false;if($this->auth->hasIdentity()) {$identity = $this->auth->getIdentity();$userMapper = \LeadersLinked\Mapper\UserMapper::getInstance($adapter);$this->user = $userMapper->fetchOne($identity['user_id']);if($this->user) {$this->hasIdentity = true;if($this->user->impersonate_user_id) {$this->hasImpersonate = true;$this->impersonateUser = $userMapper->fetchOne($this->user->impersonate_user_id);}if($identity['company_id']) {$companyMapper = CompanyMapper::getInstance($adapter);$this->company = $companyMapper->fetchOne($identity['company_id']);}}}}/**** @return \LeadersLinked\Model\User*/public function getUser(){return $this->user;}/**** @return \LeadersLinked\Model\User*/public function getImpersonateUser(){return $this->impersonateUser;}/**** @return int*/public function getUserId(){if($this->hasIdentity) {if($this->hasImpersonate) {return $this->impersonateUser->id;} else {return $this->user->id;}} else {return 0;}}/*** @return string*/public function getUserTypeId(){if($this->hasIdentity) {if($this->hasImpersonate) {return $this->impersonateUser->usertype_id;} else {return $this->user->usertype_id;}} else {return UserType::GUEST;}}/**** @return boolean*/public function hasImpersonate(){return $this->hasImpersonate;}/**** @return boolean*/public function hasIdentity(){return $this->hasIdentity;}/**** @return \LeadersLinked\Model\Company*/public function getCompany(){return $this->company;}public function getCompanyId(){if($this->company) {} else {return 0;}}public function clearIdentity(){$this->auth->clearIdentity();}}