Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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