Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5205 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
use LeadersLinked\Model\CompanyUser;
7
use LeadersLinked\Mapper\Common\MapperCommon;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Log\LoggerInterface;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Db\Sql\Expression;
2085 nelberth 12
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
2086 nelberth 13
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
14
 
1 www 15
class CompanyUserMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_company_users';
18
 
19
 
20
    /**
21
     *
22
     * @var CompanyUserMapper
23
     */
24
    private static $_instance;
25
 
26
    /**
27
     *
28
     * @param AdapterInterface $adapter
29
     */
30
    private function __construct($adapter)
31
    {
32
        parent::__construct($adapter);
33
    }
34
 
35
    /**
36
     *
37
     * @param AdapterInterface $adapter
38
     * @param LoggerInterface $logger
39
     * @param int $user_id
40
     * @return \LeadersLinked\Mapper\CompanyUserMapper
41
     */
42
    public static function getInstance($adapter)
43
    {
44
        if(self::$_instance == null) {
45
            self::$_instance = new CompanyUserMapper($adapter);
46
        }
47
        return self::$_instance;
48
    }
49
 
50
    /**
7159 efrain 51
     *
52
     * @param int $company_id
53
     * @param int $user_ids
54
     * @return CompanyUser[]
55
     */
56
    public function fetchAllActivesByCompanyIdAndUserIds($company_id, $user_ids)
57
    {
58
        $prototype = new CompanyUser();
59
        $select = $this->sql->select(self::_TABLE);
60
        $select->where->equalTo('company_id', $company_id);
61
        $select->where->in('user_id', $user_ids);
62
        $select->where->in('status',[
63
            CompanyUser::STATUS_ACCEPTED,
64
            CompanyUser::STATUS_ADMIN_WILL_ADD
65
        ]);
66
 
67
        return $this->executeFetchAllObject($select, $prototype);
68
    }
69
 
70
 
71
 
72
    /**
1 www 73
     *
74
     * @param int $company_id
75
     * @return CompanyUser[]
76
     */
77
    public function fetchAllByCompanyId($company_id)
78
    {
79
        $prototype = new CompanyUser();
80
        $select = $this->sql->select(self::_TABLE);
81
        $select->where->equalTo('company_id', $company_id);
82
 
83
        return $this->executeFetchAllObject($select, $prototype);
84
    }
2380 nelberth 85
 
86
    /**
87
     *
88
     * @param int $company_id
89
     * @return CompanyUser[]
90
     */
91
    public function fetchAllByCompanyIdAndNotUserId($company_id,$user_id)
92
    {
93
        $prototype = new CompanyUser();
94
        $select = $this->sql->select(self::_TABLE);
95
        $select->where->equalTo('company_id', $company_id);
96
        $select->where->notEqualTo('user_id', $user_id);
97
        $select->where->equalTo('owner', CompanyUser::OWNER_NO);
98
        return $this->executeFetchAllObject($select, $prototype);
99
    }
1 www 100
 
101
    /**
102
     *
103
     * @param int $company_id
104
     * @return CompanyUser[]
105
     */
106
    public function fetchAllByUserId($user_id)
107
    {
108
        $prototype = new CompanyUser();
109
        $select = $this->sql->select(self::_TABLE);
110
        $select->where->equalTo('user_id', $user_id);
111
 
112
        return $this->executeFetchAllObject($select, $prototype);
113
    }
114
 
115
    /**
116
     *
117
     * @param int $id
118
     * @return CompanyUser
119
     */
120
    public function fetchOne($id)
121
    {
122
        $prototype = new CompanyUser();
123
        $select = $this->sql->select(self::_TABLE);
124
        $select->where->equalTo('id', $id);
125
 
126
        return $this->executeFetchOneObject($select, $prototype);
127
    }
128
 
129
    /**
130
     *
131
     * @param int $company_id
132
     * @return CompanyUser
133
     */
134
    public function fetchOwnerByCompanyId($company_id)
135
    {
136
        $prototype = new CompanyUser();
137
        $select = $this->sql->select(self::_TABLE);
138
        $select->where->equalTo('company_id', $company_id);
139
        $select->where->equalTo('owner', CompanyUser::OWNER_YES);
140
 
141
        return $this->executeFetchOneObject($select, $prototype);
142
    }
