Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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