Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3143 | Rev 3210 | 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
    }
78
 
79
     /**
80
     *
81
     * @param int $id
82
     * @return Feed
83
     */
84
    public function fetchOneNonDeleted($id)
85
    {
86
        $select = $this->sql->select(self::_TABLE);
87
        $select->where->equalTo('id', $id);
88
        $select->where->equalTo('type', Feed::TYPE_MYT_QUESTION);
2109 eleazar 89
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
1 www 90
 
91
        $prototype = new Feed();
92
        return $this->executeFetchOneObject($select, $prototype);
93
    }
94
 
95
    /**
96
     *
3143 efrain 97
     * @param int $id
98
     * @return Feed
99
     */
100
    public function fetchOneAnyStatus($id)
101
    {
102
        $prototype = new Feed();
103
        $select = $this->sql->select(self::_TABLE);
104
        $select->where->equalTo('id', $id);
105
 
106
 
107
        return $this->executeFetchOneObject($select, $prototype);
108
    }
109
 
110
    /**
111
     *
1 www 112
     * @param int $feed_uuid
113
     * @return Feed
114
     */
115
    public function fetchOneByUuid($uuid)
3146 efrain 116
    {
117
        $prototype = new Feed();
1 www 118
        $select = $this->sql->select(self::_TABLE);
119
        $select->where->equalTo('uuid', $uuid);
2163 eleazar 120
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
2155 eleazar 121
        //$select->getSqlString($this->adapter->platform);
2150 eleazar 122
 
1 www 123
        return $this->executeFetchOneObject($select, $prototype);
124
    }
125
 
3146 efrain 126
 
1 www 127
    /**
128
     *
3146 efrain 129
     * @param int $feed_uuid
130
     * @return Feed
131
     */
132
    public function fetchOneByUuidAnyStatus($uuid)
133
    {
134
        $prototype = new Feed();
135
        $select = $this->sql->select(self::_TABLE);
136
        $select->where->equalTo('uuid', $uuid);
137
 
138
 
139
        return $this->executeFetchOneObject($select, $prototype);
140
    }
141
 
142
    /**
143
     *
242 efrain 144
     * @return Feed[]
145
     */
146
    public function fetchAllTypeVideo()
147
    {
148
        $select = $this->sql->select(self::_TABLE);
149
        $select->where->equalTo('file_type', Feed::FILE_TYPE_VIDEO);
150
 
151
        //echo $select->getSqlString($this->adapter->platform);
152
 
153
        $prototype = new Feed();
154
        return $this->executeFetchAllObject($select, $prototype);
155
    }
1776 nelberth 156
 
157
    public function fetchAllTypeCalendar($highPerformanceTeamsGroups_id)
158
    {
159
        $select = $this->sql->select(self::_TABLE);
160
        $select->where->equalTo('file_type', Feed::FILE_TYPE_MEETING);
161
 
162
        $select->where->equalTo('high_performance_group_id',$highPerformanceTeamsGroups_id);
163
        //echo $select->getSqlString($this->adapter->platform);
164
 
165
        $prototype = new Feed();
166
        return $this->executeFetchAllObject($select, $prototype);
167
    }
242 efrain 168
 
1869 nelberth 169
    public function fetchAllDataTableForo($search, $page = 1, $records_per_page = 10, $order_field= 'added_on', $order_direction = 'DESC', $topic_id)
1855 nelberth 170
    {
171
        $prototype = new Feed();
172
        $select = $this->sql->select(self::_TABLE);
173
        $select->where->equalTo('topic_id', $topic_id);
1882 nelberth 174
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
1855 nelberth 175
        if($search) {
176
            $select->where->like('title', '%' . $search . '%');
177
        }
178
        $select->order($order_field . ' ' . $order_direction);
179
 
180
 
181
 
182
        $hydrator   = new ObjectPropertyHydrator();
183
        $resultset  = new HydratingResultSet($hydrator, $prototype);
184
 
185
        $adapter = new DbSelect($select, $this->sql, $resultset);
186
        $paginator = new Paginator($adapter);
187
        $paginator->setItemCountPerPage($records_per_page);
188
        $paginator->setCurrentPageNumber($page);
189
 
190
 
191
        return $paginator;
192
    }
1907 nelberth 193
    public function fetchFiveForoJoinTopic($group_id,$topic_type)
