Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6388 | | 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
 
7063 efrain 224
    /*
1869 nelberth 225
    public function fetchAllDataTableForo($search, $page = 1, $records_per_page = 10, $order_field= 'added_on', $order_direction = 'DESC', $topic_id)
1855 nelberth 226
    {
227
        $prototype = new Feed();
228
        $select = $this->sql->select(self::_TABLE);
229
        $select->where->equalTo('topic_id', $topic_id);
1882 nelberth 230
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
1855 nelberth 231
        if($search) {
232
            $select->where->like('title', '%' . $search . '%');
233
        }
234
        $select->order($order_field . ' ' . $order_direction);
235
 
236
 
237
 
238
        $hydrator   = new ObjectPropertyHydrator();
239
        $resultset  = new HydratingResultSet($hydrator, $prototype);
240
 
241
        $adapter = new DbSelect($select, $this->sql, $resultset);
242
        $paginator = new Paginator($adapter);
243
        $paginator->setItemCountPerPage($records_per_page);
244
        $paginator->setCurrentPageNumber($page);
245
 
246
 
247
        return $paginator;
7063 efrain 248
    }*/
249
 
1907 nelberth 250
    public function fetchFiveForoJoinTopic($group_id,$topic_type)
1904 nelberth 251
    {
252
        $prototype = new Feed();
1910 nelberth 253
        $select = $this->sql->select();
1930 nelberth 254
        $select->from(['f' => self::_TABLE]);
255
        $select->join(['t' => TopicMapper::_TABLE], 't.id = f.topic_id ', []);
1923 nelberth 256
        $select->where->equalTo('f.high_performance_group_id', $group_id);
257
        $select->where->equalTo('f.status', Feed::STATUS_PUBLISHED);
1924 nelberth 258
        $select->where->equalTo('f.type', Feed::TYPE_HPTG);
1923 nelberth 259
        $select->where->equalTo('t.type', $topic_type);
260
        $select->where->equalTo('t.status', Topic::STATUS_ACTIVE);
1922 nelberth 261
 
262
        $select->order('added_on DESC');
1904 nelberth 263
 
264
        $hydrator   = new ObjectPropertyHydrator();
265
        $resultset  = new HydratingResultSet($hydrator, $prototype);
266
 
267
        $adapter = new DbSelect($select, $this->sql, $resultset);
268
        $paginator = new Paginator($adapter);
269
        $paginator->setItemCountPerPage(5);
270
        $paginator->setCurrentPageNumber(1);
271
 
272
 
273
        return $paginator;
274
    }
242 efrain 275
    /**
276
     *
1 www 277
     * @param int $shared_feed_id
278
     * @return int
279
     */
280
    public function fetchCountSharedByFeedId($shared_feed_id)
281
    {
282
        $select = $this->sql->select(self::_TABLE);
283
        $select->columns(['total' => new Expression('COUNT(*)') ]);
284
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
285
 
286
        $record = $this->executeFetchOneArray($select);
287
        return $record['total'];
288
    }
289
 
290
 
291
    /**
292
     *
293
     * @param Feed $feed
294
     * @return boolean
295
     */
296
    public function update($feed)
297
    {
298
        $hydrator = new ObjectPropertyHydrator();
299
        $values = $hydrator->extract($feed);
300
        $values = $this->removeEmpty($values);
301
 
302
        $update = $this->sql->update(self::_TABLE);
303
        $update->set($values);
304
        $update->where->equalTo('id', $feed->id);
305
 
424 geraldo 306
 
307
 
1 www 308
        return $this->executeUpdate($update);
309
    }
310
 
311
    /**
312
     *
313
     * @param Feed $feed
314
     * @return boolean
315
     */
316
    public function insert($feed)
317
    {
318
        $hydrator = new ObjectPropertyHydrator();
319
        $values = $hydrator->extract($feed);
428 geraldo 320
        $values = $this->removeEmpty($values);
1 www 321
 
322
        $insert = $this->sql->insert(self::_TABLE);
421 geraldo 323
        $insert->values($values);
1986 eleazar 324
        //echo $insert->getSqlString($this->adapter->platform); exit;
1 www 325
 
326
        $response = $this->executeInsert($insert);
327
        if($response) {
328
            $feed->id = $this->lastInsertId;
329
        }
330
 
426 geraldo 331
        return $values;
1 www 332
    }
333
 
334
    /**
335
     *
336
     * @param int $id
337
     * @return int
338
     */
339
    public function fetchTotalComments($id)
340
    {
341
        $select = $this->sql->select(self::_TABLE);
342
        $select->columns(['total_comments']);
343
        $select->where->equalTo('id', $id);
344
 
345
        $record = $this->executeFetchOneArray($select);
346
        return $record['total_comments'];
347
    }
348
 
