Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1859 | Rev 1861 | 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;
12
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
1858 nelberth 13
use Laminas\Paginator\Paginator;
1859 nelberth 14
use Laminas\Db\ResultSet\HydratingResultSet;
1 www 15
 
1860 nelberth 16
use Laminas\Paginator\Adapter\DbSelect;
1 www 17
 
18
class FeedMapper extends MapperCommon
19
{
20
    const _TABLE = 'tbl_feeds';
21
 
22
 
23
    /**
24
     *
25
     * @var FeedMapper
26
     */
27
    private static $_instance;
28
 
29
    /**
30
     *
31
     * @param AdapterInterface $adapter
32
     */
33
    private function __construct($adapter)
34
    {
35
        parent::__construct($adapter);
36
    }
37
 
38
    /**
39
     *
40
     * @param AdapterInterface $adapter
41
     * @return \LeadersLinked\Mapper\FeedMapper
42
     */
43
    public static function getInstance($adapter)
44
    {
45
        if(self::$_instance == null) {
46
            self::$_instance = new FeedMapper($adapter);
47
        }
48
        return self::$_instance;
49
    }
50
 
51
    /*
52
    public function fetchCountSharesByFeedId(int $shared_feed_id)
53
    {
54
        $select = $this->sql->select(self::_TABLE);
55
        $select->columns(['total' => new Expression('COUNT(*)') ]);
56
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
57
 
58
        $record = $this->executeFetchOneArray($select);
59
        return $record['total'];
60
    }*/
61
 
62
    /**
63
     *
64
     * @param int $id
65
     * @return Feed
66
     */
67
    public function fetchOne($id)
68
    {
69
        $select = $this->sql->select(self::_TABLE);
70
        $select->where->equalTo('id', $id);
71
 
72
        $prototype = new Feed();
73
        return $this->executeFetchOneObject($select, $prototype);
74
    }
75
 
76
    /**
77
     *
78
     * @param int $feed_uuid
79
     * @return Feed
80
     */
81
    public function fetchOneByUuid($uuid)
82
    {
83
        $select = $this->sql->select(self::_TABLE);
84
        $select->where->equalTo('uuid', $uuid);
85
 
86
        $prototype = new Feed();
87
        return $this->executeFetchOneObject($select, $prototype);
88
    }
89
 
90
    /**
91
     *
242 efrain 92
     * @return Feed[]
93
     */
94
    public function fetchAllTypeVideo()
95
    {
96
        $select = $this->sql->select(self::_TABLE);
97
        $select->where->equalTo('file_type', Feed::FILE_TYPE_VIDEO);
98
 
99
        //echo $select->getSqlString($this->adapter->platform);
100
 
101
        $prototype = new Feed();
102
        return $this->executeFetchAllObject($select, $prototype);
103
    }
1776 nelberth 104
 
105
    public function fetchAllTypeCalendar($highPerformanceTeamsGroups_id)
106
    {
107
        $select = $this->sql->select(self::_TABLE);
108
        $select->where->equalTo('file_type', Feed::FILE_TYPE_MEETING);
109
 
110
        $select->where->equalTo('high_performance_group_id',$highPerformanceTeamsGroups_id);
111
        //echo $select->getSqlString($this->adapter->platform);
112
 
113
        $prototype = new Feed();
114
        return $this->executeFetchAllObject($select, $prototype);
115
    }
242 efrain 116
 
1855 nelberth 117
    public function fetchAllDataTableForo($search, $page = 1, $records_per_page = 10, $order_field= 'id', $order_direction = 'ASC', $topic_id)
118
    {
119
        $prototype = new Feed();
120
        $select = $this->sql->select(self::_TABLE);
121
        $select->where->equalTo('topic_id', $topic_id);
122
 
123
        if($search) {
124
            $select->where->like('title', '%' . $search . '%');
125
        }
126
        $select->order($order_field . ' ' . $order_direction);
127
 
128
 
129
 
130
        $hydrator   = new ObjectPropertyHydrator();
131
        $resultset  = new HydratingResultSet($hydrator, $prototype);
132
 
133
        $adapter = new DbSelect($select, $this->sql, $resultset);
134
        $paginator = new Paginator($adapter);
135
        $paginator->setItemCountPerPage($records_per_page);
136
        $paginator->setCurrentPageNumber($page);
137
 
138
 
139
        return $paginator;
140
    }
242 efrain 141
    /**
142
     *
1 www 143
     * @param int $shared_feed_id
144
     * @return int
145
     */
146
    public function fetchCountSharedByFeedId($shared_feed_id)
147
    {
148
        $select = $this->sql->select(self::_TABLE);
149
        $select->columns(['total' => new Expression('COUNT(*)') ]);
150
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
151
 
152
        $record = $this->executeFetchOneArray($select);
153
        return $record['total'];
154
    }
155
 
156
 
157
    /**
158
     *
159
     * @param Feed $feed
160
     * @return boolean
161
     */
162
    public function update($feed)
163
    {
164
        $hydrator = new ObjectPropertyHydrator();
165
        $values = $hydrator->extract($feed);
166
        $values = $this->removeEmpty($values);
167
 
168
        $update = $this->sql->update(self::_TABLE);
169
        $update->set($values);
170
        $update->where->equalTo('id', $feed->id);
171
 
424 geraldo 172
 
173
 
1 www 174
        return $this->executeUpdate($update);
175
    }
176
 
177
    /**
178
     *
179
     * @param Feed $feed
180
     * @return boolean
181
     */
182
    public function insert($feed)
183
    {
184
        $hydrator = new ObjectPropertyHydrator();
185
        $values = $hydrator->extract($feed);
428 geraldo 186
        $values = $this->removeEmpty($values);
1 www 187
 
188
        $insert = $this->sql->insert(self::_TABLE);
421 geraldo 189
        $insert->values($values);
1 www 190
 
191
        $response = $this->executeInsert($insert);
192
        if($response) {
193
            $feed->id = $this->lastInsertId;
194
        }
195
 
426 geraldo 196
        return $values;
1 www 197
    }
198
 
199
    /**
200
     *
201
     * @param int $id
202
     * @return int
203
     */
204
    public function fetchTotalComments($id)
205
    {
206
        $select = $this->sql->select(self::_TABLE);
207
        $select->columns(['total_comments']);
208
        $select->where->equalTo('id', $id);
209
 
210
        $record = $this->executeFetchOneArray($select);
211
        return $record['total_comments'];
212
    }
213
 
214
    /**
215
     *
216
     * @param int $feed_id
217
     * @return boolean
218
     */
219
     /*
220
    public function incTotalComments($id)
221
    {
222
 
223
        $update = $this->sql->update(self::_TABLE);
224
        $update->set(['total_comments' => new Expression('total_comments + 1')]);
225
        $update->where->equalTo('id', $id);
226
 
227
        return $this->executeUpdate($update);
228
    }
229
    */
230
 
231
    /**
232
     *
233
     * @param int $feed_id
234
     * @return boolean
235
     */
236
    public function incTotalShared($id)
237
    {
238
        $update = $this->sql->update(self::_TABLE);
239
        $update->set(['total_shared' => new Expression('total_shared + 1')]);
240
        $update->where->equalTo('id', $id);
241
 
242
        return $this->executeUpdate($update);
243
    }
244
 
245
    /**
246
     *
247
     * @param int $id
248
     * @return int
249
     */
250
    public function fetchTotalShared($id)
251
    {
252
        $select = $this->sql->select(self::_TABLE);
253
        $select->columns(['total_shared']);
254
        $select->where->equalTo('id', $id);
255
 
256
        $record = $this->executeFetchOneArray($select);
257
        return $record['total_shared'];
258
    }
259
 
260
    /**
261
     *
262
     * @param int $feed_id
263
     * @return boolean
264
     */
265
    public function delete($feed_id)
266
    {
267
        $update = $this->sql->update(self::_TABLE);
268
        $update->set([
269
            'status' => Feed::STATUS_DELETED
270
        ]);
271
        $update->where->equalTo('id', $feed_id);
272
 
273
        return $this->executeUpdate($update);
274
    }
275
}