Completed
Push — master ( 5edd90...dec614 )
by Aleksandar
04:23 queued 01:58
created

AdminUsersMapper::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
declare(strict_types = 1);
3
namespace Core\Mapper;
4
5
use Zend\Db\Adapter\Adapter;
6
use Zend\Db\Adapter\AdapterAwareInterface;
7
use Zend\Db\TableGateway\AbstractTableGateway;
8
9
/**
10
 * Class AdminUsersMapper.
11
 *
12
 * @package Core\Mapper
13
 */
14
class AdminUsersMapper extends AbstractTableGateway implements AdapterAwareInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $table = 'admin_users';
20
21
    /**
22
     * Db adapter setter method,
23
     *
24
     * @param Adapter $adapter db adapter
25
     * @return void
26
     */
27
    public function setDbAdapter(Adapter $adapter)
28
    {
29
        $this->adapter = $adapter;
30
    }
31
32
    public function get($id)
33
    {
34
        return $this->select(['admin_user_uuid' => $id])->current();
35
    }
36
37
    /**
38
     * Get admin user by email.
39
     *
40
     * @param string $email email
41
     * @return array|\ArrayObject|null
42
     */
43
    public function getByEmail(string $email)
44
    {
45
        return $this->select(['email' => $email])->current();
46
    }
47
48
    /**
49
     * Updates login data.
50
     *
51
     * @param string $uuid admin user uuid
52
     * @return int number of affected rows
53
     */
54
    public function updateLogin(string $uuid) : int
55
    {
56
        return $this->update(['last_login' => date('Y-m-d H:i:s')], ['admin_user_uuid' => $uuid]);
57
    }
58
59
    public function getPaginationSelect($userId)
60
    {
61
        $select = $this->getSql()->select()->order(['created_at' => 'desc']);
62
63
        $select->where->notEqualTo('admin_user_uuid', $userId);
64
65
        return $select;
66
    }
67
}
68