349
    /**
350
     *
351
     * @param int $feed_id
352
     * @return boolean
353
     */
354
     /*
355
    public function incTotalComments($id)
356
    {
357
 
358
        $update = $this->sql->update(self::_TABLE);
359
        $update->set(['total_comments' => new Expression('total_comments + 1')]);
360
        $update->where->equalTo('id', $id);
361
 
362
        return $this->executeUpdate($update);
363
    }
364
    */
365
 
366
    /**
367
     *
368
     * @param int $feed_id
369
     * @return boolean
370
     */
371
    public function incTotalShared($id)
372
    {
373
        $update = $this->sql->update(self::_TABLE);
374
        $update->set(['total_shared' => new Expression('total_shared + 1')]);
375
        $update->where->equalTo('id', $id);
376
 
377
        return $this->executeUpdate($update);
378
    }
379
 
380
    /**
381
     *
382
     * @param int $id
383
     * @return int
384
     */
385
    public function fetchTotalShared($id)
386
    {
387
        $select = $this->sql->select(self::_TABLE);
388
        $select->columns(['total_shared']);
389
        $select->where->equalTo('id', $id);
390
 
391
        $record = $this->executeFetchOneArray($select);
392
        return $record['total_shared'];
393
    }
394
 
395
    /**
6388 efrain 396
     *
397
     * @param FastSurvey $fastSurvey
398
     * @return boolean
399
     */
400
    public function deleteByFastSurvey($fastSurvey)
401
    {
402
        $delete = $this->sql->delete(self::_TABLE);
403
        $delete->where->equalTo('fast_survey_id', $fastSurvey->id);
404
 
405
        return $this->executeDelete($delete);
406
    }
407
 
408
 
409
    /**
1 www 410
     *
411
     * @param int $feed_id
412
     * @return boolean
413
     */
414
    public function delete($feed_id)
415
    {
416
        $update = $this->sql->update(self::_TABLE);
417
        $update->set([
418
            'status' => Feed::STATUS_DELETED
419
        ]);
420
        $update->where->equalTo('id', $feed_id);
421
 
422
        return $this->executeUpdate($update);
423
    }
1980 eleazar 424
 
2012 eleazar 425
    /**
1980 eleazar 426
     *
2012 eleazar 427
     * @return Feed
1980 eleazar 428
     */
2012 eleazar 429
    public function fetchAllByMytQuestion()
1980 eleazar 430
    {
431
        $prototype = new Feed();
2012 eleazar 432
 
1980 eleazar 433
        $select = $this->sql->select(self::_TABLE);
1987 eleazar 434
        $select->where->equalTo('type', Feed::TYPE_MYT_QUESTION);
1988 eleazar 435
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
2137 eleazar 436
        $select->order('added_on DESC');
1980 eleazar 437
 
2012 eleazar 438
        return $this->executeFetchAllObject($select, $prototype);
1980 eleazar 439
    }
2011 eleazar 440
 
2051 eleazar 441
    /**
442
     *
443
     * @return Feed
444
     */
2072 eleazar 445
    public function fetchAllByMytAnswer($related_feed)
2051 eleazar 446
    {
447
        $prototype = new Feed();
448
 
449
        $select = $this->sql->select(self::_TABLE);
2072 eleazar 450
        $select->where->equalTo('related_feed', $related_feed);
2051 eleazar 451
        $select->where->equalTo('type', Feed::TYPE_MYT_ANSWER);
452
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
453
        $select->order('title');
454
 
455
        return $this->executeFetchAllObject($select, $prototype);
456
    }
457
 
2490 eleazar 458
      /**
459
     *
460
     * @return Feed
461
     */
462
    public function fetchAllByTopicId($topic_id)
463
    {
464
        $prototype = new Feed();
465
 
466
        $select = $this->sql->select(self::_TABLE);
467
        $select->where->equalTo('topic_id', $topic_id);
468
        $select->order('title');
469
 
470
        return $this->executeFetchAllObject($select, $prototype);
471
    }
472
 
2054 eleazar 473
    /**
474
     *
475
     * @return Feed
476
     */
477
    public function fetchAllByMytAnswerComented()
478
    {
479
        $prototype = new Feed();
480
 
481
        $select = $this->sql->select(self::_TABLE);
482
        $select->where->equalTo('type', Feed::TYPE_MYT_ANSWER);
483
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
484
        $select->order('title');
485
 
2056 eleazar 486
        return $this->executeFetchAllObject($select, $prototype);
2054 eleazar 487
    }
488
 
2237 eleazar 489
     /**
490
     *
491
     * @return Feed
492
     */
3261 kerby 493
    public function fetchAllByDevelop()
