Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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