Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2136 | Rev 2147 | 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)
69
    {
70
        $select = $this->sql->select(self::_TABLE);
71
        $select->where->equalTo('id', $id);
2110 eleazar 72
 
73
        $prototype = new Feed();
74
        return $this->executeFetchOneObject($select, $prototype);
75
    }
76
 
77
     /**
78
     *
79
     * @param int $id
80
     * @return Feed
81
     */
82
    public function fetchOneNonDeleted($id)
83
    {
84
        $select = $this->sql->select(self::_TABLE);
85
        $select->where->equalTo('id', $id);
86
        $select->where->equalTo('type', Feed::TYPE_MYT_QUESTION);
2109 eleazar 87
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
1 www 88
 
89
        $prototype = new Feed();
90
        return $this->executeFetchOneObject($select, $prototype);
91
    }
92
 
93
    /**
94
     *
95
     * @param int $feed_uuid
96
     * @return Feed
97
     */
98
    public function fetchOneByUuid($uuid)
99
    {
100
        $select = $this->sql->select(self::_TABLE);
101
        $select->where->equalTo('uuid', $uuid);
102
 
103
        $prototype = new Feed();
104
        return $this->executeFetchOneObject($select, $prototype);
105
    }
106
 
107
    /**
108
     *
242 efrain 109
     * @return Feed[]
110
     */
111
    public function fetchAllTypeVideo()
112
    {
113
        $select = $this->sql->select(self::_TABLE);
114
        $select->where->equalTo('file_type', Feed::FILE_TYPE_VIDEO);
115
 
116
        //echo $select->getSqlString($this->adapter->platform);
117
 
118
        $prototype = new Feed();
119
        return $this->executeFetchAllObject($select, $prototype);
120
    }
1776 nelberth 121
 
122
    public function fetchAllTypeCalendar($highPerformanceTeamsGroups_id)
123
    {
124
        $select = $this->sql->select(self::_TABLE);
125
        $select->where->equalTo('file_type', Feed::FILE_TYPE_MEETING);
126
 
127
        $select->where->equalTo('high_performance_group_id',$highPerformanceTeamsGroups_id);
128
        //echo $select->getSqlString($this->adapter->platform);
129
 
130
        $prototype = new Feed();
131
        return $this->executeFetchAllObject($select, $prototype);
132
    }
242 efrain 133
 
1869 nelberth 134
    public function fetchAllDataTableForo($search, $page = 1, $records_per_page = 10, $order_field= 'added_on', $order_direction = 'DESC', $topic_id)
1855 nelberth 135
    {
136
        $prototype = new Feed();
137
        $select = $this->sql->select(self::_TABLE);
138
        $select->where->equalTo('topic_id', $topic_id);
1882 nelberth 139
        $select->where->equalTo('status', Feed::STATUS_PUBLISHED);
1855 nelberth 140
        if($search) {
141
            $select->where->like('title', '%' . $search . '%');
142
        }
143
        $select->order($order_field . ' ' . $order_direction);
144
 
145
 
146
 
147
        $hydrator   = new ObjectPropertyHydrator();
148
        $resultset  = new HydratingResultSet($hydrator, $prototype);
149
 
150
        $adapter = new DbSelect($select, $this->sql, $resultset);
151
        $paginator = new Paginator($adapter);
152
        $paginator->setItemCountPerPage($records_per_page);
153
        $paginator->setCurrentPageNumber($page);
154
 
155
 
156
        return $paginator;
157
    }
1907 nelberth 158
    public function fetchFiveForoJoinTopic($group_id,$topic_type)
1904 nelberth 159
    {
160
        $prototype = new Feed();
1910 nelberth 161
        $select = $this->sql->select();
1930 nelberth 162
        $select->from(['f' => self::_TABLE]);
163
        $select->join(['t' => TopicMapper::_TABLE], 't.id = f.topic_id ', []);
1923 nelberth 164
        $select->where->equalTo('f.high_performance_group_id', $group_id);
165
        $select->where->equalTo('f.status', Feed::STATUS_PUBLISHED);
1924 nelberth 166
        $select->where->equalTo('f.type', Feed::TYPE_HPTG);
1923 nelberth 167
        $select->where->equalTo('t.type', $topic_type);
168
        $select->where->equalTo('t.status', Topic::STATUS_ACTIVE);
1922 nelberth 169
 
170
        $select->order('added_on DESC');
1904 nelberth 171
 
172
        $hydrator   = new ObjectPropertyHydrator();
173
        $resultset  = new HydratingResultSet($hydrator, $prototype);
174
 
175
        $adapter = new DbSelect($select, $this->sql, $resultset);
176
        $paginator = new Paginator($adapter);
177
        $paginator->setItemCountPerPage(5);
178
        $paginator->setCurrentPageNumber(1);
179
 
180
 
181
        return $paginator;
182
    }
242 efrain 183
    /**
184
     *
1 www 185
     * @param int $shared_feed_id
186
     * @return int
187
     */
188
    public function fetchCountSharedByFeedId($shared_feed_id)
189
    {
190
        $select = $this->sql->select(self::_TABLE);
191
        $select->columns(['total' => new Expression('COUNT(*)') ]);
192
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
193
 
194
        $record = $this->executeFetchOneArray($select);
195
        return $record['total'];
196
    }
197
 
198
 
199
    /**
200
     *
201
     * @param Feed $feed
202
     * @return boolean
203
     */
