1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Admin\Mapper; |
6
|
|
|
|
7
|
|
|
use Zend\Db\Adapter\Adapter; |
8
|
|
|
use Zend\Db\Adapter\AdapterAwareInterface; |
9
|
|
|
use Zend\Db\Sql\Expression; |
10
|
|
|
use Zend\Db\TableGateway\AbstractTableGateway; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class AdminUsersMapper. |
14
|
|
|
*/ |
15
|
|
|
class AdminUsersMapper extends AbstractTableGateway implements AdapterAwareInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $table = 'admin_users'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Db adapter setter method,. |
24
|
|
|
* |
25
|
|
|
* @param Adapter $adapter db adapter |
26
|
|
|
* |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
|
|
public function setDbAdapter(Adapter $adapter) |
30
|
|
|
{ |
31
|
|
|
$this->adapter = $adapter; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function get($id) |
35
|
|
|
{ |
36
|
|
|
return $this->select(['admin_user_id' => $id])->current(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get admin user by email. |
41
|
|
|
* |
42
|
|
|
* @param string $email email |
43
|
|
|
* |
44
|
|
|
* @return array|\ArrayObject|null |
45
|
|
|
*/ |
46
|
|
|
public function getByEmail(string $email) |
47
|
|
|
{ |
48
|
|
|
return $this->select(['email' => $email])->current(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Updates login data. |
53
|
|
|
* |
54
|
|
|
* @param string $uuid admin user id |
|
|
|
|
55
|
|
|
* |
56
|
|
|
* @return int number of affected rows |
57
|
|
|
*/ |
58
|
|
|
public function updateLogin(string $userId): int |
59
|
|
|
{ |
60
|
|
|
return $this->update(['last_login' => date('Y-m-d H:i:s')], ['admin_user_id' => $userId]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getPaginationSelect($userId) |
64
|
|
|
{ |
65
|
|
|
$select = $this->getSql()->select()->order(['created_at' => 'desc']); |
66
|
|
|
|
67
|
|
|
$select->where->notEqualTo('admin_user_id', $userId); |
68
|
|
|
|
69
|
|
|
return $select; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getRandom($limit) |
73
|
|
|
{ |
74
|
|
|
$select = $this->getSql()->select() |
75
|
|
|
->where(['status' => 1]) |
76
|
|
|
->order(new Expression('rand()')) |
|
|
|
|
77
|
|
|
->limit($limit); |
78
|
|
|
|
79
|
|
|
return $this->selectWith($select); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getUuid($adminUserId) |
83
|
|
|
{ |
84
|
|
|
$user = $this->select(['admin_user_id' => $adminUserId])->current(); |
85
|
|
|
|
86
|
|
|
if (!$user) { |
87
|
|
|
throw new \Exception('Admin user does not exist!', 400); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $user->admin_user_uuid; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.