143
 
144
    /**
145
     *
146
     * @param int $company_id
147
     * @return CompanyUser
148
     */
149
    public function fetchCreatorByCompanyId($company_id)
150
    {
151
        $prototype = new CompanyUser();
152
        $select = $this->sql->select(self::_TABLE);
153
        $select->where->equalTo('company_id', $company_id);
154
        $select->where->equalTo('creator', CompanyUser::CREATOR_YES);
155
 
156
        return $this->executeFetchOneObject($select, $prototype);
157
    }
158
 
159
    /**
160
     *
161
     * @param int $company_id
162
     * @param int $user_id
163
     * @return CompanyUser
164
     */
165
    public function fetchOneByCompanyIdAndUserId($company_id, $user_id)
166
    {
167
        $prototype = new CompanyUser();
168
        $select = $this->sql->select(self::_TABLE);
169
        $select->where->equalTo('company_id', $company_id);
170
        $select->where->equalTo('user_id', $user_id);
171
 
172
       // echo $select->getSqlString($this->adapter->platform); exit;
173
 
174
        return $this->executeFetchOneObject($select, $prototype);
175
    }
176
 
5205 efrain 177
    /**
178
     *
179
     * @param int $company_id
180
     * @param int $user_id
181
     * @return CompanyUser
182
     */
183
    public function fetchOneAcceptedByCompanyIdAndUserId($company_id, $user_id)
184
    {
185
        $prototype = new CompanyUser();
186
        $select = $this->sql->select(self::_TABLE);
187
        $select->where->equalTo('company_id', $company_id);
188
        $select->where->equalTo('user_id', $user_id);
189
        $select->where->equalTo('status', CompanyUser::STATUS_ACCEPTED);
190
 
191
        // echo $select->getSqlString($this->adapter->platform); exit;
192
 
193
        return $this->executeFetchOneObject($select, $prototype);
194
    }
1 www 195
 
5205 efrain 196
 
1 www 197
    /**
198
     *
199
     * @param int $company_id
200
     * @param int $user_id
201
     * @return int
202
     */
203
    public function fetchCountOtherCompaniesByCompanyIdAndUserId($company_id, $user_id)
204
    {
205
        $prototype = new CompanyUser();
206
        $select = $this->sql->select();
207
        $select->columns(['total' => new Expression('COUNT(*)') ]);
208
        $select->from(self::_TABLE);
209
        $select->where->notEqualTo('company_id', $company_id);
210
        $select->where->equalTo('user_id', $user_id);
211
 
212
        $record = $this->executeFetchOneArray($select);
213
 
214
        return $record['total'];
215
    }
216
 
217
    /**
218
     *
219
     * @param CompanyUser $companyUser
220
     * @return boolean
221
     */
222
    public function insert($companyUser)
223
    {
224
        $hydrator = new ObjectPropertyHydrator();
225
        $values = $hydrator->extract($companyUser);
226
        $values = $this->removeEmpty($values);
227
 
228
 
229
        $insert = $this->sql->insert(self::_TABLE);
230
        $insert->values($values);
231
 
232
        $result = $this->executeInsert($insert);
233
        if($result) {
234
            $companyUser->id = $this->lastInsertId;
235
        }
236
 
237
        return $result;
238
    }
239
 
240
    /**
241
     *
242
     * @param CompanyUser $companyUser
243
     * @return boolean
244
     */
245
    public function update($companyUser)
246
    {
247
        $hydrator = new ObjectPropertyHydrator();
248
        $values = $hydrator->extract($companyUser);
249
        $values = $this->removeEmpty($values);
250
 
251
        $update = $this->sql->update(self::_TABLE);
252
        $update->set($values);
253
        $update->where->equalTo('id', $companyUser->id);
254
 
255
        return $this->executeUpdate($update);
256
    }
257
 
258
    /**
259
     *
260
     * @param int $id
261
     * @return boolean
262
     */
263
    public function delete($id)
264
    {
265
        $delete = $this->sql->select(self::_TABLE);
266
        $delete->where->equalTo('id', $id);
267
 
268
        return $this->executeDelete($delete);
269
    }
270
 
271
 
2093 nelberth 272
 
1 www 273
}