Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 1 | Rev 17002 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Plugin;
6
 
7
use Laminas\Mvc\Controller\Plugin\AbstractPlugin;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Authentication\AuthenticationService;
10
use LeadersLinked\Model\Device;
11
use LeadersLinked\Mapper\DeviceMapper;
12
use LeadersLinked\Model\UserType;
13
use LeadersLinked\Mapper\CompanyMapper;
14
 
15
 
16
class CurrentUserPlugin extends AbstractPlugin
17
{
18
 
19
    /**
20
     *
21
     * @var AuthenticationService
22
     */
23
    protected $auth;
24
 
25
    /**
26
     *
27
     * @var boolean
28
     */
29
    protected $hasIdentity;
30
 
31
 
32
    /**
33
     *
15342 efrain 34
     * @var boolean
35
     */
36
    protected $hasImpersonate;
37
 
38
 
39
    /**
40
     *
1 www 41
     * @return \LeadersLinked\Model\User
42
     */
43
    protected $user;
44
 
45
 
15342 efrain 46
 
47
    /**
48
     *
49
     * @return \LeadersLinked\Model\User
50
     */
51
    protected $impersonateUser;
52
 
53
 
1 www 54
    /***
55
     *
56
     * @var \LeadersLinked\Model\Company
57
     */
58
    protected $company;
59
 
60
 
61
    /**
62
     *
63
     * @param AdapterInterface $adapter
64
     */
65
    public function __construct($adapter)
66
    {
67
        $this->auth = new \Laminas\Authentication\AuthenticationService();
15342 efrain 68
        $this->impersonateUser = null;
1 www 69
        $this->hasIdentity = false;
15342 efrain 70
        $this->hasImpersonate = false;
71
 
1 www 72
        if($this->auth->hasIdentity()) {
73
            $identity = $this->auth->getIdentity();
74
 
75
            $userMapper     = \LeadersLinked\Mapper\UserMapper::getInstance($adapter);
76
            $this->user     = $userMapper->fetchOne($identity['user_id']);
77
 
78
            if($this->user) {
79
                $this->hasIdentity = true;
80
 
15342 efrain 81
                if($this->user->impersonate_user_id) {
82
                    $this->hasImpersonate = true;
83
                    $this->impersonateUser = $userMapper->fetchOne($this->user->impersonate_user_id);
84
                }
85
 
86
 
1 www 87
                if($identity['company_id']) {
88
                    $companyMapper = CompanyMapper::getInstance($adapter);
89
                    $this->company = $companyMapper->fetchOne($identity['company_id']);
90
                }
91
            }
92
        }
93
    }
94
 
95
 
96
    /**
97
     *
98
     * @return \LeadersLinked\Model\User
99
     */
100
    public function getUser()
101
    {
102
 
103
        return $this->user;
104
    }
105
 
15342 efrain 106
 
107
 
1 www 108
    /**
15342 efrain 109
     *
110
     * @return \LeadersLinked\Model\User
1 www 111
     */
15342 efrain 112
    public function getImpersonateUser()
1 www 113
    {
15342 efrain 114
 
115
        return $this->impersonateUser;
1 www 116
    }
15342 efrain 117
 
1 www 118
 
119
 
15342 efrain 120
     /**
1 www 121
     *
122
     * @return int
123
     */
124
    public function getUserId()
125
    {
126
        if($this->hasIdentity) {
15342 efrain 127
            if($this->hasImpersonate) {
128
                return $this->impersonateUser->id;
129
            } else {
130
                return $this->user->id;
131
            }
1 www 132
        } else {
133
            return 0;
134
        }
135
    }
136
 
137
 
138
    /**
139
     * @return string
140
     */
141
    public function getUserTypeId()
142
    {
143
        if($this->hasIdentity) {
15342 efrain 144
            if($this->hasImpersonate) {
145
                return $this->impersonateUser->usertype_id;
146
            } else {
147
                return $this->user->usertype_id;
148
            }
1 www 149
        } else {
150
            return UserType::GUEST;
151
        }
152
    }
153
 
15342 efrain 154
    /**
155
     *
156
     * @return boolean
157
     */
158
    public function hasImpersonate()
159
    {
160
        return $this->hasImpersonate;
161
    }
1 www 162
 
15342 efrain 163
 
164
 
1 www 165
    /**
166
     *
15342 efrain 167
     * @return boolean
168
     */
169
    public function hasIdentity()
170
    {
171
        return $this->hasIdentity;
172
    }
173
 
174
 
175
    /**
176
     *
1 www 177
     * @return \LeadersLinked\Model\Company
178
     */
179
    public function getCompany()
180
    {
181
        return $this->company;
182
    }
183
 
184
    public function getCompanyId()
185
    {
186
        if($this->company) {
187
 
188
        } else {
189
            return 0;
190
        }
191
    }
15342 efrain 192
 
1 www 193
 
194
    public function clearIdentity()
195
    {
196
        $this->auth->clearIdentity();
197
    }
198
 
199
 
200
}