Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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