Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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