| 1 |
www |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Mapper;
|
|
|
6 |
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
8 |
use Laminas\Db\Sql\Expression;
|
|
|
9 |
use Laminas\Log\LoggerInterface;
|
|
|
10 |
|
|
|
11 |
use LeadersLinked\Model\User;
|
|
|
12 |
use LeadersLinked\Mapper\Common\MapperCommon;
|
|
|
13 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
14 |
use Laminas\Hydrator\ArraySerializableHydrator;
|
|
|
15 |
use Laminas\Paginator\Paginator;
|
|
|
16 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
17 |
use Laminas\Db\ResultSet\HydratingResultSet;
|
|
|
18 |
use LeadersLinked\Model\UserType;
|
|
|
19 |
use LeadersLinked\Model\CompanyUser;
|
|
|
20 |
use LeadersLinked\Model\CompanyMicrolearningCapsuleUser;
|
|
|
21 |
|
|
|
22 |
|
| 1665 |
nelberth |
23 |
|
| 1 |
www |
24 |
class UserMapper extends MapperCommon
|
|
|
25 |
{
|
|
|
26 |
const _TABLE = 'tbl_users';
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
*
|
|
|
30 |
* @var UserMapper
|
|
|
31 |
*/
|
|
|
32 |
private static $_instance;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
*
|
|
|
36 |
* @param AdapterInterface $adapter
|
|
|
37 |
*/
|
|
|
38 |
private function __construct($adapter)
|
|
|
39 |
{
|
|
|
40 |
parent::__construct($adapter);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
*
|
|
|
45 |
* @param AdapterInterface $adapter
|
|
|
46 |
* @return UserMapper
|
|
|
47 |
*/
|
|
|
48 |
public static function getInstance($adapter)
|
|
|
49 |
{
|
|
|
50 |
if(self::$_instance == null) {
|
|
|
51 |
self::$_instance = new UserMapper($adapter);
|
|
|
52 |
}
|
|
|
53 |
return self::$_instance;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
*
|
|
|
58 |
* @param string $uuid
|
|
|
59 |
* @return User
|
|
|
60 |
*/
|
|
|
61 |
public function fetchOneByUuid($uuid)
|
|
|
62 |
{
|
|
|
63 |
$prototype = new User();
|
|
|
64 |
$select = $this->sql->select(self::_TABLE);
|
|
|
65 |
$select->where->equalTo('uuid', $uuid);
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
*
|
|
|
73 |
* @param int $id
|
|
|
74 |
* @return User
|
|
|
75 |
*/
|
|
|
76 |
public function fetchOne($id)
|
|
|
77 |
{
|
|
|
78 |
$prototype = new User();
|
|
|
79 |
$select = $this->sql->select(self::_TABLE);
|
|
|
80 |
$select->where->equalTo('id', $id);
|
|
|
81 |
|
|
|
82 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
83 |
}
|
|
|
84 |
|
| 1271 |
nelberth |
85 |
public function fetchOneRelation($id)
|
|
|
86 |
{
|
|
|
87 |
$prototype = new User();
|
|
|
88 |
$select = $this->sql->select(self::_TABLE);
|
|
|
89 |
$select->where->equalTo('id', $id);
|
|
|
90 |
|
|
|
91 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
|
| 1 |
www |
95 |
/**
|
|
|
96 |
*
|
|
|
97 |
* @param string $email
|
|
|
98 |
* @return void|User
|
|
|
99 |
*/
|
|
|
100 |
public function fetchOneByEmail($email)
|
|
|
101 |
{
|
|
|
102 |
$prototype = new User();
|
|
|
103 |
$select = $this->sql->select(self::_TABLE);
|
|
|
104 |
$select->where->equalTo('email', $email);
|
|
|
105 |
|
|
|
106 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
107 |
|
|
|
108 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
*
|
|
|
113 |
* @param string $password_reset_key
|
|
|
114 |
* @return void|User
|
|
|
115 |
*/
|
|
|
116 |
public function fetchOneByPasswordResetKey($password_reset_key)
|
|
|
117 |
{
|
|
|
118 |
$prototype = new User();
|
|
|
119 |
$select = $this->sql->select(self::_TABLE);
|
|
|
120 |
$select->where->equalTo('password_reset_key', $password_reset_key);
|
|
|
121 |
|
|
|
122 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
/**
|
|
|
126 |
*
|
|
|
127 |
* @param string $activation_key
|
|
|
128 |
* @return void|User
|
|
|
129 |
*/
|
|
|
130 |
public function fetchOneByActivationKey($activation_key)
|
|
|
131 |
{
|
|
|
132 |
$prototype = new User();
|
|
|
133 |
$select = $this->sql->select(self::_TABLE);
|
|
|
134 |
$select->where->equalTo('activation_key', $activation_key);
|
|
|
135 |
|
|
|
136 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
/**
|
|
|
142 |
*
|
|
|
143 |
* @param string $keyword
|
|
|
144 |
* @param int $current_user
|
|
|
145 |
* @return User[]
|
|
|
146 |
*/
|
|
|
147 |
public function fetchAllByKeyword($keyword, $current_user = 0)
|
|
|
148 |
{
|
|
|
149 |
|
|
|
150 |
$prototype = new User();
|
|
|
151 |
|
|
|
152 |
$select = $this->sql->select(self::_TABLE);
|
|
|
153 |
|
|
|
154 |
$select->where->equalTo('status', User::STATUS_ACTIVE);
|
|
|
155 |
$select->where->notEqualTo('id', $current_user);
|
|
|
156 |
$select->where->and->nest()
|
|
|
157 |
->like('first_name', '%' . $keyword . '%')
|
|
|
158 |
->or->like('last_name', '%' . $keyword . '%')
|
|
|
159 |
->or->like(new Expression("CONCAT(first_name,' ',last_name)"), '%'. $keyword . '%')
|
|
|
160 |
->unnest();
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
/**
|
|
|
167 |
*
|
|
|
168 |
* @param int[] $ids
|
|
|
169 |
* @param int $current_user
|
|
|
170 |
* @param string $status
|
|
|
171 |
* @return User[]
|
|
|
172 |
*/
|
|
|
173 |
public function fetchAllByIds($ids, $current_user = 0, $status = User::STATUS_ACTIVE)
|
|
|
174 |
{
|
|
|
175 |
|
|
|
176 |
$prototype = new User();
|
|
|
177 |
$select = $this->sql->select(self::_TABLE);
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
$select->where->equalTo('status', User::STATUS_ACTIVE);
|
| 630 |
efrain |
181 |
$select->where->and->in('id',$ids);
|
| 1 |
www |
182 |
|
|
|
183 |
if($current_user) {
|
|
|
184 |
$select->where->and->notEqualTo('id ', $current_user);
|
|
|
185 |
}
|
| 630 |
efrain |
186 |
$select->order(['first_name ASC', 'last_name ASC', 'email ASC']);
|
| 1 |
www |
187 |
|
|
|
188 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
/**
|
|
|
193 |
*
|
|
|
194 |
* @return User[]
|
|
|
195 |
*/
|
|
|
196 |
public function fetchAllByActives()
|
|
|
197 |
{
|
|
|
198 |
|
|
|
199 |
$prototype = new User();
|
|
|
200 |
$select = $this->sql->select(self::_TABLE);
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
$select->where->equalTo('status', User::STATUS_ACTIVE);
|
|
|
204 |
$select->where->equalTo('email_verified',User::EMAIL_VERIFIED_YES);
|
|
|
205 |
|
| 646 |
efrain |
206 |
$select->order(['first_name DESC, last_name DESC, email_DESC']);
|
|
|
207 |
|
| 1 |
www |
208 |
|
|
|
209 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
/**
|
|
|
213 |
*
|
| 646 |
efrain |
214 |
* @param int $company_id
|
|
|
215 |
* @return array
|
|
|
216 |
*/
|
|
|
217 |
public function fetchAllByCompanyId($company_id)
|
|
|
218 |
{
|
|
|
219 |
|
|
|
220 |
$prototype = new User();
|
|
|
221 |
$select = $this->sql->select();
|
|
|
222 |
$select->from(['tb1' => self::_TABLE]);
|
|
|
223 |
$select->join(['tb2' => CompanyUserMapper::_TABLE], 'tb1.id = tb2.user_id', []);
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
$select->where->equalTo('tb2.company_id', $company_id);
|
|
|
227 |
$select->where->in('tb2.status', [CompanyUser::STATUS_ACCEPTED, CompanyUser::STATUS_ADMIN_WILL_ADD]);
|
|
|
228 |
|
|
|
229 |
$select->where->equalTo('tb1.status', User::STATUS_ACTIVE);
|
|
|
230 |
$select->where->equalTo('tb1.email_verified',User::EMAIL_VERIFIED_YES);
|
|
|
231 |
|
|
|
232 |
$select->order(['first_name DESC, last_name DESC, email_DESC']);
|
|
|
233 |
|
|
|
234 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
/**
|
|
|
238 |
*
|
| 1 |
www |
239 |
* @param int $user_id
|
|
|
240 |
* @param string $password_reset_key
|
|
|
241 |
* @return boolean
|
|
|
242 |
*/
|
|
|
243 |
public function updatePasswordResetKey($user_id, $password_reset_key)
|
|
|
244 |
{
|
|
|
245 |
$values = [
|
|
|
246 |
'password_reset_key' => $password_reset_key,
|
|
|
247 |
'password_generated_on' => date('Y-m-d H:i:s'),
|
|
|
248 |
'updated_on' => new Expression('NOW()')
|
|
|
249 |
];
|
|
|
250 |
|
|
|
251 |
$update = $this->sql->update(self::_TABLE);
|
|
|
252 |
$update->set($values);
|
|
|
253 |
$update->where->equalTo('id', $user_id);
|
|
|
254 |
|
|
|
255 |
return $this->executeUpdate($update);
|
|
|
256 |
}
|
|
|
257 |
|
| 1979 |
efrain |
258 |
|
|
|
259 |
/**
|
|
|
260 |
*
|
|
|
261 |
* @param int $user_id
|
|
|
262 |
* @param string $delete_account_key
|
|
|
263 |
* @return boolean
|
|
|
264 |
*/
|
|
|
265 |
public function updateDeleteAccountKey($user_id, $delete_account_key)
|
|
|
266 |
{
|
|
|
267 |
$values = [
|
|
|
268 |
'delete_account_key' => $delete_account_key,
|
|
|
269 |
'delete_account_generated_on' => date('Y-m-d H:i:s'),
|
|
|
270 |
'updated_on' => new Expression('NOW()')
|
|
|
271 |
];
|
|
|
272 |
|
|
|
273 |
$update = $this->sql->update(self::_TABLE);
|
|
|
274 |
$update->set($values);
|
|
|
275 |
$update->where->equalTo('id', $user_id);
|
|
|
276 |
|
|
|
277 |
return $this->executeUpdate($update);
|
|
|
278 |
}
|
|
|
279 |
|
| 1 |
www |
280 |
|
|
|
281 |
|
|
|
282 |
/**
|
|
|
283 |
*
|
|
|
284 |
* @param User $user
|
|
|
285 |
* @param string $password_hash
|
|
|
286 |
* @return boolean
|
|
|
287 |
*/
|
|
|
288 |
public function updatePassword($user, $password_hash)
|
|
|
289 |
{
|
|
|
290 |
$values = [
|
|
|
291 |
'password' => $password_hash,
|
|
|
292 |
'password_reset_key' => '',
|
|
|
293 |
'password_updated_on' => date('Y-m-d H:i:s'),
|
|
|
294 |
'login_attempt' => 0,
|
|
|
295 |
'blocked' => User::BLOCKED_NO,
|
|
|
296 |
'updated_on' => new Expression('NOW()')
|
|
|
297 |
];
|
|
|
298 |
|
|
|
299 |
$update = $this->sql->update(self::_TABLE);
|
|
|
300 |
$update->set($values);
|
|
|
301 |
$update->where->equalTo('id', $user->id);
|
|
|
302 |
|
|
|
303 |
return $this->executeUpdate($update);
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
/**
|
|
|
308 |
*
|
|
|
309 |
* @param User $user
|
|
|
310 |
* @return boolean
|
|
|
311 |
*/
|
|
|
312 |
public function unblock($user)
|
|
|
313 |
{
|
|
|
314 |
$values = [
|
|
|
315 |
'login_attempt' => 0,
|
|
|
316 |
'blocked' => User::BLOCKED_NO,
|
|
|
317 |
'updated_on' => new Expression('NOW()')
|
|
|
318 |
];
|
|
|
319 |
|
|
|
320 |
$update = $this->sql->update(self::_TABLE);
|
|
|
321 |
$update->set($values);
|
|
|
322 |
$update->where->equalTo('id', $user->id);
|
|
|
323 |
|
|
|
324 |
return $this->executeUpdate($update);
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
|
330 |
/**
|
|
|
331 |
*
|
|
|
332 |
* @param User $user
|
|
|
333 |
* @param string $one_time_password
|
|
|
334 |
* @return boolean
|
|
|
335 |
*/
|
|
|
336 |
public function updateOneTimePassword($user, $one_time_password)
|
|
|
337 |
{
|
|
|
338 |
$values = [
|
|
|
339 |
'one_time_password' => $one_time_password,
|
|
|
340 |
'updated_on' => new Expression('NOW()')
|
|
|
341 |
];
|
|
|
342 |
|
|
|
343 |
$update = $this->sql->update(self::_TABLE);
|
|
|
344 |
$update->set($values);
|
|
|
345 |
$update->where->equalTo('id', $user->id);
|
|
|
346 |
|
|
|
347 |
return $this->executeUpdate($update);
|
|
|
348 |
}
|
|
|
349 |
|
|
|
350 |
|
|
|
351 |
/**
|
|
|
352 |
*
|
|
|
353 |
* @param User $user
|
|
|
354 |
* @return boolean
|
|
|
355 |
*/
|
|
|
356 |
public function update($user)
|
|
|
357 |
{
|
|
|
358 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
359 |
$values = $hydrator->extract($user);
|
| 1979 |
efrain |
360 |
//$values = $this->removeEmpty($values);
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
unset($values['added_on']);
|
| 1 |
www |
364 |
$values['updated_on'] = new Expression('NOW()') ;
|
|
|
365 |
|
|
|
366 |
$update = $this->sql->update(self::_TABLE);
|
|
|
367 |
$update->set($values);
|
|
|
368 |
$update->where->equalTo('id',$user->id);
|
|
|
369 |
|
| 1979 |
efrain |
370 |
//echo $update->getSqlString($this->adapter->platform); exit;
|
|
|
371 |
|
| 1 |
www |
372 |
return $this->executeUpdate($update);
|
|
|
373 |
}
|
|
|
374 |
|
|
|
375 |
/**
|
|
|
376 |
*
|
|
|
377 |
* @param User $user
|
|
|
378 |
* @return boolean
|
|
|
379 |
*/
|
|
|
380 |
public function updatePrivacy($user)
|
|
|
381 |
{
|
|
|
382 |
$values = [
|
|
|
383 |
'show_in_search' => $user->show_in_search,
|
|
|
384 |
'updated_on' => new Expression('NOW()')
|
|
|
385 |
];
|
|
|
386 |
|
|
|
387 |
$update = $this->sql->update(self::_TABLE);
|
|
|
388 |
$update->set($values);
|
|
|
389 |
$update->where->equalTo('id',$user->id);
|
|
|
390 |
|
|
|
391 |
return $this->executeUpdate($update);
|
|
|
392 |
}
|
|
|
393 |
|
|
|
394 |
/**
|
|
|
395 |
*
|
|
|
396 |
* @param User $user
|
|
|
397 |
* @return boolean
|
|
|
398 |
*/
|
|
|
399 |
public function updateBasic($user)
|
|
|
400 |
{
|
|
|
401 |
$values = [
|
|
|
402 |
'first_name' => $user->first_name,
|
|
|
403 |
'last_name' => $user->last_name,
|
|
|
404 |
'phone' => $user->phone,
|
|
|
405 |
'gender' => $user->gender,
|
|
|
406 |
'updated_on' => new Expression('NOW()')
|
|
|
407 |
];
|
|
|
408 |
|
|
|
409 |
$update = $this->sql->update(self::_TABLE);
|
|
|
410 |
$update->set($values);
|
|
|
411 |
$update->where->equalTo('id',$user->id);
|
|
|
412 |
|
|
|
413 |
return $this->executeUpdate($update);
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
|
|
|
417 |
/**
|
|
|
418 |
*
|
|
|
419 |
* @param User $user
|
|
|
420 |
* @return boolean
|
|
|
421 |
*/
|
|
|
422 |
public function updateImage($user)
|
|
|
423 |
{
|
|
|
424 |
$values = [
|
|
|
425 |
'image' => $user->image,
|
|
|
426 |
'updated_on' => new Expression('NOW()')
|
|
|
427 |
];
|
|
|
428 |
|
|
|
429 |
$update = $this->sql->update(self::_TABLE);
|
|
|
430 |
$update->set($values);
|
|
|
431 |
$update->where->equalTo('id',$user->id);
|
|
|
432 |
|
|
|
433 |
return $this->executeUpdate($update);
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
/**
|
|
|
437 |
*
|
|
|
438 |
* @param User $user
|
|
|
439 |
* @return boolean
|
|
|
440 |
*/
|
|
|
441 |
public function updateLocation($user)
|
|
|
442 |
{
|
|
|
443 |
$values = [
|
|
|
444 |
'location_id' => $user->location_id,
|
|
|
445 |
'updated_on' => new Expression('NOW()')
|
|
|
446 |
];
|
|
|
447 |
|
|
|
448 |
$update = $this->sql->update(self::_TABLE);
|
|
|
449 |
$update->set($values);
|
|
|
450 |
$update->where->equalTo('id',$user->id);
|
|
|
451 |
|
|
|
452 |
return $this->executeUpdate($update);
|
|
|
453 |
}
|
|
|
454 |
|
|
|
455 |
/**
|
|
|
456 |
*
|
|
|
457 |
* @param int $user_id
|
|
|
458 |
* @return boolean
|
|
|
459 |
*/
|
|
|
460 |
public function activateAccount($user_id)
|
|
|
461 |
{
|
|
|
462 |
$values = [
|
|
|
463 |
'email_verified' => User::EMAIL_VERIFIED_YES,
|
|
|
464 |
'status' => User::STATUS_ACTIVE,
|
|
|
465 |
'activation_key' => '',
|
|
|
466 |
'updated_on' => new Expression('NOW()')
|
|
|
467 |
];
|
|
|
468 |
|
|
|
469 |
$update = $this->sql->update(self::_TABLE);
|
|
|
470 |
$update->set($values);
|
|
|
471 |
$update->where->equalTo('id', $user_id);
|
|
|
472 |
|
|
|
473 |
return $this->executeUpdate($update);
|
|
|
474 |
}
|
|
|
475 |
|
|
|
476 |
/**
|
|
|
477 |
*
|
|
|
478 |
* @param User $user
|
|
|
479 |
* @return boolean
|
|
|
480 |
*/
|
|
|
481 |
public function insert($user)
|
|
|
482 |
{
|
|
|
483 |
|
|
|
484 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
485 |
$values = $hydrator->extract($user);
|
|
|
486 |
$values = $this->removeEmpty($values);
|
|
|
487 |
|
|
|
488 |
$insert = $this->sql->insert(self::_TABLE);
|
|
|
489 |
$insert->values($values);
|
|
|
490 |
|
|
|
491 |
$response = $this->executeInsert($insert);
|
|
|
492 |
if($response) {
|
|
|
493 |
$user->id = $this->lastInsertId;
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
return $response;
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
|
|
|
500 |
/**
|
|
|
501 |
*
|
|
|
502 |
* @return boolean
|
|
|
503 |
*/
|
|
|
504 |
public function truncate()
|
|
|
505 |
{
|
|
|
506 |
$sql = sprintf('TRUNCATE TABLE `%s` ', self::_TABLE);
|
|
|
507 |
return $this->executeSentenceWithParameters($sql);
|
|
|
508 |
}
|
|
|
509 |
|
|
|
510 |
/**
|
|
|
511 |
*
|
|
|
512 |
* @param int $company_id
|
|
|
513 |
* @param string $status
|
|
|
514 |
* @param string $search
|
|
|
515 |
* @param int $page
|
|
|
516 |
* @param int $records_per_page
|
|
|
517 |
* @param string $order_field
|
|
|
518 |
* @param string $order_direction
|
|
|
519 |
* @return Paginator
|
|
|
520 |
*/
|
|
|
521 |
public function fetchAllDataTableByCompanyId($company_id, $status = '', $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
|
|
|
522 |
{
|
|
|
523 |
$select = $this->sql->select();
|
|
|
524 |
$select->columns(['status', 'backend', 'creator']);
|
|
|
525 |
$select->from(['tb1' => CompanyUserMapper::_TABLE]);
|
|
|
526 |
$select->join(['tb2' => self::_TABLE] , 'tb1.user_id = tb2.id', [
|
|
|
527 |
'id', 'uuid', 'first_name', 'last_name', 'email', 'last_activity_on', 'image',
|
|
|
528 |
'blocked', 'login_attempt', 'email_verified'
|
|
|
529 |
|
|
|
530 |
]);
|
|
|
531 |
|
|
|
532 |
$select->where->equalTo('tb1.company_id', $company_id);
|
|
|
533 |
$select->where->equalTo('tb1.owner', CompanyUser::OWNER_NO);
|
|
|
534 |
|
|
|
535 |
if($status) {
|
|
|
536 |
$select->where->equalTo('tb1.status', $status);
|
|
|
537 |
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
if($search) {
|
|
|
541 |
$select->where->nest()
|
|
|
542 |
->like('first_name', '%' . $search . '%')
|
|
|
543 |
->or->like('last_name', '%' . $search . '%')
|
|
|
544 |
->or->like('email', '%' . $search . '%')
|
|
|
545 |
->unnest();
|
|
|
546 |
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
|
|
|
550 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
551 |
|
|
|
552 |
$hydrator = new ArraySerializableHydrator();
|
|
|
553 |
$resultset = new HydratingResultSet($hydrator);
|
|
|
554 |
|
|
|
555 |
$adapter = new DbSelect($select, $this->sql, $resultset);
|
|
|
556 |
$paginator = new Paginator($adapter);
|
|
|
557 |
$paginator->setItemCountPerPage($records_per_page);
|
|
|
558 |
$paginator->setCurrentPageNumber($page);
|
|
|
559 |
|
|
|
560 |
|
|
|
561 |
return $paginator;
|
|
|
562 |
}
|
|
|
563 |
|
|
|
564 |
|
|
|
565 |
/**
|
|
|
566 |
*
|
|
|
567 |
* @param int $company_id
|
|
|
568 |
* @param string $search
|
|
|
569 |
* @param int $page
|
|
|
570 |
* @param int $records_per_page
|
|
|
571 |
* @param string $order_field
|
|
|
572 |
* @param string $order_direction
|
|
|
573 |
* @return Paginator
|
|
|
574 |
*/
|
|
|
575 |
public function fetchAllDataTableStudensByCompanyId($company_id, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
|
|
|
576 |
{
|
|
|
577 |
$date = date('Y-m-d');
|
|
|
578 |
|
|
|
579 |
$selectCapsuleUser = $this->getSql()->select();
|
|
|
580 |
$selectCapsuleUser->columns(['user_id' => new Expression('DISTINCT(user_id)') ]);
|
|
|
581 |
$selectCapsuleUser->from(CompanyMicrolearningCapsuleUserMapper::_TABLE);
|
|
|
582 |
$selectCapsuleUser->where->equalTo('company_id', $company_id);
|
|
|
583 |
$selectCapsuleUser->where->nest->equalTo('access', CompanyMicrolearningCapsuleUser::ACCESS_UNLIMITED)->or->nest()
|
|
|
584 |
->equalTo('access', CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD)
|
|
|
585 |
->and->lessThanOrEqualTo(new Expression('DATE(paid_from)'), $date)
|
|
|
586 |
->and->greaterThanOrEqualTo(new Expression('DATE(paid_to)'), $date )->unnest()->unnest();
|
|
|
587 |
|
|
|
588 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
589 |
|
|
|
590 |
$select = $this->sql->select();
|
|
|
591 |
$select->columns(['id' , 'uuid', 'first_name', 'last_name', 'email','blocked']);
|
|
|
592 |
$select->from(UserMapper::_TABLE);
|
|
|
593 |
$select->where->in('id', $selectCapsuleUser);
|
|
|
594 |
|
|
|
595 |
|
|
|
596 |
if($search) {
|
|
|
597 |
$select->where->nest()
|
|
|
598 |
->like('first_name', '%' . $search . '%')
|
|
|
599 |
->or->like('last_name', '%' . $search . '%')
|
|
|
600 |
->or->like('email', '%' . $search . '%')
|
|
|
601 |
->unnest();
|
|
|
602 |
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
|
|
|
606 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
607 |
|
|
|
608 |
$hydrator = new ArraySerializableHydrator();
|
|
|
609 |
$resultset = new HydratingResultSet($hydrator);
|
|
|
610 |
|
|
|
611 |
$adapter = new DbSelect($select, $this->sql, $resultset);
|
|
|
612 |
$paginator = new Paginator($adapter);
|
|
|
613 |
$paginator->setItemCountPerPage($records_per_page);
|
|
|
614 |
$paginator->setCurrentPageNumber($page);
|
|
|
615 |
|
|
|
616 |
|
|
|
617 |
return $paginator;
|
|
|
618 |
}
|
|
|
619 |
|
|
|
620 |
/**
|
|
|
621 |
*
|
|
|
622 |
* @param string $search
|
|
|
623 |
* @return User[]
|
|
|
624 |
*/
|
|
|
625 |
public function fetchAllSuggest($search)
|
|
|
626 |
{
|
|
|
627 |
|
|
|
628 |
$select = $this->sql->select();
|
|
|
629 |
$select->from(self::_TABLE);
|
|
|
630 |
$select->where->equalTo('status', User::STATUS_ACTIVE);
|
|
|
631 |
$select->where->equalTo('email_verified', User::EMAIL_VERIFIED_YES);
|
|
|
632 |
|
|
|
633 |
if($search) {
|
|
|
634 |
$select->where->nest()
|
|
|
635 |
->like('first_name', '%' . $search . '%')
|
|
|
636 |
->or->like('last_name', '%' . $search . '%')
|
|
|
637 |
->or->like('email', '%' . $search . '%')
|
|
|
638 |
->unnest();
|
|
|
639 |
|
|
|
640 |
}
|
|
|
641 |
|
|
|
642 |
$select->order(['first_name', 'last_name']);
|
|
|
643 |
|
|
|
644 |
// echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
645 |
|
|
|
646 |
$prototype = new User();
|
|
|
647 |
|
|
|
648 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
649 |
}
|
|
|
650 |
|
|
|
651 |
|
|
|
652 |
/**
|
|
|
653 |
*
|
|
|
654 |
* @param int $company_id
|
|
|
655 |
* @param string $search
|
|
|
656 |
* @return User[]
|
|
|
657 |
*/
|
|
|
658 |
public function fetchAllSuggestForInvitationByCompanyId($company_id, $search)
|
|
|
659 |
{
|
|
|
660 |
$selectCompanyUsers = $this->sql->select(CompanyUserMapper::_TABLE);
|
|
|
661 |
$selectCompanyUsers->columns(['user_id']);
|
|
|
662 |
$selectCompanyUsers->where->equalTo('company_id', $company_id);
|
|
|
663 |
$selectCompanyUsers->where->in('status', [
|
|
|
664 |
CompanyUser::STATUS_ACCEPTED,
|
|
|
665 |
CompanyUser::STATUS_PENDING,
|
|
|
666 |
CompanyUser::STATUS_SENT,
|
|
|
667 |
|
|
|
668 |
]);
|
|
|
669 |
|
|
|
670 |
//echo $selectCompanyUsers->getSqlString($this->adapter->platform); exit;
|
|
|
671 |
|
|
|
672 |
$select = $this->sql->select();
|
|
|
673 |
$select->from(self::_TABLE);
|
|
|
674 |
$select->where->notIn('id', $selectCompanyUsers);
|
|
|
675 |
$select->where->equalTo('status', User::STATUS_ACTIVE);
|
|
|
676 |
$select->where->equalTo('email_verified', User::EMAIL_VERIFIED_YES);
|
|
|
677 |
|
|
|
678 |
if($search) {
|
|
|
679 |
$select->where->nest()
|
|
|
680 |
->like('first_name', '%' . $search . '%')
|
|
|
681 |
->or->like('last_name', '%' . $search . '%')
|
|
|
682 |
->or->like('email', '%' . $search . '%')
|
|
|
683 |
->unnest();
|
|
|
684 |
|
|
|
685 |
}
|
|
|
686 |
|
|
|
687 |
$select->order(['first_name', 'last_name']);
|
|
|
688 |
|
|
|
689 |
// echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
690 |
|
|
|
691 |
$prototype = new User();
|
|
|
692 |
|
|
|
693 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
694 |
}
|
|
|
695 |
|
|
|
696 |
/**
|
|
|
697 |
*
|
|
|
698 |
* @param int $group_id
|
|
|
699 |
* @param string $search
|
|
|
700 |
* @return User[]
|
|
|
701 |
*/
|
|
|
702 |
public function fetchAllSuggestForInvitationByGroupId($group_id, $search)
|
|
|
703 |
{
|
|
|
704 |
$selectGroupMembers = $this->sql->select(GroupMemberMapper::_TABLE);
|
|
|
705 |
$selectGroupMembers->columns(['user_id']);
|
|
|
706 |
$selectGroupMembers->where->equalTo('group_id', $group_id);
|
|
|
707 |
$selectGroupMembers->where->in('status', [
|
|
|
708 |
CompanyUser::STATUS_ACCEPTED,
|
|
|
709 |
]);
|
|
|
710 |
|
|
|
711 |
//echo $selectGroupMembers->getSqlString($this->adapter->platform); exit;
|
|
|
712 |
|
|
|
713 |
$select = $this->sql->select();
|
|
|
714 |
$select->from(self::_TABLE);
|
|
|
715 |
$select->where->notIn('id', $selectGroupMembers);
|
|
|
716 |
$select->where->equalTo('status', User::STATUS_ACTIVE);
|
|
|
717 |
$select->where->equalTo('email_verified', User::EMAIL_VERIFIED_YES);
|
|
|
718 |
|
|
|
719 |
if($search) {
|
|
|
720 |
$select->where->nest()
|
|
|
721 |
->like('first_name', '%' . $search . '%')
|
|
|
722 |
->or->like('last_name', '%' . $search . '%')
|
|
|
723 |
->or->like('email', '%' . $search . '%')
|
|
|
724 |
->unnest();
|
|
|
725 |
|
|
|
726 |
}
|
|
|
727 |
|
|
|
728 |
$select->order(['first_name', 'last_name']);
|
|
|
729 |
|
|
|
730 |
// echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
731 |
|
|
|
732 |
$prototype = new User();
|
|
|
733 |
|
|
|
734 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
735 |
}
|
| 1665 |
nelberth |
736 |
|
|
|
737 |
public function fetchAllSuggestForInvitationByHptgId($group_id, $search)
|
|
|
738 |
{
|
|
|
739 |
$selectGroupMembers = $this->sql->select(HighPerformanceTeamsGroupsMembersMapper::_TABLE);
|
|
|
740 |
$selectGroupMembers->columns(['user_id']);
|
|
|
741 |
$selectGroupMembers->where->equalTo('group_id', $group_id);
|
|
|
742 |
$selectGroupMembers->where->in('status', [
|
| 2082 |
nelberth |
743 |
HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED,
|
|
|
744 |
HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN,
|
|
|
745 |
HighPerformanceTeamsGroupsMembers::STATUS_INVITED,
|
| 1665 |
nelberth |
746 |
]);
|
|
|
747 |
|
|
|
748 |
//echo $selectGroupMembers->getSqlString($this->adapter->platform); exit;
|
|
|
749 |
|
|
|
750 |
$select = $this->sql->select();
|
|
|
751 |
$select->from(self::_TABLE);
|
|
|
752 |
$select->where->notIn('id', $selectGroupMembers);
|
|
|
753 |
$select->where->equalTo('status', User::STATUS_ACTIVE);
|
|
|
754 |
$select->where->equalTo('email_verified', User::EMAIL_VERIFIED_YES);
|
|
|
755 |
|
|
|
756 |
if($search) {
|
|
|
757 |
$select->where->nest()
|
|
|
758 |
->like('first_name', '%' . $search . '%')
|
|
|
759 |
->or->like('last_name', '%' . $search . '%')
|
|
|
760 |
->or->like('email', '%' . $search . '%')
|
|
|
761 |
->unnest();
|
|
|
762 |
|
|
|
763 |
}
|
|
|
764 |
|
|
|
765 |
$select->order(['first_name', 'last_name']);
|
|
|
766 |
|
|
|
767 |
// echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
768 |
|
|
|
769 |
$prototype = new User();
|
|
|
770 |
|
|
|
771 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
772 |
}
|
| 1 |
www |
773 |
/**
|
|
|
774 |
*
|
|
|
775 |
* @param string $search
|
|
|
776 |
* @param int $page
|
|
|
777 |
* @param int $records_per_page
|
|
|
778 |
* @param string $order_field
|
|
|
779 |
* @param string $order_direction
|
|
|
780 |
* @return Paginator
|
|
|
781 |
*/
|
|
|
782 |
public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
|
|
|
783 |
{
|
|
|
784 |
$prototype = new User();
|
|
|
785 |
$select = $this->sql->select(self::_TABLE);
|
|
|
786 |
$select->where->in('usertype_id', [UserType::ADMIN, UserType::USER]);
|
|
|
787 |
|
|
|
788 |
|
|
|
789 |
if($search) {
|
|
|
790 |
$select->where->nest()
|
|
|
791 |
->like('first_name', '%' . $search . '%')
|
|
|
792 |
->or->like('last_name', '%' . $search . '%')
|
|
|
793 |
->or->like('email', '%' . $search . '%')
|
|
|
794 |
->unnest();
|
|
|
795 |
|
|
|
796 |
}
|
|
|
797 |
|
|
|
798 |
|
|
|
799 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
800 |
|
|
|
801 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
802 |
$resultset = new HydratingResultSet($hydrator, $prototype);
|
|
|
803 |
|
|
|
804 |
$adapter = new DbSelect($select, $this->sql, $resultset);
|
|
|
805 |
$paginator = new Paginator($adapter);
|
|
|
806 |
$paginator->setItemCountPerPage($records_per_page);
|
|
|
807 |
$paginator->setCurrentPageNumber($page);
|
|
|
808 |
|
|
|
809 |
|
|
|
810 |
return $paginator;
|
|
|
811 |
}
|
|
|
812 |
|
|
|
813 |
/**
|
|
|
814 |
*
|
|
|
815 |
* @param int $id
|
|
|
816 |
* @return boolean
|
|
|
817 |
*/
|
|
|
818 |
public function updateChatOnlineStatus($id)
|
|
|
819 |
{
|
|
|
820 |
$update = $this->sql->update(self::_TABLE);
|
|
|
821 |
$update->set([
|
|
|
822 |
'online' => 1,
|
|
|
823 |
]);
|
|
|
824 |
$update->where->equalTo('id', $id);
|
|
|
825 |
|
|
|
826 |
return $this->executeUpdate($update);
|
|
|
827 |
}
|
|
|
828 |
|
|
|
829 |
/**
|
|
|
830 |
*
|
|
|
831 |
* @param int $id
|
|
|
832 |
* @return boolean
|
|
|
833 |
*/
|
|
|
834 |
public function updateChatOfflineStatus($id)
|
|
|
835 |
{
|
|
|
836 |
$update = $this->sql->update(self::_TABLE);
|
|
|
837 |
$update->set([
|
|
|
838 |
'online' => 0,
|
|
|
839 |
]);
|
|
|
840 |
$update->where->equalTo('id', $id);
|
|
|
841 |
|
|
|
842 |
return $this->executeUpdate($update);
|
|
|
843 |
}
|
|
|
844 |
|
|
|
845 |
/**
|
|
|
846 |
*
|
|
|
847 |
* @param int $id
|
|
|
848 |
* @return boolean
|
|
|
849 |
*/
|
|
|
850 |
public function updateLastActivity($id)
|
|
|
851 |
{
|
|
|
852 |
$update = $this->sql->update(self::_TABLE);
|
|
|
853 |
$update->set([
|
|
|
854 |
'last_activity_on' => new Expression('NOW()'),
|
|
|
855 |
]);
|
|
|
856 |
$update->where->equalTo('id', $id);
|
|
|
857 |
|
|
|
858 |
return $this->executeUpdate($update);
|
|
|
859 |
}
|
|
|
860 |
|
|
|
861 |
|
|
|
862 |
/**
|
|
|
863 |
*
|
|
|
864 |
* @param int $id
|
|
|
865 |
* @return boolean
|
|
|
866 |
*/
|
|
|
867 |
public function updateLastHeartBeat($id)
|
|
|
868 |
{
|
|
|
869 |
$update = $this->sql->update(self::_TABLE);
|
|
|
870 |
$update->set([
|
|
|
871 |
'last_heart_beat_at' => new Expression('NOW()'),
|
| 242 |
efrain |
872 |
'online' => 1,
|
|
|
873 |
|
| 1 |
www |
874 |
]);
|
|
|
875 |
$update->where->equalTo('id', $id);
|
|
|
876 |
|
|
|
877 |
return $this->executeUpdate($update);
|
|
|
878 |
}
|
| 242 |
efrain |
879 |
|
|
|
880 |
/**
|
|
|
881 |
*
|
|
|
882 |
* @param int $id
|
|
|
883 |
* @return boolean
|
|
|
884 |
*/
|
|
|
885 |
public function emailVerifyAndActive($id)
|
|
|
886 |
{
|
|
|
887 |
$update = $this->sql->update(self::_TABLE);
|
|
|
888 |
$update->set([
|
|
|
889 |
'email_verified' => User::EMAIL_VERIFIED_YES,
|
|
|
890 |
'status' => User::STATUS_ACTIVE,
|
|
|
891 |
]);
|
|
|
892 |
$update->where->equalTo('id', $id);
|
| 1 |
www |
893 |
|
| 242 |
efrain |
894 |
return $this->executeUpdate($update);
|
|
|
895 |
}
|
|
|
896 |
|
| 630 |
efrain |
897 |
|
|
|
898 |
/**
|
|
|
899 |
*
|
|
|
900 |
* @param int $company_id
|
|
|
901 |
* @return User[]
|
|
|
902 |
*/
|
|
|
903 |
public function fetchAllVerifyAndActiveByCompanyId($company_id)
|
|
|
904 |
{
|
|
|
905 |
$select = $this->sql->select();
|
|
|
906 |
$select->columns(['status', 'company_id']);
|
|
|
907 |
$select->from(['tb1' => CompanyUserMapper::_TABLE]);
|
|
|
908 |
$select->join(['tb2' => self::_TABLE] , 'tb1.user_id = tb2.id');
|
|
|
909 |
|
|
|
910 |
|
|
|
911 |
|
|
|
912 |
$select->where->equalTo('tb1.company_id', $company_id);
|
|
|
913 |
$select->where->equalTo('tb1.owner', CompanyUser::OWNER_NO);
|
|
|
914 |
$select->where->in('tb1.status', [CompanyUser::STATUS_ACCEPTED, CompanyUser::STATUS_ADMIN_WILL_ADD]);
|
|
|
915 |
$select->where->equalTo('tb2.email_verified', User::EMAIL_VERIFIED_YES);
|
|
|
916 |
$select->where->equalTo('tb2.status', User::STATUS_ACTIVE);
|
|
|
917 |
|
|
|
918 |
$select->order('first_name', 'last_name', 'email');
|
|
|
919 |
|
|
|
920 |
$prototype = User();
|
|
|
921 |
|
|
|
922 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
923 |
}
|
| 1 |
www |
924 |
}
|