Proyectos de Subversion LeadersLinked - Services

Rev

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