1904 nelberth 194
    {
195
        $prototype = new Feed();
1910 nelberth 196
        $select = $this->sql->select();
1930 nelberth 197
        $select->from(['f' => self::_TABLE]);
198
        $select->join(['t' => TopicMapper::_TABLE], 't.id = f.topic_id ', []);
1923 nelberth 199
        $select->where->equalTo('f.high_performance_group_id', $group_id);
200
        $select->where->equalTo('f.status', Feed::STATUS_PUBLISHED);
1924 nelberth 201
        $select->where->equalTo('f.type', Feed::TYPE_HPTG);
1923 nelberth 202
        $select->where->equalTo('t.type', $topic_type);
203
        $select->where->equalTo('t.status', Topic::STATUS_ACTIVE);
1922 nelberth 204
 
205
        $select->order('added_on DESC');
1904 nelberth 206
 
207
        $hydrator   = new ObjectPropertyHydrator();
208
        $resultset  = new HydratingResultSet($hydrator, $prototype);
209
 
210
        $adapter = new DbSelect($select, $this->sql, $resultset);
211
        $paginator = new Paginator($adapter);
212
        $paginator->setItemCountPerPage(5);
213
        $paginator->setCurrentPageNumber(1);
214
 
215
 
216
        return $paginator;
217
    }
242 efrain 218
    /**
219
     *
1 www 220
     * @param int $shared_feed_id
221
     * @return int
222
     */
223
    public function fetchCountSharedByFeedId($shared_feed_id)
224
    {
225
        $select = $this->sql->select(self::_TABLE);
226
        $select->columns(['total' => new Expression('COUNT(*)') ]);
227
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
228
 
229
        $record = $this->executeFetchOneArray($select);
230
        return $record['total'];
231
    }
232
 
233
 
234
    /**
235
     *
236
     * @param Feed $feed
237
     * @return boolean
238
     */
239
    public function update($feed)
240
    {
241
        $hydrator = new ObjectPropertyHydrator();
242
        $values = $hydrator->extract($feed);
243
        $values = $this->removeEmpty($values);
244
 
245
        $update = $this->sql->update(self::_TABLE);
246
        $update->set($values);
247
        $update->where->equalTo('id', $feed->id);
248
 
424 geraldo 249
 
250
 
1 www 251
        return $this->executeUpdate($update);
252
    }
253
 
254
    /**
255
     *
256
     * @param Feed $feed
257
     * @return boolean
258
     */
259
    public function insert($feed)
260
    {
261
        $hydrator = new ObjectPropertyHydrator();
262
        $values = $hydrator->extract($feed);
428 geraldo 263
        $values = $this->removeEmpty($values);
1 www 264
 
265
        $insert = $this->sql->insert(self::_TABLE);
421 geraldo 266
        $insert->values($values);
1986 eleazar 267
        //echo $insert->getSqlString($this->adapter->platform); exit;
1 www 268
 
269
        $response = $this->executeInsert($insert);
270
        if($response) {
271
            $feed->id = $this->lastInsertId;
272
        }
273
 
426 geraldo 274
        return $values;
1 www 275
    }
276
 
277
    /**
278
     *
279
     * @param int $id
280
     * @return int
281
     */
282
    public function fetchTotalComments($id)
283
    {
284
        $select = $this->sql->select(self::_TABLE);
285
        $select->columns(['total_comments']);
286
        $select->where->equalTo('id', $id);
287
 
288
        $record = $this->executeFetchOneArray($select);
289
        return $record['total_comments'];
290
    }
291
 
292
    /**
293
     *
294
     * @param int $feed_id
295
     * @return boolean
296
     */
297
     /*
298
    public function incTotalComments($id)
299
    {
300
 
301
        $update = $this->sql->update(self::_TABLE);
302
        $update->set(['total_comments' => new Expression('total_comments + 1')]);
303
        $update->where->equalTo('id', $id);
304
 
305
        return $this->executeUpdate($update);
306
    }
307
    */
308
 
309
    /**
310
     *
311
     * @param int $feed_id
312
     * @return boolean
313
     */
314
    public function incTotalShared($id)
315
    {
316
        $update = $this->sql->update(self::_TABLE);
317
        $update->set(['total_shared' => new Expression('total_shared + 1')]);
318
        $update->where->equalTo('id', $id);
319
 
320
        return $this->executeUpdate($update);
321
    }
322
 
323
    /**
324
     *
325
     * @param int $id
326
     * @return int
327
     */
328
    public function fetchTotalShared($id)
329
    {
330
        $select = $this->sql->select(self::_TABLE);
331
        $select->columns(['total_shared']);
332
        $select->where->equalTo('id', $id);
333
 
334
        $record = $this->executeFetchOneArray($select);
335
        return $record['total_shared'];
336
    }
337
 
338
    /**
339
     *
340
     * @param int $feed_id
341
     * @return boolean
342
     */
343
    public function delete($feed_id)
344
    {
345
        $update = $this->sql->update(self::_TABLE);
346
        $update->set([
347
            'status' => Feed::STATUS_DELETED
348
        ]);
349
        $update->where->equalTo('id', $feed_id);
350
 
351
        return $this->executeUpdate($update);
352
    }
1980 eleazar 353
 
2012 eleazar 354
    /**
1980 eleazar 355
     *
2012 eleazar 356
     * @return Feed
1980 eleazar 357
     */
2012 eleazar 358
    public function fetchAllByMytQuestion()
