Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| 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 LeadersLinked\Model\UserExperience;
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use Laminas\Log\LoggerInterface;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
 
13
 
14
class UserExperienceMapper extends MapperCommon
15
{
16
    const _TABLE = 'tbl_user_experiences';
17
 
18
 
19
    /**
20
     *
21
     * @var UserExperienceMapper
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 \LeadersLinked\Mapper\UserExperienceMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new UserExperienceMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
50
     * @return UserExperience[]
51
     */
52
    public function fetchOne($id)
53
    {
54
        $prototype = new UserExperience();
55
        $select = $this->sql->select(self::_TABLE);
56
        $select->where->equalTo('id', $id);
57
 
58
        return $this->executeFetchOneObject($select, $prototype);
59
    }
60
 
61
    /**
62
     *
63
     * @param string $uuid
64
     * @return UserExperience[]
65
     */
66
    public function fetchOneByUuid($uuid)
67
    {
68
        $prototype = new UserExperience();
69
        $select = $this->sql->select(self::_TABLE);
70
        $select->where->equalTo('uuid', $uuid);
71
 
72
        return $this->executeFetchOneObject($select, $prototype);
73
    }
74
 
75
    /**
76
     *
77
     * @param int $user_id
78
     * @return UserExperience[]
79
     */
80
    public function fetchAllByUserId($user_id)
81
    {
82
        $prototype = new UserExperience();
83
        $select = $this->sql->select(self::_TABLE);
84
        $select->where->equalTo('user_id', $user_id);
85
 
86
        return $this->executeFetchAllObject($select, $prototype);
87
    }
88
 
89
    /**
90
     *
91
     * @param int $user_profile_id
92
     * @return UserExperience[]
93
     */
94
    public function fetchAllByUserProfileId($user_profile_id)
95
    {
96
        $prototype = new UserExperience();
97
        $select = $this->sql->select(self::_TABLE);
98
        $select->where->equalTo('user_profile_id', $user_profile_id);
99
        $select->order(['from_year DESC',  'to_year DESC']);
100
 
101
        return $this->executeFetchAllObject($select, $prototype);
102
    }
103
 
104
 
105
    /**
106
     *
107
     * @param UserExperience $userExperience
108
     * @return int
109
     */
110
    public function insert($userExperience)
111
    {
112
        $hydrator = new ObjectPropertyHydrator();
113
        $values = $hydrator->extract($userExperience);
114
        $values = $this->removeEmpty($values);
115
 
116
        $insert = $this->sql->insert(self::_TABLE);
117
        $insert->values($values);
118
 
119
        $result = $this->executeInsert($insert);
120
        if($result) {
121
            $userExperience->id = $this->lastInsertId;
122
        }
123
 
124
        return $result;
125
    }
126
 
127
 
128
    /**
129
     *
130
     * @param UserExperience $userExperience
131
     * @return int
132
     */
133
    public function update($userExperience)
134
    {
135
        $hydrator = new ObjectPropertyHydrator();
136
        $values = $hydrator->extract($userExperience);
137
        $values = $this->removeEmpty($values);
138
 
139
        $update = $this->sql->update(self::_TABLE);
140
        $update->set($values);
141
        $update->where->equalTo('id', $userExperience->id);
142
 
143
        return $this->executeUpdate($update);
144
    }
145
 
146
 
147
    /**
148
     *
149
     * @param UserExperience $userExperience
150
     * @return boolean
151
     */
152
    public function delete($userExperience)
153
    {
154
        $delete = $this->sql->delete(self::_TABLE);
155
        $delete->where->equalTo('id', $userExperience->id);
156
 
157
        return $this->executeDelete($delete);
158
    }
159
}