Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3163 | Ir a la última revisión | | 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\UserProfile;
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 UserProfileMapper extends MapperCommon
15
{
16
    const _TABLE = 'tbl_user_profiles';
17
 
18
 
19
    /**
20
     *
21
     * @var UserProfileMapper
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\UserProfileMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new UserProfileMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
 
48
    /**
49
     *
50
     * @param int $user_id
51
     * @return UserProfile[]
52
     */
53
    public function fetchAllByUserId($user_id)
54
    {
55
        $prototype = new UserProfile;
56
        $select = $this->sql->select(self::_TABLE);
57
        $select->where->equalTo('user_id', $user_id);
58
 
59
        return $this->executeFetchAllObject($select, $prototype);
60
    }
61
 
62
    /**
63
     *
64
     * @param int $id
65
     * @return UserProfile
66
     */
67
    public function fetchOne($id)
68
    {
69
        $select = $this->sql->select(self::_TABLE);
70
        $select->where->equalTo('id', $id);
71
        $select->limit(1);
72
 
73
        $prototype = new UserProfile();
74
        return $this->executeFetchOneObject($select, $prototype);
75
    }
76
 
77
    /**
78
     *
79
     * @param int $uuid
80
     * @return UserProfile
81
     */
82
    public function fetchOneByUuid($uuid)
83
    {
84
        $prototype = new UserProfile;
85
        $select = $this->sql->select(self::_TABLE);
86
        $select->where->equalTo('uuid', $uuid);
87
 
88
        return $this->executeFetchOneObject($select, $prototype);
89
    }
90
 
91
    /**
92
     *
93
     * @param int $user_id
94
     * @return UserProfile
95
     */
96
    public function fetchOnePublicByUserId($user_id)
97
    {
98
        $select = $this->sql->select(self::_TABLE);
99
        $select->where->equalTo('user_id', $user_id);
100
        $select->limit(1);
101
 
102
        $prototype = new UserProfile();
103
        return $this->executeFetchOneObject($select, $prototype);
104
    }
105
 
106
    /**
107
     *
108
     * @param UserProfile $userProfile
109
     * @return boolean
110
     */
111
    public function insert($userProfile)
112
    {
113
        $hydrator = new ObjectPropertyHydrator();
114
        $values = $hydrator->extract($userProfile);
115
        $values = $this->removeEmpty($values);
116
 
117
        $insert = $this->sql->insert(self::_TABLE);
118
        $insert->values($values);
119
 
120
 
121
        $result = $this->executeInsert($insert);
122
        if($result) {
123
            $userProfile->id = $this->lastInsertId;
124
        }
125
 
126
        return $result;
127
 
128
    }
129
 
130
    /**
131
     *
132
     * @param UserProfile $userProfile
133
     * @return boolean
134
     */
135
    public function updateExtended($userProfile)
136
    {
137
        $values = [
138
            'description' => $userProfile->description,
139
        ];
140
 
141
        $update = $this->sql->update(self::_TABLE);
142
        $update->set($values);
143
        $update->where->equalTo('id', $userProfile->id);
144
 
145
        return $this->executeUpdate($update);
146
 
147
    }
148
 
149
    /**
150
     *
151
     * @param UserProfile $userProfile
152
     * @return boolean
153
     */
154
    public function updateImage($userProfile)
155
    {
156
        $values = [
157
            'image' => $userProfile->image,
158
        ];
159
 
160
        $update = $this->sql->update(self::_TABLE);
161
        $update->set($values);
162
        $update->where->equalTo('id', $userProfile->id);
163
 
164
        return $this->executeUpdate($update);
165
 
166
    }
167
 
168
    /**
169
     *
170
     * @param UserProfile $userProfile
171
     * @return boolean
172
     */
173
    public function updateCover($userProfile)
174
    {
175
        $values = [
176
            'cover' => $userProfile->cover,
177
        ];
178
 
179
        $update = $this->sql->update(self::_TABLE);
180
        $update->set($values);
181
        $update->where->equalTo('id', $userProfile->id);
182
 
183
        return $this->executeUpdate($update);
184
 
185
    }
186
 
187
    /**
188
     *
189
     * @param UserProfile $userProfile
190
     * @return boolean
191
     */
192
    public function updateSocialNetwork($userProfile)
193
    {
194
        $values = [
195
            'facebook' => $userProfile->facebook,
196
            'instagram' => $userProfile->instagram,
197
            'twitter' => $userProfile->twitter,
198
        ];
199
 
200
        $update = $this->sql->update(self::_TABLE);
201
        $update->set($values);
202
        $update->where->equalTo('id', $userProfile->id);
203
 
204
        return $this->executeUpdate($update);
205
 
206
    }
207
 
208
    /**
209
     *
210
     * @param UserProfile $userProfile
211
     * @return boolean
212
     */
213
    public function updateLocation($userProfile)
214
    {
215
        $values = [
216
            'location_id' => $userProfile->location_id,
217
        ];
218
 
219
        $update = $this->sql->update(self::_TABLE);
220
        $update->set($values);
221
 
222
 
223
        $update->where->equalTo('id', $userProfile->id);
224
        return $this->executeUpdate($update);
225
 
226
    }
227
 
228
 
229
    /**
230
     *
231
     * @param UserProfile $userProfile
232
     * @return boolean
233
     */
234
    public function delete($userProfile)
235
    {
236
        $delete = $this->sql->delete(self::_TABLE);
237
        $delete->where->equalTo('id', $userProfile->id);
238
 
239
        return $this->executeDelete($delete);
240
 
241
    }
242
}