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