1980 eleazar 359
    {
360
        $prototype = new Feed();
2012 eleazar 361
 
1980 eleazar 362
        $select = $this->sql->select(self::_TABLE);
1987 eleazar 363
        $select->where->equalTo('type', Feed::TYPE_MYT_QUESTION);
1988 eleazar 364
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
2137 eleazar 365
        $select->order('added_on DESC');
1980 eleazar 366
 
2012 eleazar 367
        return $this->executeFetchAllObject($select, $prototype);
1980 eleazar 368
    }
2011 eleazar 369
 
2051 eleazar 370
    /**
371
     *
372
     * @return Feed
373
     */
2072 eleazar 374
    public function fetchAllByMytAnswer($related_feed)
2051 eleazar 375
    {
376
        $prototype = new Feed();
377
 
378
        $select = $this->sql->select(self::_TABLE);
2072 eleazar 379
        $select->where->equalTo('related_feed', $related_feed);
2051 eleazar 380
        $select->where->equalTo('type', Feed::TYPE_MYT_ANSWER);
381
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
382
        $select->order('title');
383
 
384
        return $this->executeFetchAllObject($select, $prototype);
385
    }
386
 
2490 eleazar 387
      /**
388
     *
389
     * @return Feed
390
     */
391
    public function fetchAllByTopicId($topic_id)
392
    {
393
        $prototype = new Feed();
394
 
395
        $select = $this->sql->select(self::_TABLE);
396
        $select->where->equalTo('topic_id', $topic_id);
397
        $select->order('title');
398
 
399
        return $this->executeFetchAllObject($select, $prototype);
400
    }
401
 
2054 eleazar 402
    /**
403
     *
404
     * @return Feed
405
     */
406
    public function fetchAllByMytAnswerComented()
407
    {
408
        $prototype = new Feed();
409
 
410
        $select = $this->sql->select(self::_TABLE);
411
        $select->where->equalTo('type', Feed::TYPE_MYT_ANSWER);
412
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
413
        $select->order('title');
414
 
2056 eleazar 415
        return $this->executeFetchAllObject($select, $prototype);
2054 eleazar 416
    }
417
 
2237 eleazar 418
     /**
419
     *
420
     * @return Feed
421
     */
3140 kerby 422
    public function fetchAllByDevelop($allowEdit)
2237 eleazar 423
    {
424
        $prototype = new Feed();
425
 
426
        $select = $this->sql->select(self::_TABLE);
427
        $select->where->equalTo('type', Feed::TYPE_DC);
428
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
3140 kerby 429
 
3142 kerby 430
        if(!$allowEdit){
431
            $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
432
        }
3140 kerby 433
 
3128 kerby 434
        $select->order('added_on DESC');
2237 eleazar 435
 
436
        return $this->executeFetchAllObject($select, $prototype);
437
    }
3032 kerby 438
    /**
439
     *
440
     * @return Feed
441
     */
3140 kerby 442
    public function fetchAllByDevelopAndCategoryId($id, $allowEdit)
3032 kerby 443
    {
444
        $prototype = new Feed();
2237 eleazar 445
 
3032 kerby 446
        $select = $this->sql->select(self::_TABLE);
447
        $select->where->equalTo('type', Feed::TYPE_DC);
448
        $select->where->equalTo('topic_id', $id);
449
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
3142 kerby 450
        if (!$allowEdit) {
451
            $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
452
        }
3140 kerby 453
 
3032 kerby 454
        $select->order('added_on DESC');
455
 
456
        return $this->executeFetchAllObject($select, $prototype);
457
    }
458
 
459
 
2337 eleazar 460
     /**
461
     *
462
     * @return Feed
463
     */
464
    public function fetchAllByDevelopInternContent()
465
    {
466
        $prototype = new Feed();
467
 
468
        $select = $this->sql->select(self::_TABLE);
469
        $select->where->equalTo('type', Feed::TYPE_DC);
2489 eleazar 470
        //$select->where->equalTo('link_media', 'cesa');
2488 eleazar 471
        $select->where->isNotNull('file_type');
2337 eleazar 472
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
473
        $select->order('title');
2482 eleazar 474
        //echo $insert->getSqlString($this->adapter->platform); exit;
2337 eleazar 475
        return $this->executeFetchAllObject($select, $prototype);
476
    }
477
 
478
      /**
479
     *
480
     * @return Feed
481
     */
482
    public function fetchAllByDevelopExternContent()
483
    {
484
        $prototype = new Feed();
485
 
486
        $select = $this->sql->select(self::_TABLE);
487
        $select->where->equalTo('type', Feed::TYPE_DC);
488
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
489
        $select->where->notEqualTo('link_media', 'cesa');
490
        $select->order('title');
491
 
492
        return $this->executeFetchAllObject($select, $prototype);
493
    }
494
 
1 www 495
}