Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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