Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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