Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3639 | Rev 6388 | Ir a la última revisión | | 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\Sql\Expression;
9
use Laminas\Log\LoggerInterface;
10
use LeadersLinked\Mapper\Common\MapperCommon;
11
use LeadersLinked\Model\Feed;
1904 nelberth 12
use LeadersLinked\Model\Topic;
1 www 13
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
1858 nelberth 14
use Laminas\Paginator\Paginator;
1859 nelberth 15
use Laminas\Db\ResultSet\HydratingResultSet;
1860 nelberth 16
use Laminas\Paginator\Adapter\DbSelect;
1904 nelberth 17
use LeadersLinked\Mapper\TopicMapper;
1 www 18
 
19
class FeedMapper extends MapperCommon
20
{
21
    const _TABLE = 'tbl_feeds';
22
 
23
 
24
    /**
25
     *
26
     * @var FeedMapper
27
     */
28
    private static $_instance;
29
 
30
    /**
31
     *
32
     * @param AdapterInterface $adapter
33
     */
34
    private function __construct($adapter)
35
    {
36
        parent::__construct($adapter);
37
    }
38
 
39
    /**
40
     *
41
     * @param AdapterInterface $adapter
42
     * @return \LeadersLinked\Mapper\FeedMapper
43
     */
44
    public static function getInstance($adapter)
45
    {
46
        if(self::$_instance == null) {
47
            self::$_instance = new FeedMapper($adapter);
48
        }
49
        return self::$_instance;
50
    }
51
 
52
    /*
53
    public function fetchCountSharesByFeedId(int $shared_feed_id)
54
    {
55
        $select = $this->sql->select(self::_TABLE);
56
        $select->columns(['total' => new Expression('COUNT(*)') ]);
57
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
58
 
59
        $record = $this->executeFetchOneArray($select);
60
        return $record['total'];
61
    }*/
62
 
63
    /**
64
     *
65
     * @param int $id
66
     * @return Feed
67
     */
68
    public function fetchOne($id)
2154 eleazar 69
    {
70
        $prototype = new Feed();
1 www 71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('id', $id);
2163 eleazar 73
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
2156 eleazar 74
        //$select->getSqlString($this->adapter->platform);
2110 eleazar 75
 
76
        return $this->executeFetchOneObject($select, $prototype);
77
    }
3639 efrain 78
 
79
 
80
    /**
81
     *
82
     * @param int $id
83
     * @param int $network_id
84
     * @return Feed
85
     */
86
    public function fetchOneByIdAndNetworkId($id, $network_id)
87
    {
88
        $prototype = new Feed();
89
        $select = $this->sql->select(self::_TABLE);
90
        $select->where->equalTo('id', $id);
91
        $select->where->equalTo('network_id', $network_id);
92
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
93
        //$select->getSqlString($this->adapter->platform);
94
 
95
        return $this->executeFetchOneObject($select, $prototype);
96
    }
2110 eleazar 97
 
98
     /**
99
     *
100
     * @param int $id
101
     * @return Feed
102
     */
103
    public function fetchOneNonDeleted($id)
104
    {
105
        $select = $this->sql->select(self::_TABLE);
106
        $select->where->equalTo('id', $id);
107
        $select->where->equalTo('type', Feed::TYPE_MYT_QUESTION);
2109 eleazar 108
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
1 www 109
 
110
        $prototype = new Feed();
111
        return $this->executeFetchOneObject($select, $prototype);
112
    }
113
 
114
    /**
115
     *
3143 efrain 116
     * @param int $id
117
     * @return Feed
118
     */
119
    public function fetchOneAnyStatus($id)
120
    {
121
        $prototype = new Feed();
122
        $select = $this->sql->select(self::_TABLE);
123
        $select->where->equalTo('id', $id);
124
 
125
 
126
        return $this->executeFetchOneObject($select, $prototype);
127
    }
128
 
129
    /**
130
     *
1 www 131
     * @param int $feed_uuid
132
     * @return Feed
133
     */
134
    public function fetchOneByUuid($uuid)
3146 efrain 135
    {
136
        $prototype = new Feed();
1 www 137
        $select = $this->sql->select(self::_TABLE);
138
        $select->where->equalTo('uuid', $uuid);
2163 eleazar 139
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
2155 eleazar 140
        //$select->getSqlString($this->adapter->platform);
2150 eleazar 141
 
1 www 142
        return $this->executeFetchOneObject($select, $prototype);
143
    }
144
 
145
    /**
146
     *
3146 efrain 147
     * @param int $feed_uuid
148
     * @return Feed
149
     */
3639 efrain 150
    public function fetchOneByUuidAndNetworkId($uuid, $network_id)
151
    {
152
        $prototype = new Feed();
153
        $select = $this->sql->select(self::_TABLE);
154
        $select->where->equalTo('uuid', $uuid);
155
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
156
        //$select->getSqlString($this->adapter->platform);
157
 
158
        return $this->executeFetchOneObject($select, $prototype);
159
    }
160
 
161
 
162
    /**
163
     *
164
     * @param string $feed_uuid
165
     * @return Feed
166
     */
3146 efrain 167
    public function fetchOneByUuidAnyStatus($uuid)
168
    {
169
        $prototype = new Feed();
170
        $select = $this->sql->select(self::_TABLE);
171
        $select->where->equalTo('uuid', $uuid);
172
 
173
 
174
        return $this->executeFetchOneObject($select, $prototype);
175
    }
176
 
3639 efrain 177
 
3146 efrain 178
    /**
179
     *
3639 efrain 180
     * @param string $feed_uuid
181
     * @param int $network_id
182
     * @return Feed
183
     */
184
    public function fetchOneByUuidAndNetworkIdAnyStatus($uuid, $network_id)
185
    {
186
        $prototype = new Feed();
187
        $select = $this->sql->select(self::_TABLE);
188
        $select->where->equalTo('uuid', $uuid);
189
        $select->where->equalTo('network_id', $network_id);
190
 
191
        return $this->executeFetchOneObject($select, $prototype);
192
    }
193
 
194
 
195
 
196
    /**
197
     *
242 efrain 198
     * @return Feed[]
199
     */
200
    public function fetchAllTypeVideo()
201
    {
202
        $select = $this->sql->select(self::_TABLE);
203
        $select->where->equalTo('file_type', Feed::FILE_TYPE_VIDEO);
204
 
205
        //echo $select->getSqlString($this->adapter->platform);
206
 
207
        $prototype = new Feed();
208
        return $this->executeFetchAllObject($select, $prototype);
209
    }
1776 nelberth 210
 
211
    public function fetchAllTypeCalendar($highPerformanceTeamsGroups_id)
212
    {
213
        $select = $this->sql->select(self::_TABLE);
214
        $select->where->equalTo('file_type', Feed::FILE_TYPE_MEETING);
215
 
216
        $select->where->equalTo('high_performance_group_id',$highPerformanceTeamsGroups_id);
217
        //echo $select->getSqlString($this->adapter->platform);
218
 
219
        $prototype = new Feed();
220
        return $this->executeFetchAllObject($select, $prototype);
221
    }
242 efrain 222
 
1869 nelberth 223
    public function fetchAllDataTableForo($search, $page = 1, $records_per_page = 10, $order_field= 'added_on', $order_direction = 'DESC', $topic_id)
1855 nelberth 224
    {
225
        $prototype = new Feed();
226
        $select = $this->sql->select(self::_TABLE);
227
        $select->where->equalTo('topic_id', $topic_id);
1882 nelberth 228
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
1855 nelberth 229
        if($search) {
230
            $select->where->like('title', '%' . $search . '%');
231
        }
232
        $select->order($order_field . ' ' . $order_direction);
233
 
234
 
235
 
236
        $hydrator   = new ObjectPropertyHydrator();
237
        $resultset  = new HydratingResultSet($hydrator, $prototype);
238
 
239
        $adapter = new DbSelect($select, $this->sql, $resultset);
240
        $paginator = new Paginator($adapter);
241
        $paginator->setItemCountPerPage($records_per_page);
242
        $paginator->setCurrentPageNumber($page);
243
 
244
 
245
        return $paginator;
246
    }
1907 nelberth 247
    public function fetchFiveForoJoinTopic($group_id,$topic_type)
1904 nelberth 248
    {
249
        $prototype = new Feed();
1910 nelberth 250
        $select = $this->sql->select();
1930 nelberth 251
        $select->from(['f' => self::_TABLE]);
252
        $select->join(['t' => TopicMapper::_TABLE], 't.id = f.topic_id ', []);
1923 nelberth 253
        $select->where->equalTo('f.high_performance_group_id', $group_id);
254
        $select->where->equalTo('f.status', Feed::STATUS_PUBLISHED);
1924 nelberth 255
        $select->where->equalTo('f.type', Feed::TYPE_HPTG);
1923 nelberth 256
        $select->where->equalTo('t.type', $topic_type);
257
        $select->where->equalTo('t.status', Topic::STATUS_ACTIVE);
1922 nelberth 258
 
259
        $select->order('added_on DESC');
1904 nelberth 260
 
261
        $hydrator   = new ObjectPropertyHydrator();
262
        $resultset  = new HydratingResultSet($hydrator, $prototype);
263
 
264
        $adapter = new DbSelect($select, $this->sql, $resultset);
265
        $paginator = new Paginator($adapter);
266
        $paginator->setItemCountPerPage(5);
267
        $paginator->setCurrentPageNumber(1);
268
 
269
 
270
        return $paginator;
271
    }
242 efrain 272
    /**
273
     *
1 www 274
     * @param int $shared_feed_id
275
     * @return int
276
     */
277
    public function fetchCountSharedByFeedId($shared_feed_id)
278
    {
279
        $select = $this->sql->select(self::_TABLE);
280
        $select->columns(['total' => new Expression('COUNT(*)') ]);
281
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
282
 
283
        $record = $this->executeFetchOneArray($select);
284
        return $record['total'];
285
    }
286
 
287
 
288
    /**
289
     *
290
     * @param Feed $feed
291
     * @return boolean
292
     */
293
    public function update($feed)
294
    {
295
        $hydrator = new ObjectPropertyHydrator();
296
        $values = $hydrator->extract($feed);
297
        $values = $this->removeEmpty($values);
298
 
299
        $update = $this->sql->update(self::_TABLE);
300
        $update->set($values);
301
        $update->where->equalTo('id', $feed->id);
302
 
424 geraldo 303
 
304
 
1 www 305
        return $this->executeUpdate($update);
306
    }
307
 
308
    /**
309
     *
310
     * @param Feed $feed
311
     * @return boolean
312
     */
313
    public function insert($feed)
314
    {
315
        $hydrator = new ObjectPropertyHydrator();
316
        $values = $hydrator->extract($feed);
428 geraldo 317
        $values = $this->removeEmpty($values);
1 www 318
 
319
        $insert = $this->sql->insert(self::_TABLE);
421 geraldo 320
        $insert->values($values);
1986 eleazar 321
        //echo $insert->getSqlString($this->adapter->platform); exit;
1 www 322
 
323
        $response = $this->executeInsert($insert);
324
        if($response) {
325
            $feed->id = $this->lastInsertId;
326
        }
327
 
426 geraldo 328
        return $values;
1 www 329
    }
330
 
331
    /**
332
     *
333
     * @param int $id
334
     * @return int
335
     */
336
    public function fetchTotalComments($id)
337
    {
338
        $select = $this->sql->select(self::_TABLE);
339
        $select->columns(['total_comments']);
340
        $select->where->equalTo('id', $id);
341
 
342
        $record = $this->executeFetchOneArray($select);
343
        return $record['total_comments'];
344
    }
345
 
346
    /**
347
     *
348
     * @param int $feed_id
349
     * @return boolean
350
     */
351
     /*
352
    public function incTotalComments($id)
353
    {
354
 
355
        $update = $this->sql->update(self::_TABLE);
356
        $update->set(['total_comments' => new Expression('total_comments + 1')]);
357
        $update->where->equalTo('id', $id);
358
 
359
        return $this->executeUpdate($update);
360
    }
361
    */
362
 
363
    /**
364
     *
365
     * @param int $feed_id
366
     * @return boolean
367
     */
368
    public function incTotalShared($id)
369
    {
370
        $update = $this->sql->update(self::_TABLE);
371
        $update->set(['total_shared' => new Expression('total_shared + 1')]);
372
        $update->where->equalTo('id', $id);
373
 
374
        return $this->executeUpdate($update);
375
    }
376
 
377
    /**
378
     *
379
     * @param int $id
380
     * @return int
381
     */
382
    public function fetchTotalShared($id)
383
    {
384
        $select = $this->sql->select(self::_TABLE);
385
        $select->columns(['total_shared']);
386
        $select->where->equalTo('id', $id);
387
 
388
        $record = $this->executeFetchOneArray($select);
389
        return $record['total_shared'];
390
    }
391
 
392
    /**
393
     *
394
     * @param int $feed_id
395
     * @return boolean
396
     */
397
    public function delete($feed_id)
398
    {
399
        $update = $this->sql->update(self::_TABLE);
400
        $update->set([
401
            'status' => Feed::STATUS_DELETED
402
        ]);
403
        $update->where->equalTo('id', $feed_id);
404
 
405
        return $this->executeUpdate($update);
406
    }
1980 eleazar 407
 
2012 eleazar 408
    /**
1980 eleazar 409
     *
2012 eleazar 410
     * @return Feed
1980 eleazar 411
     */
2012 eleazar 412
    public function fetchAllByMytQuestion()
1980 eleazar 413
    {
414
        $prototype = new Feed();
2012 eleazar 415
 
1980 eleazar 416
        $select = $this->sql->select(self::_TABLE);
1987 eleazar 417
        $select->where->equalTo('type', Feed::TYPE_MYT_QUESTION);
1988 eleazar 418
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
2137 eleazar 419
        $select->order('added_on DESC');
1980 eleazar 420
 
2012 eleazar 421
        return $this->executeFetchAllObject($select, $prototype);
1980 eleazar 422
    }
2011 eleazar 423
 
2051 eleazar 424
    /**
425
     *
426
     * @return Feed
427
     */
2072 eleazar 428
    public function fetchAllByMytAnswer($related_feed)
2051 eleazar 429
    {
430
        $prototype = new Feed();
431
 
432
        $select = $this->sql->select(self::_TABLE);
2072 eleazar 433
        $select->where->equalTo('related_feed', $related_feed);
2051 eleazar 434
        $select->where->equalTo('type', Feed::TYPE_MYT_ANSWER);
435
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
436
        $select->order('title');
437
 
438
        return $this->executeFetchAllObject($select, $prototype);
439
    }
440
 
2490 eleazar 441
      /**
442
     *
443
     * @return Feed
444
     */
445
    public function fetchAllByTopicId($topic_id)
446
    {
447
        $prototype = new Feed();
448
 
449
        $select = $this->sql->select(self::_TABLE);
450
        $select->where->equalTo('topic_id', $topic_id);
451
        $select->order('title');
452
 
453
        return $this->executeFetchAllObject($select, $prototype);
454
    }
455
 
2054 eleazar 456
    /**
457
     *
458
     * @return Feed
459
     */
460
    public function fetchAllByMytAnswerComented()
461
    {
462
        $prototype = new Feed();
463
 
464
        $select = $this->sql->select(self::_TABLE);
465
        $select->where->equalTo('type', Feed::TYPE_MYT_ANSWER);
466
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
467
        $select->order('title');
468
 
2056 eleazar 469
        return $this->executeFetchAllObject($select, $prototype);
2054 eleazar 470
    }
471
 
2237 eleazar 472
     /**
473
     *
474
     * @return Feed
475
     */
3261 kerby 476
    public function fetchAllByDevelop()
2237 eleazar 477
    {
478
        $prototype = new Feed();
479
 
480
        $select = $this->sql->select(self::_TABLE);
481
        $select->where->equalTo('type', Feed::TYPE_DC);
482
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
3128 kerby 483
        $select->order('added_on DESC');
2237 eleazar 484
 
485
        return $this->executeFetchAllObject($select, $prototype);
486
    }
3261 kerby 487
 
488
    public function fetchAllByDevelopContentPublished()
489
    {
490
        $prototype = new Feed();
491
 
492
        $select = $this->sql->select(self::_TABLE);
493
        $select->where->equalTo('type', Feed::TYPE_DC);
494
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
495
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
496
        $select->order('added_on DESC');
497
 
498
        return $this->executeFetchAllObject($select, $prototype);
499
    }
3032 kerby 500
    /**
501
     *
502
     * @return Feed
503
     */
3261 kerby 504
    public function fetchAllByDevelopContentByCategoryId($id)
3032 kerby 505
    {
506
        $prototype = new Feed();
2237 eleazar 507
 
3032 kerby 508
        $select = $this->sql->select(self::_TABLE);
509
        $select->where->equalTo('type', Feed::TYPE_DC);
510
        $select->where->equalTo('topic_id', $id);
511
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
3261 kerby 512
 
513
        $select->order('added_on DESC');
514
 
515
        return $this->executeFetchAllObject($select, $prototype);
516
    }
517
 
518
    /**
519
     *
520
     * @return Feed
521
     */
3291 kerby 522
    public function fetchAllByDevelopContentPublishedByCategoryId($id)
3261 kerby 523
    {
524
        $prototype = new Feed();
525
 
526
        $select = $this->sql->select(self::_TABLE);
527
        $select->where->equalTo('type', Feed::TYPE_DC);
528
        $select->where->equalTo('topic_id', $id);
529
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
3291 kerby 530
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
3140 kerby 531
 
3032 kerby 532
        $select->order('added_on DESC');
533
 
534
        return $this->executeFetchAllObject($select, $prototype);
535
    }
536
 
537
 
3261 kerby 538
 
3211 kerby 539
    /**
540
     *
541
     * @return Feed
542
     */
543
    public function fetchAllByDevelopAndCategoryIdCount($id)
544
    {
545
        $select = $this->sql->select(self::_TABLE);
546
        $select->columns(['total' => new Expression('COUNT(id)')]);
3212 kerby 547
        $select->where->equalTo('topic_id', $id);
548
        $select->where->equalTo('type', Feed::TYPE_DC);
3211 kerby 549
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
550
        $record = $this->executeFetchOneArray($select);
551
        return $record['total'];
552
    }
553
 
554
 
2337 eleazar 555
     /**
556
     *
557
     * @return Feed
558
     */
559
    public function fetchAllByDevelopInternContent()
560
    {
561
        $prototype = new Feed();
562
 
563
        $select = $this->sql->select(self::_TABLE);
564
        $select->where->equalTo('type', Feed::TYPE_DC);
2489 eleazar 565
        //$select->where->equalTo('link_media', 'cesa');
2488 eleazar 566
        $select->where->isNotNull('file_type');
2337 eleazar 567
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
568
        $select->order('title');
2482 eleazar 569
        //echo $insert->getSqlString($this->adapter->platform); exit;
2337 eleazar 570
        return $this->executeFetchAllObject($select, $prototype);
571
    }
572
 
573
      /**
574
     *
575
     * @return Feed
576
     */
577
    public function fetchAllByDevelopExternContent()
578
    {
579
        $prototype = new Feed();
580
 
581
        $select = $this->sql->select(self::_TABLE);
582
        $select->where->equalTo('type', Feed::TYPE_DC);
583
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
584
        $select->where->notEqualTo('link_media', 'cesa');
585
        $select->order('title');
586
 
587
        return $this->executeFetchAllObject($select, $prototype);
588
    }
4778 efrain 589
 
590
 
2337 eleazar 591
 
4778 efrain 592
    /**
593
     *
594
     * @param int $feed_id
595
     * @return boolean
596
     */
597
    public function incTotalExternalShared($id)
598
    {
599
        $update = $this->sql->update(self::_TABLE);
600
        $update->set(['total_external_shared' => new Expression('total_external_shared + 1')]);
601
        $update->where->equalTo('id', $id);
602
 
603
        return $this->executeUpdate($update);
604
    }
605
 
606
    /**
607
     *
608
     * @param int $id
609
     * @return int
610
     */
611
    public function fetchTotalExternalShared($id)
612
    {
613
        $select = $this->sql->select(self::_TABLE);
614
        $select->columns(['total_external_shared']);
615
        $select->where->equalTo('id', $id);
616
 
617
        $record = $this->executeFetchOneArray($select);
618
        return $record['total_external_shared'];
619
    }
620
 
1 www 621
}