Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
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\UserPassword;
12
use LeadersLinked\Mapper\Common\MapperCommon;
13
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
14
 
15
class UserPasswordMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_user_passwords';
18
 
19
    /**
20
     *
21
     * @var UserPasswordMapper
22
     */
23
    private static $_instance;
24
 
25
    /**
26
     *
27
     * @param AdapterInterface $adapter
28
     */
29
    private function __construct($adapter)
30
    {
31
        parent::__construct($adapter);
32
    }
33
 
34
    /**
35
     *
36
     * @param AdapterInterface $adapter
37
     * @return UserPasswordMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new UserPasswordMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $user_id
50
     * @return UserPassword[]
51
     */
52
    public function fetchAllByUserId($user_id)
53
    {
54
 
55
        $prototype = new UserPassword();
56
 
57
        $select = $this->sql->select(self::_TABLE);
58
        $select->where->equalTo('user_id', $user_id);
59
 
60
 
61
 
62
        return $this->executeFetchAllObject($select, $prototype);
63
    }
64
 
4751 efrain 65
 
1 www 66
    /**
4751 efrain 67
     *
68
     * @param int $user_id
69
     * @return UserPassword
70
     */
71
    public function fetchLastByUserId($user_id)
72
    {
73
 
74
        $prototype = new UserPassword();
75
 
76
        $select = $this->sql->select(self::_TABLE);
77
        $select->where->equalTo('user_id', $user_id);
78
        $select->order('id DESC');
79
 
80
 
81
 
82
 
83
        return $this->executeFetchOneObject($select, $prototype);
84
    }
85
 
86
    /**
1 www 87
     *
88
     * @param UserPassword $userPassword
89
     * @return boolean
90
     */
91
    public function insert($userPassword)
92
    {
93
        $hydrator = new ObjectPropertyHydrator();
94
        $values = $hydrator->extract($userPassword);
95
        $values = $this->removeEmpty($values);
96
 
97
        $insert = $this->sql->insert(self::_TABLE);
98
        $insert->values($values);
99
 
100
        $response = $this->executeInsert($insert);
101
        if($response) {
102
            $userPassword->id = $this->lastInsertId;
103
        }
104
 
105
        return $response;
106
    }
107
 
108
}