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