2237 eleazar 494
    {
495
        $prototype = new Feed();
496
 
497
        $select = $this->sql->select(self::_TABLE);
498
        $select->where->equalTo('type', Feed::TYPE_DC);
499
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
3128 kerby 500
        $select->order('added_on DESC');
2237 eleazar 501
 
502
        return $this->executeFetchAllObject($select, $prototype);
503
    }
3261 kerby 504
 
505
    public function fetchAllByDevelopContentPublished()
506
    {
507
        $prototype = new Feed();
508
 
509
        $select = $this->sql->select(self::_TABLE);
510
        $select->where->equalTo('type', Feed::TYPE_DC);
511
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
512
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
513
        $select->order('added_on DESC');
514
 
515
        return $this->executeFetchAllObject($select, $prototype);
516
    }
3032 kerby 517
    /**
518
     *
519
     * @return Feed
520
     */
3261 kerby 521
    public function fetchAllByDevelopContentByCategoryId($id)
3032 kerby 522
    {
523
        $prototype = new Feed();
2237 eleazar 524
 
3032 kerby 525
        $select = $this->sql->select(self::_TABLE);
526
        $select->where->equalTo('type', Feed::TYPE_DC);
527
        $select->where->equalTo('topic_id', $id);
528
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
3261 kerby 529
 
530
        $select->order('added_on DESC');
531
 
532
        return $this->executeFetchAllObject($select, $prototype);
533
    }
534
 
535
    /**
536
     *
537
     * @return Feed
538
     */
3291 kerby 539
    public function fetchAllByDevelopContentPublishedByCategoryId($id)
3261 kerby 540
    {
541
        $prototype = new Feed();
542
 
543
        $select = $this->sql->select(self::_TABLE);
544
        $select->where->equalTo('type', Feed::TYPE_DC);
545
        $select->where->equalTo('topic_id', $id);
546
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
3291 kerby 547
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
3140 kerby 548
 
3032 kerby 549
        $select->order('added_on DESC');
550
 
551
        return $this->executeFetchAllObject($select, $prototype);
552
    }
553
 
554
 
3261 kerby 555
 
3211 kerby 556
    /**
557
     *
558
     * @return Feed
559
     */
560
    public function fetchAllByDevelopAndCategoryIdCount($id)
561
    {
562
        $select = $this->sql->select(self::_TABLE);
563
        $select->columns(['total' => new Expression('COUNT(id)')]);
3212 kerby 564
        $select->where->equalTo('topic_id', $id);
565
        $select->where->equalTo('type', Feed::TYPE_DC);
3211 kerby 566
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
567
        $record = $this->executeFetchOneArray($select);
568
        return $record['total'];
569
    }
570
 
571
 
2337 eleazar 572
     /**
573
     *
574
     * @return Feed
575
     */
576
    public function fetchAllByDevelopInternContent()
577
    {
578
        $prototype = new Feed();
579
 
580
        $select = $this->sql->select(self::_TABLE);
581
        $select->where->equalTo('type', Feed::TYPE_DC);
2489 eleazar 582
        //$select->where->equalTo('link_media', 'cesa');
2488 eleazar 583
        $select->where->isNotNull('file_type');
2337 eleazar 584
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
585
        $select->order('title');
2482 eleazar 586
        //echo $insert->getSqlString($this->adapter->platform); exit;
2337 eleazar 587
        return $this->executeFetchAllObject($select, $prototype);
588
    }
589
 
590
      /**
591
     *
592
     * @return Feed
593
     */
594
    public function fetchAllByDevelopExternContent()
595
    {
596
        $prototype = new Feed();
597
 
598
        $select = $this->sql->select(self::_TABLE);
599
        $select->where->equalTo('type', Feed::TYPE_DC);
600
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
601
        $select->where->notEqualTo('link_media', 'cesa');
602
        $select->order('title');
603
 
604
        return $this->executeFetchAllObject($select, $prototype);
605
    }
4778 efrain 606
 
607
 
2337 eleazar 608
 
4778 efrain 609
    /**
610
     *
611
     * @param int $feed_id
612
     * @return boolean
613
     */
614
    public function incTotalExternalShared($id)
615
    {
616
        $update = $this->sql->update(self::_TABLE);
617
        $update->set(['total_external_shared' => new Expression('total_external_shared + 1')]);
618
        $update->where->equalTo('id', $id);
619
 
620
        return $this->executeUpdate($update);
621
    }
622
 
623
    /**
624
     *
625
     * @param int $id
626
     * @return int
627
     */
628
    public function fetchTotalExternalShared($id)
629
    {
630
        $select = $this->sql->select(self::_TABLE);
631
        $select->columns(['total_external_shared']);
632
        $select->where->equalTo('id', $id);
633
 
634
        $record = $this->executeFetchOneArray($select);
635
        return $record['total_external_shared'];
636
    }
637
 
1 www 638
}