Proyectos de Subversion LeadersLinked - Services

Rev

Rev 283 | | 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 Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Db\Sql\Expression;
9
use Laminas\Log\LoggerInterface;
10
use LeadersLinked\Mapper\Common\MapperCommon;
11
use LeadersLinked\Model\Feed;
12
use LeadersLinked\Model\Topic;
13
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
14
use Laminas\Paginator\Paginator;
15
use Laminas\Db\ResultSet\HydratingResultSet;
16
use Laminas\Paginator\Adapter\DbSelect;
17
use LeadersLinked\Mapper\TopicMapper;
18
use LeadersLinked\Model\FastSurvey;
345 www 19
use LeadersLinked\Library\Storage;
1 efrain 20
 
21
class FeedMapper extends MapperCommon
22
{
23
    const _TABLE = 'tbl_feeds';
24
 
25
 
26
    /**
27
     *
28
     * @var FeedMapper
29
     */
30
    private static $_instance;
31
 
32
    /**
33
     *
34
     * @param AdapterInterface $adapter
35
     */
36
    private function __construct($adapter)
37
    {
38
        parent::__construct($adapter);
39
    }
40
 
41
    /**
42
     *
43
     * @param AdapterInterface $adapter
44
     * @return \LeadersLinked\Mapper\FeedMapper
45
     */
46
    public static function getInstance($adapter)
47
    {
48
        if(self::$_instance == null) {
49
            self::$_instance = new FeedMapper($adapter);
50
        }
51
        return self::$_instance;
52
    }
53
 
54
    /*
55
    public function fetchCountSharesByFeedId(int $shared_feed_id)
56
    {
57
        $select = $this->sql->select(self::_TABLE);
58
        $select->columns(['total' => new Expression('COUNT(*)') ]);
59
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
60
 
61
        $record = $this->executeFetchOneArray($select);
62
        return $record['total'];
63
    }*/
64
 
65
    /**
66
     *
67
     * @param int $id
68
     * @return Feed
69
     */
70
    public function fetchOne($id)
71
    {
72
        $prototype = new Feed();
73
        $select = $this->sql->select(self::_TABLE);
74
        $select->where->equalTo('id', $id);
75
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
76
        //$select->getSqlString($this->adapter->platform);
77
 
78
        return $this->executeFetchOneObject($select, $prototype);
79
    }
80
 
81
 
82
    /**
83
     *
84
     * @param int $id
85
     * @param int $network_id
86
     * @return Feed
87
     */
88
    public function fetchOneByIdAndNetworkId($id, $network_id)
89
    {
90
        $prototype = new Feed();
91
        $select = $this->sql->select(self::_TABLE);
92
        $select->where->equalTo('id', $id);
93
        $select->where->equalTo('network_id', $network_id);
94
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
95
        //$select->getSqlString($this->adapter->platform);
96
 
97
        return $this->executeFetchOneObject($select, $prototype);
98
    }
99
 
192 efrain 100
 
1 efrain 101
 
102
    /**
103
     *
104
     * @param int $id
105
     * @return Feed
106
     */
107
    public function fetchOneAnyStatus($id)
108
    {
109
        $prototype = new Feed();
110
        $select = $this->sql->select(self::_TABLE);
111
        $select->where->equalTo('id', $id);
112
 
113
 
114
        return $this->executeFetchOneObject($select, $prototype);
115
    }
116
 
117
    /**
118
     *
119
     * @param int $feed_uuid
120
     * @return Feed
121
     */
122
    public function fetchOneByUuid($uuid)
123
    {
124
        $prototype = new Feed();
125
        $select = $this->sql->select(self::_TABLE);
126
        $select->where->equalTo('uuid', $uuid);
127
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
128
        //$select->getSqlString($this->adapter->platform);
129
 
130
        return $this->executeFetchOneObject($select, $prototype);
131
    }
132
 
133
    /**
134
     *
135
     * @param int $feed_uuid
136
     * @return Feed
137
     */
138
    public function fetchOneByUuidAndNetworkId($uuid, $network_id)
139
    {
140
        $prototype = new Feed();
141
        $select = $this->sql->select(self::_TABLE);
142
        $select->where->equalTo('uuid', $uuid);
143
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
144
        //$select->getSqlString($this->adapter->platform);
145
 
146
        return $this->executeFetchOneObject($select, $prototype);
147
    }
148
 
149
 
150
    /**
151
     *
152
     * @param string $feed_uuid
153
     * @return Feed
154
     */
155
    public function fetchOneByUuidAnyStatus($uuid)
156
    {
157
        $prototype = new Feed();
158
        $select = $this->sql->select(self::_TABLE);
159
        $select->where->equalTo('uuid', $uuid);
160
 
161
 
162
        return $this->executeFetchOneObject($select, $prototype);
163
    }
164
 
165
 
166
    /**
167
     *
168
     * @param string $feed_uuid
169
     * @param int $network_id
170
     * @return Feed
171
     */
172
    public function fetchOneByUuidAndNetworkIdAnyStatus($uuid, $network_id)
173
    {
174
        $prototype = new Feed();
175
        $select = $this->sql->select(self::_TABLE);
176
        $select->where->equalTo('uuid', $uuid);
177
        $select->where->equalTo('network_id', $network_id);
178
 
179
        return $this->executeFetchOneObject($select, $prototype);
180
    }
181
 
182
 
183
 
184
    /**
185
     *
186
     * @return Feed[]
187
     */
188
    public function fetchAllTypeVideo()
189
    {
190
        $select = $this->sql->select(self::_TABLE);
345 www 191
        $select->where->equalTo('file_type', Storage::FILE_TYPE_VIDEO);
1 efrain 192
 
193
        //echo $select->getSqlString($this->adapter->platform);
194
 
195
        $prototype = new Feed();
196
        return $this->executeFetchAllObject($select, $prototype);
197
    }
198
 
199
    public function fetchAllTypeCalendar($highPerformanceTeamsGroups_id)
200
    {
201
        $select = $this->sql->select(self::_TABLE);
202
        $select->where->equalTo('file_type', Feed::FILE_TYPE_MEETING);
203
 
204
        $select->where->equalTo('high_performance_group_id',$highPerformanceTeamsGroups_id);
205
        //echo $select->getSqlString($this->adapter->platform);
206
 
207
        $prototype = new Feed();
208
        return $this->executeFetchAllObject($select, $prototype);
209
    }
210
 
211
    /*
212
    public function fetchAllDataTableForo($search, $page = 1, $records_per_page = 10, $order_field= 'added_on', $order_direction = 'DESC', $topic_id)
213
    {
214
        $prototype = new Feed();
215
        $select = $this->sql->select(self::_TABLE);
216
        $select->where->equalTo('topic_id', $topic_id);
217
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
218
        if($search) {
219
            $select->where->like('title', '%' . $search . '%');
220
        }
221
        $select->order($order_field . ' ' . $order_direction);
222
 
223
 
224
 
225
        $hydrator   = new ObjectPropertyHydrator();
226
        $resultset  = new HydratingResultSet($hydrator, $prototype);
227
 
228
        $adapter = new DbSelect($select, $this->sql, $resultset);
229
        $paginator = new Paginator($adapter);
230
        $paginator->setItemCountPerPage($records_per_page);
231
        $paginator->setCurrentPageNumber($page);
232
 
233
 
234
        return $paginator;
235
    }*/
236
 
192 efrain 237
 
1 efrain 238
    /**
239
     *
240
     * @param int $shared_feed_id
241
     * @return int
242
     */
243
    public function fetchCountSharedByFeedId($shared_feed_id)
244
    {
245
        $select = $this->sql->select(self::_TABLE);
246
        $select->columns(['total' => new Expression('COUNT(*)') ]);
247
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
248
 
249
        $record = $this->executeFetchOneArray($select);
250
        return $record['total'];
251
    }
252
 
253
 
254
    /**
255
     *
256
     * @param Feed $feed
257
     * @return boolean
258
     */
259
    public function update($feed)
260
    {
261
        $hydrator = new ObjectPropertyHydrator();
262
        $values = $hydrator->extract($feed);
263
        $values = $this->removeEmpty($values);
264
 
283 www 265
        if(empty($values['publish_on'])) {
266
            $values['publish_on'] = new Expression('CURRENT_DATE()');
267
        }
268
 
1 efrain 269
        $update = $this->sql->update(self::_TABLE);
270
        $update->set($values);
271
        $update->where->equalTo('id', $feed->id);
272
 
273
 
274
 
275
        return $this->executeUpdate($update);
276
    }
277
 
278
    /**
279
     *
280
     * @param Feed $feed
281
     * @return boolean
282
     */
283
    public function insert($feed)
284
    {
285
        $hydrator = new ObjectPropertyHydrator();
286
        $values = $hydrator->extract($feed);
287
        $values = $this->removeEmpty($values);
288
 
283 www 289
        if(empty($values['publish_on'])) {
290
            $values['publish_on'] = new Expression('CURRENT_DATE()');
291
        }
292
 
1 efrain 293
        $insert = $this->sql->insert(self::_TABLE);
294
        $insert->values($values);
295
        //echo $insert->getSqlString($this->adapter->platform); exit;
296
 
297
        $response = $this->executeInsert($insert);
298
        if($response) {
299
            $feed->id = $this->lastInsertId;
300
        }
301
 
302
        return $values;
303
    }
304
 
305
    /**
306
     *
307
     * @param int $id
308
     * @return int
309
     */
310
    public function fetchTotalComments($id)
311
    {
312
        $select = $this->sql->select(self::_TABLE);
313
        $select->columns(['total_comments']);
314
        $select->where->equalTo('id', $id);
315
 
316
        $record = $this->executeFetchOneArray($select);
317
        return $record['total_comments'];
318
    }
319
 
320
    /**
321
     *
322
     * @param int $feed_id
323
     * @return boolean
324
     */
325
     /*
326
    public function incTotalComments($id)
327
    {
328
 
329
        $update = $this->sql->update(self::_TABLE);
330
        $update->set(['total_comments' => new Expression('total_comments + 1')]);
331
        $update->where->equalTo('id', $id);
332
 
333
        return $this->executeUpdate($update);
334
    }
335
    */
336
 
337
    /**
338
     *
339
     * @param int $feed_id
340
     * @return boolean
341
     */
342
    public function incTotalShared($id)
343
    {
344
        $update = $this->sql->update(self::_TABLE);
345
        $update->set(['total_shared' => new Expression('total_shared + 1')]);
346
        $update->where->equalTo('id', $id);
347
 
348
        return $this->executeUpdate($update);
349
    }
350
 
351
    /**
352
     *
353
     * @param int $id
354
     * @return int
355
     */
356
    public function fetchTotalShared($id)
357
    {
358
        $select = $this->sql->select(self::_TABLE);
359
        $select->columns(['total_shared']);
360
        $select->where->equalTo('id', $id);
361
 
362
        $record = $this->executeFetchOneArray($select);
363
        return $record['total_shared'];
364
    }
365
 
366
    /**
367
     *
368
     * @param FastSurvey $fastSurvey
369
     * @return boolean
370
     */
371
    public function deleteByFastSurvey($fastSurvey)
372
    {
373
        $delete = $this->sql->delete(self::_TABLE);
374
        $delete->where->equalTo('fast_survey_id', $fastSurvey->id);
375
 
376
        return $this->executeDelete($delete);
377
    }
378
 
379
 
380
    /**
381
     *
382
     * @param int $feed_id
383
     * @return boolean
384
     */
385
    public function delete($feed_id)
386
    {
387
        $update = $this->sql->update(self::_TABLE);
388
        $update->set([
389
            'status' => Feed::STATUS_DELETED
390
        ]);
391
        $update->where->equalTo('id', $feed_id);
392
 
393
        return $this->executeUpdate($update);
394
    }
395
 
396
 
397
 
398
    /**
399
     *
400
     * @param int $feed_id
401
     * @return boolean
402
     */
403
    public function incTotalExternalShared($id)
404
    {
405
        $update = $this->sql->update(self::_TABLE);
406
        $update->set(['total_external_shared' => new Expression('total_external_shared + 1')]);
407
        $update->where->equalTo('id', $id);
408
 
409
        return $this->executeUpdate($update);
410
    }
411
 
412
    /**
413
     *
414
     * @param int $id
415
     * @return int
416
     */
417
    public function fetchTotalExternalShared($id)
418
    {
419
        $select = $this->sql->select(self::_TABLE);
420
        $select->columns(['total_external_shared']);
421
        $select->where->equalTo('id', $id);
422
 
423
        $record = $this->executeFetchOneArray($select);
424
        return $record['total_external_shared'];
425
    }
283 www 426
 
427
    /**
428
     *
429
     * @return Feed[]
430
     */
431
    public function fetchAll()
432
    {
433
        $select = $this->sql->select(self::_TABLE);
434
 
435
        $prototype = new Feed();
436
        return $this->executeFetchAllObject($select, $prototype);
437
    }
1 efrain 438
 
439
}