Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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