Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1921 | Rev 1923 | 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();
1904 nelberth 146
        $select->from(['t' => TopicMapper::_TABLE]);
1922 nelberth 147
        $select->join(['f' => self::_TABLE], 'f.topic_id = t.id', []);
148
        $select->where->equalTo('f.group_id', $group_id);
149
 
150
        $select->order('added_on DESC');
1904 nelberth 151
 
152
        $hydrator   = new ObjectPropertyHydrator();
153
        $resultset  = new HydratingResultSet($hydrator, $prototype);
154
 
155
        $adapter = new DbSelect($select, $this->sql, $resultset);
156
        $paginator = new Paginator($adapter);
157
        $paginator->setItemCountPerPage(5);
158
        $paginator->setCurrentPageNumber(1);
159
 
160
 
161
        return $paginator;
162
    }
242 efrain 163
    /**
164
     *
1 www 165
     * @param int $shared_feed_id
166
     * @return int
167
     */
168
    public function fetchCountSharedByFeedId($shared_feed_id)
169
    {
170
        $select = $this->sql->select(self::_TABLE);
171
        $select->columns(['total' => new Expression('COUNT(*)') ]);
172
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
173
 
174
        $record = $this->executeFetchOneArray($select);
175
        return $record['total'];
176
    }
177
 
178
 
179
    /**
180
     *
181
     * @param Feed $feed
182
     * @return boolean
183
     */
184
    public function update($feed)
185
    {
186
        $hydrator = new ObjectPropertyHydrator();
187
        $values = $hydrator->extract($feed);
188
        $values = $this->removeEmpty($values);
189
 
190
        $update = $this->sql->update(self::_TABLE);
191
        $update->set($values);
192
        $update->where->equalTo('id', $feed->id);
193
 
424 geraldo 194
 
195
 
1 www 196
        return $this->executeUpdate($update);
197
    }
198
 
199
    /**
200
     *
201
     * @param Feed $feed
202
     * @return boolean
203
     */
204
    public function insert($feed)
205
    {
206
        $hydrator = new ObjectPropertyHydrator();
207
        $values = $hydrator->extract($feed);
428 geraldo 208
        $values = $this->removeEmpty($values);
1 www 209
 
210
        $insert = $this->sql->insert(self::_TABLE);
421 geraldo 211
        $insert->values($values);
1 www 212
 
213
        $response = $this->executeInsert($insert);
214
        if($response) {
215
            $feed->id = $this->lastInsertId;
216
        }
217
 
426 geraldo 218
        return $values;
1 www 219
    }
220
 
221
    /**
222
     *
223
     * @param int $id
224
     * @return int
225
     */
226
    public function fetchTotalComments($id)
227
    {
228
        $select = $this->sql->select(self::_TABLE);
229
        $select->columns(['total_comments']);
230
        $select->where->equalTo('id', $id);
231
 
232
        $record = $this->executeFetchOneArray($select);
233
        return $record['total_comments'];
234
    }
235
 
236
    /**
237
     *
238
     * @param int $feed_id
239
     * @return boolean
240
     */
241
     /*
242
    public function incTotalComments($id)
243
    {
244
 
245
        $update = $this->sql->update(self::_TABLE);
246
        $update->set(['total_comments' => new Expression('total_comments + 1')]);
247
        $update->where->equalTo('id', $id);
248
 
249
        return $this->executeUpdate($update);
250
    }
251
    */
252
 
253
    /**
254
     *
255
     * @param int $feed_id
256
     * @return boolean
257
     */
258
    public function incTotalShared($id)
259
    {
260
        $update = $this->sql->update(self::_TABLE);
261
        $update->set(['total_shared' => new Expression('total_shared + 1')]);
262
        $update->where->equalTo('id', $id);
263
 
264
        return $this->executeUpdate($update);
265
    }
266
 
267
    /**
268
     *
269
     * @param int $id
270
     * @return int
271
     */
272
    public function fetchTotalShared($id)
273
    {
274
        $select = $this->sql->select(self::_TABLE);
275
        $select->columns(['total_shared']);
276
        $select->where->equalTo('id', $id);
277
 
278
        $record = $this->executeFetchOneArray($select);
279
        return $record['total_shared'];
280
    }
281
 
282
    /**
283
     *
284
     * @param int $feed_id
285
     * @return boolean
286
     */
287
    public function delete($feed_id)
288
    {
289
        $update = $this->sql->update(self::_TABLE);
290
        $update->set([
291
            'status' => Feed::STATUS_DELETED
292
        ]);
293
        $update->where->equalTo('id', $feed_id);
294
 
295
        return $this->executeUpdate($update);
296
    }
297
}