Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev Autor Línea Nro. Línea
1 efrain 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
     *
65
     * @param int $user_id
66
     * @param string $search
67
     * @return UserProfile[]
68
     */
69
    public function fetchAllByUserIdAndSearch($user_id, $search = '')
70
    {
71
        $prototype = new UserProfile;
72
        $select = $this->sql->select(self::_TABLE);
73
        $select->where->equalTo('user_id', $user_id);
74
 
75
        if($search) {
76
            $select->where->like('name', '%' . $search . '%');
77
        }
78
 
79
        return $this->executeFetchAllObject($select, $prototype);
80
    }
81
 
82
    /**
83
     *
84
     * @param int $id
85
     * @return UserProfile
86
     */
87
    public function fetchOne($id)
88
    {
89
        $select = $this->sql->select(self::_TABLE);
90
        $select->where->equalTo('id', $id);
91
        $select->limit(1);
92
 
93
        $prototype = new UserProfile();
94
        return $this->executeFetchOneObject($select, $prototype);
95
    }
96
 
97
    /**
98
     *
99
     * @param int $uuid
100
     * @return UserProfile
101
     */
102
    public function fetchOneByUuid($uuid)
103
    {
104
        $prototype = new UserProfile;
105
        $select = $this->sql->select(self::_TABLE);
106
        $select->where->equalTo('uuid', $uuid);
107
 
108
        return $this->executeFetchOneObject($select, $prototype);
109
    }
110
 
111
    /**
112
     *
113
     * @param int $user_id
114
     * @return UserProfile
115
     */
116
    public function fetchOnePublicByUserId($user_id)
117
    {
118
 
119
        $select = $this->sql->select(self::_TABLE);
120
        $select->where->equalTo('user_id', $user_id);
121
        $select->where->equalTo('public', UserProfile::PUBLIC_YES);
122
        $select->limit(1);
123
 
124
        $prototype = new UserProfile();
125
        return $this->executeFetchOneObject($select, $prototype);
126
    }
127
 
128
    /**
129
     *
130
     * @param UserProfile $userProfile
131
     * @return boolean
132
     */
133
    public function insert($userProfile)
134
    {
135
        $hydrator = new ObjectPropertyHydrator();
136
        $values = $hydrator->extract($userProfile);
137
        $values = $this->removeEmpty($values);
138
 
139
        $insert = $this->sql->insert(self::_TABLE);
140
        $insert->values($values);
141
 
142
 
143
        $result = $this->executeInsert($insert);
144
        if($result) {
145
            $userProfile->id = $this->lastInsertId;
146
        }
147
 
148
        return $result;
149
 
150
    }
151
 
152
    /**
153
     *
154
     * @param UserProfile $userProfile
155
     * @return boolean
156
     */
157
    public function updateExtended($userProfile)
158
    {
159
        $values = [
160
            'description' => $userProfile->description,
161
        ];
162
 
163
        $update = $this->sql->update(self::_TABLE);
164
        $update->set($values);
165
        $update->where->equalTo('id', $userProfile->id);
166
 
167
        return $this->executeUpdate($update);
168
 
169
    }
170
 
171
    /**
172
     *
173
     * @param UserProfile $userProfile
174
     * @return boolean
175
     */
176
    public function updateImage($userProfile)
177
    {
178
        $values = [
179
            'image' => $userProfile->image,
180
        ];
181
 
182
        $update = $this->sql->update(self::_TABLE);
183
        $update->set($values);
184
        $update->where->equalTo('id', $userProfile->id);
185
 
186
        return $this->executeUpdate($update);
187
 
188
    }
189
 
190
    /**
191
     *
192
     * @param UserProfile $userProfile
193
     * @return boolean
194
     */
195
    public function updateCover($userProfile)
196
    {
197
        $values = [
198
            'cover' => $userProfile->cover,
199
        ];
200
 
201
        $update = $this->sql->update(self::_TABLE);
202
        $update->set($values);
203
        $update->where->equalTo('id', $userProfile->id);
204
 
205
        return $this->executeUpdate($update);
206
 
207
    }
383 www 208
 
209
 
1 efrain 210
 
211
    /**
212
     *
213
     * @param UserProfile $userProfile
214
     * @return boolean
215
     */
216
    public function updateSocialNetwork($userProfile)
217
    {
218
        $values = [
219
            'facebook' => $userProfile->facebook,
220
            'instagram' => $userProfile->instagram,
221
            'twitter' => $userProfile->twitter,
222
        ];
223
 
224
        $update = $this->sql->update(self::_TABLE);
225
        $update->set($values);
226
        $update->where->equalTo('id', $userProfile->id);
227
 
228
        return $this->executeUpdate($update);
229
 
230
    }
231
 
232
    /**
233
     *
234
     * @param UserProfile $userProfile
235
     * @return boolean
236
     */
237
    public function updateLocation($userProfile)
238
    {
239
        $values = [
240
            'location_id' => $userProfile->location_id,
241
        ];
242
 
243
        $update = $this->sql->update(self::_TABLE);
244
        $update->set($values);
245
 
246
 
247
        $update->where->equalTo('id', $userProfile->id);
248
        return $this->executeUpdate($update);
249
 
250
    }
251
 
252
 
253
    /**
254
     *
255
     * @param UserProfile $userProfile
256
     * @return boolean
257
     */
258
    public function delete($userProfile)
259
    {
260
        $delete = $this->sql->delete(self::_TABLE);
261
        $delete->where->equalTo('id', $userProfile->id);
262
 
263
        return $this->executeDelete($delete);
264
 
265
    }
266
}