Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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