Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | | 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 Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Db\ResultSet\HydratingResultSet;
9
use Laminas\Paginator\Adapter\DbSelect;
10
use Laminas\Paginator\Paginator;
11
use Laminas\Log\LoggerInterface;
12
use Laminas\Hydrator\ArraySerializableHydrator;
13
 
14
 
15
use LeadersLinked\Model\Group;
16
use LeadersLinked\Mapper\Common\MapperCommon;
17
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
18
use Laminas\Db\Sql\Expression;
19
 
20
class GroupMapper extends MapperCommon
21
{
22
    const _TABLE = 'tbl_groups';
23
 
24
 
25
    /**
26
     *
27
     * @var GroupMapper
28
     */
29
    private static $_instance;
30
 
31
    /**
32
     *
33
     * @param AdapterInterface $adapter
34
     */
35
    private function __construct($adapter)
36
    {
37
        parent::__construct($adapter);
38
    }
39
 
40
    /**
41
     *
42
     * @param AdapterInterface $adapter
43
     * @return GroupMapper
44
     */
45
    public static function getInstance($adapter)
46
    {
47
        if(self::$_instance == null) {
48
            self::$_instance = new GroupMapper($adapter);
49
        }
50
        return self::$_instance;
51
    }
52
 
53
    /**
54
     *
55
     * @param int $id
56
     * @return Group
57
     */
58
    public function fetchOne($id)
59
    {
60
        $prototype = new Group();
61
 
62
        $select = $this->sql->select(self::_TABLE);
63
        $select->where->equalTo('id', $id);
64
 
65
        return $this->executeFetchOneObject($select, $prototype);
66
    }
67
 
68
    /**
69
     *
70
     * @param int $uuid
71
     * @return Group
72
     */
73
    public function fetchOneByUuid($uuid)
74
    {
75
        $prototype = new Group();
76
 
77
        $select = $this->sql->select(self::_TABLE);
78
        $select->where->equalTo('uuid', $uuid);
79
 
80
        return $this->executeFetchOneObject($select, $prototype);
81
    }
82
 
3639 efrain 83
 
1 www 84
    /**
3639 efrain 85
     *
86
     * @param int $id
87
     * @param int $network_id
88
     * @return Group
89
     */
90
    public function fetchOneByIdAndNetworkId($id, $network_id)
91
    {
92
        $prototype = new Group();
93
 
94
        $select = $this->sql->select(self::_TABLE);
95
        $select->where->equalTo('id', $id);
96
        $select->where->equalTo('network_id', $network_id);
97
 
98
        return $this->executeFetchOneObject($select, $prototype);
99
    }
100
 
101
 
102
 
103
    /**
104
     *
105
     * @param string $uuid
106
     * @param int $network_id
107
     * @return Group
108
     */
109
    public function fetchOneByUuidAndNetworkId($uuid, $network_id)
110
    {
111
        $prototype = new Group();
112
 
113
        $select = $this->sql->select(self::_TABLE);
114
        $select->where->equalTo('uuid', $uuid);
115
        $select->where->equalTo('network_id', $network_id);
116
 
117
        return $this->executeFetchOneObject($select, $prototype);
118
    }
119
 
120
    /**
1 www 121
     *
122
     * @param int $user_id
123
     * @return Group[]
124
     */
125
    public function fetchAllByUserId($user_id)
126
    {
127
        $prototype = new Group();
128
 
129
        $select = $this->sql->select(self::_TABLE);
130
        $select->where->equalTo('user_id', $user_id);
131
        $select->where->equalTo('status', Group::STATUS_ACTIVE);
132
 
133
        return $this->executeFetchAllObject($select, $prototype);
134
    }
135
 
136
    /**
137
     *
138
     * @param Group $group
139
     * return true
140
     */
141
    public function insert($group)
142
    {
143
        $hydrator = new \Laminas\Hydrator\ObjectPropertyHydrator();
144
        $values = $hydrator->extract($group);
145
        $values = $this->removeEmpty($values);
146
 
147
 
148
        $insert = $this->sql->insert(self::_TABLE);
149
        $insert->values($values);
150
 
151
        $result = $this->executeInsert($insert);
152
        if($result) {
153
            $group->id = $this->lastInsertId;
154
        }
155
 
156
        return $result;
157
    }
158
 
159
    /**
160
     *
161
     * @param Group $group
162
     * return true
163
     */
164
    public function update($group)
165
    {
166
        $hydrator = new \Laminas\Hydrator\ObjectPropertyHydrator();
167
        $values = $hydrator->extract($group);
168
        $values = $this->removeEmpty($values);
169
 
170
 
171
        $update = $this->sql->update(self::_TABLE);
172
        $update->set($values);
173
        $update->where->equalTo('id', $group->id);
174
 
175
        return $this->executeUpdate($update);
176
    }
177
 
178
    /**
179
     *
180
     * @param Group $group
181
     * return true
182
     */
183
    public function delete($group)
184
    {
185
        $update = $this->sql->update(self::_TABLE);
186
        $update->set([
187
            'status' => Group::STATUS_DELETE,
188
        ]);
189
        $update->where->equalTo('id', $group->id);
190
 
191
        return $this->executeUpdate($update);
192
    }
193
 
194
    /**
195
     *
196
     * @param Group $group
197
     * return true
198
     */
199
    public function updateIndustry($group)
200
    {
201
        $update = $this->sql->update(self::_TABLE);
202
        $update->set(['industry_id' => $group->industry_id]);
203
        $update->where->equalTo('id', $group->id);
204
 
205
        return $this->executeUpdate($update);
206
    }
207
 
208
    /**
209
     *
210
     * @param Group $group
211
     * return true
212
     */
213
    public function updateGroupType($group)
214
    {
215
        $update = $this->sql->update(self::_TABLE);
216
        $update->set(['type_id' => $group->type_id]);
217
        $update->where->equalTo('id', $group->id);
218
 
219
        return $this->executeUpdate($update);
220
    }
221
 
222
    /**
223
     *
224
     * @param Group $group
225
     * return true
226
     */
227
    public function updateExtended($group)
228
    {
229
        $update = $this->sql->update(self::_TABLE);
230
        $update->set(['description' => $group->description]);
231
        $update->where->equalTo('id', $group->id);
232
 
233
        return $this->executeUpdate($update);
234
    }
235
 
236
    /**
237
     *
238
     * @param Group $group
239
     * return true
240
     */
241
    public function updateAccessibility($group)
242
    {
243
        $update = $this->sql->update(self::_TABLE);
244
        $update->set(['accessibility' => $group->accessibility]);
245
        $update->where->equalTo('id', $group->id);
246
 
247
       // echo $update->getSqlString($this->adapter->platform); exit;
248
 
249
        return $this->executeUpdate($update);
250
    }
251
 
252
 
253
    /**
254
     *
255
     * @param Group $group
256
     * return true
257
     */
258
    public function updatePrivacy($group)
259
    {
260
        $update = $this->sql->update(self::_TABLE);
261
        $update->set(['privacy' => $group->privacy]);
262
        $update->where->equalTo('id', $group->id);
263
 
264
        return $this->executeUpdate($update);
265
    }
266
 
267
    /**
268
     *
269
     * @param Group $group
270
     * return true
271
     */
272
    public function updateImage($group)
273
    {
274
        $update = $this->sql->update(self::_TABLE);
275
        $update->set(['image' => $group->image]);
276
        $update->where->equalTo('id', $group->id);
277
 
278
        return $this->executeUpdate($update);
279
    }
280
 
281
    /**
282
     *
283
     * @param Group $group
284
     * return true
285
     */
286
    public function updateCover($group)
287
    {
288
        $update = $this->sql->update(self::_TABLE);
289
        $update->set(['cover' => $group->cover]);
290
        $update->where->equalTo('id', $group->id);
291
 
292
        return $this->executeUpdate($update);
293
    }
294
 
295
 
296
    /**
297
     *
298
     * @param Group $group
299
     * return true
300
     */
301
    public function updateWebsite($group)
302
    {
303
        $update = $this->sql->update(self::_TABLE);
304
        $update->set(['website' => $group->website]);
305
        $update->where->equalTo('id', $group->id);
306
 
307
        return $this->executeUpdate($update);
308
    }
309
 
310
}