Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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