204
    public function update($feed)
205
    {
206
        $hydrator = new ObjectPropertyHydrator();
207
        $values = $hydrator->extract($feed);
208
        $values = $this->removeEmpty($values);
209
 
210
        $update = $this->sql->update(self::_TABLE);
211
        $update->set($values);
212
        $update->where->equalTo('id', $feed->id);
213
 
424 geraldo 214
 
215
 
1 www 216
        return $this->executeUpdate($update);
217
    }
218
 
219
    /**
220
     *
221
     * @param Feed $feed
222
     * @return boolean
223
     */
224
    public function insert($feed)
225
    {
226
        $hydrator = new ObjectPropertyHydrator();
227
        $values = $hydrator->extract($feed);
428 geraldo 228
        $values = $this->removeEmpty($values);
1 www 229
 
230
        $insert = $this->sql->insert(self::_TABLE);
421 geraldo 231
        $insert->values($values);
1986 eleazar 232
        //echo $insert->getSqlString($this->adapter->platform); exit;
1 www 233
 
234
        $response = $this->executeInsert($insert);
235
        if($response) {
236
            $feed->id = $this->lastInsertId;
237
        }
238
 
426 geraldo 239
        return $values;
1 www 240
    }
241
 
242
    /**
243
     *
244
     * @param int $id
245
     * @return int
246
     */
247
    public function fetchTotalComments($id)
248
    {
249
        $select = $this->sql->select(self::_TABLE);
250
        $select->columns(['total_comments']);
251
        $select->where->equalTo('id', $id);
252
 
253
        $record = $this->executeFetchOneArray($select);
254
        return $record['total_comments'];
255
    }
256
 
257
    /**
258
     *
259
     * @param int $feed_id
260
     * @return boolean
261
     */
262
     /*
263
    public function incTotalComments($id)
264
    {
265
 
266
        $update = $this->sql->update(self::_TABLE);
267
        $update->set(['total_comments' => new Expression('total_comments + 1')]);
268
        $update->where->equalTo('id', $id);
269
 
270
        return $this->executeUpdate($update);
271
    }
272
    */
273
 
274
    /**
275
     *
276
     * @param int $feed_id
277
     * @return boolean
278
     */
279
    public function incTotalShared($id)
280
    {
281
        $update = $this->sql->update(self::_TABLE);
282
        $update->set(['total_shared' => new Expression('total_shared + 1')]);
283
        $update->where->equalTo('id', $id);
284
 
285
        return $this->executeUpdate($update);
286
    }
287
 
288
    /**
289
     *
290
     * @param int $id
291
     * @return int
292
     */
293
    public function fetchTotalShared($id)
294
    {
295
        $select = $this->sql->select(self::_TABLE);
296
        $select->columns(['total_shared']);
297
        $select->where->equalTo('id', $id);
298
 
299
        $record = $this->executeFetchOneArray($select);
300
        return $record['total_shared'];
301
    }
302
 
303
    /**
304
     *
305
     * @param int $feed_id
306
     * @return boolean
307
     */
308
    public function delete($feed_id)
309
    {
310
        $update = $this->sql->update(self::_TABLE);
311
        $update->set([
312
            'status' => Feed::STATUS_DELETED
313
        ]);
314
        $update->where->equalTo('id', $feed_id);
315
 
316
        return $this->executeUpdate($update);
317
    }
1980 eleazar 318
 
2012 eleazar 319
    /**
1980 eleazar 320
     *
2012 eleazar 321
     * @return Feed
1980 eleazar 322
     */
2012 eleazar 323
    public function fetchAllByMytQuestion()
1980 eleazar 324
    {
325
        $prototype = new Feed();
2012 eleazar 326
 
1980 eleazar 327
        $select = $this->sql->select(self::_TABLE);
1987 eleazar 328
        $select->where->equalTo('type', Feed::TYPE_MYT_QUESTION);
1988 eleazar 329
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
2137 eleazar 330
        $select->order('added_on DESC');
1980 eleazar 331
 
2012 eleazar 332
        return $this->executeFetchAllObject($select, $prototype);
1980 eleazar 333
    }
2011 eleazar 334
 
2051 eleazar 335
    /**
336
     *
337
     * @return Feed
338
     */
2072 eleazar 339
    public function fetchAllByMytAnswer($related_feed)
2051 eleazar 340
    {
341
        $prototype = new Feed();
342
 
343
        $select = $this->sql->select(self::_TABLE);
2072 eleazar 344
        $select->where->equalTo('related_feed', $related_feed);
2051 eleazar 345
        $select->where->equalTo('type', Feed::TYPE_MYT_ANSWER);
346
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
347
        $select->order('title');
348
 
349
        return $this->executeFetchAllObject($select, $prototype);
350
    }
351
 
2054 eleazar 352
    /**
353
     *
354
     * @return Feed
355
     */
356
    public function fetchAllByMytAnswerComented()
357
    {
358
        $prototype = new Feed();
359
 
360
        $select = $this->sql->select(self::_TABLE);
361
        $select->where->equalTo('type', Feed::TYPE_MYT_ANSWER);
362
        $select->where->notEqualTo('status', Feed::STATUS_DELETED);
363
        $select->order('title');
364
 
2056 eleazar 365
        return $this->executeFetchAllObject($select, $prototype);
2054 eleazar 366
    }
367
 
1 www 368
}