Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3163 | | 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 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
 
3255 efrain 62
 
1 www 63
    /**
3255 efrain 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
    /**
1 www 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
    {
3163 efrain 118
 
1 www 119
        $select = $this->sql->select(self::_TABLE);
120
        $select->where->equalTo('user_id', $user_id);
3163 efrain 121
        $select->where->equalTo('public', UserProfile::PUBLIC_YES);
1 www 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
    }
208
 
209
    /**
210
     *
211
     * @param UserProfile $userProfile
212
     * @return boolean
213
     */
214
    public function updateSocialNetwork($userProfile)
215
    {
216
        $values = [
217
            'facebook' => $userProfile->facebook,
218
            'instagram' => $userProfile->instagram,
219
            'twitter' => $userProfile->twitter,
220
        ];
221
 
222
        $update = $this->sql->update(self::_TABLE);
223
        $update->set($values);
224
        $update->where->equalTo('id', $userProfile->id);
225
 
226
        return $this->executeUpdate($update);
227
 
228
    }
229
 
230
    /**
231
     *
232
     * @param UserProfile $userProfile
233
     * @return boolean
234
     */
235
    public function updateLocation($userProfile)
236
    {
237
        $values = [
238
            'location_id' => $userProfile->location_id,
239
        ];
240
 
241
        $update = $this->sql->update(self::_TABLE);
242
        $update->set($values);
243
 
244
 
245
        $update->where->equalTo('id', $userProfile->id);
246
        return $this->executeUpdate($update);
247
 
248
    }
249
 
250
 
251
    /**
252
     *
253
     * @param UserProfile $userProfile
254
     * @return boolean
255
     */
256
    public function delete($userProfile)
257
    {
258
        $delete = $this->sql->delete(self::_TABLE);
259
        $delete->where->equalTo('id', $userProfile->id);
260
 
261
        return $this->executeDelete($delete);
262
 
263
    }
264
}