| 1 |
efrain |
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\Model\Topic;
|
|
|
13 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
14 |
use Laminas\Paginator\Paginator;
|
|
|
15 |
use Laminas\Db\ResultSet\HydratingResultSet;
|
|
|
16 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
17 |
use LeadersLinked\Mapper\TopicMapper;
|
|
|
18 |
use LeadersLinked\Model\FastSurvey;
|
|
|
19 |
|
|
|
20 |
class FeedMapper extends MapperCommon
|
|
|
21 |
{
|
|
|
22 |
const _TABLE = 'tbl_feeds';
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
*
|
|
|
27 |
* @var FeedMapper
|
|
|
28 |
*/
|
|
|
29 |
private static $_instance;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
*
|
|
|
33 |
* @param AdapterInterface $adapter
|
|
|
34 |
*/
|
|
|
35 |
private function __construct($adapter)
|
|
|
36 |
{
|
|
|
37 |
parent::__construct($adapter);
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
*
|
|
|
42 |
* @param AdapterInterface $adapter
|
|
|
43 |
* @return \LeadersLinked\Mapper\FeedMapper
|
|
|
44 |
*/
|
|
|
45 |
public static function getInstance($adapter)
|
|
|
46 |
{
|
|
|
47 |
if(self::$_instance == null) {
|
|
|
48 |
self::$_instance = new FeedMapper($adapter);
|
|
|
49 |
}
|
|
|
50 |
return self::$_instance;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/*
|
|
|
54 |
public function fetchCountSharesByFeedId(int $shared_feed_id)
|
|
|
55 |
{
|
|
|
56 |
$select = $this->sql->select(self::_TABLE);
|
|
|
57 |
$select->columns(['total' => new Expression('COUNT(*)') ]);
|
|
|
58 |
$select->where->equalTo('shared_feed_id', $shared_feed_id);
|
|
|
59 |
|
|
|
60 |
$record = $this->executeFetchOneArray($select);
|
|
|
61 |
return $record['total'];
|
|
|
62 |
}*/
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
*
|
|
|
66 |
* @param int $id
|
|
|
67 |
* @return Feed
|
|
|
68 |
*/
|
|
|
69 |
public function fetchOne($id)
|
|
|
70 |
{
|
|
|
71 |
$prototype = new Feed();
|
|
|
72 |
$select = $this->sql->select(self::_TABLE);
|
|
|
73 |
$select->where->equalTo('id', $id);
|
|
|
74 |
$select->where->notEqualTo('status', Feed::STATUS_DELETED);
|
|
|
75 |
//$select->getSqlString($this->adapter->platform);
|
|
|
76 |
|
|
|
77 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
/**
|
|
|
82 |
*
|
|
|
83 |
* @param int $id
|
|
|
84 |
* @param int $network_id
|
|
|
85 |
* @return Feed
|
|
|
86 |
*/
|
|
|
87 |
public function fetchOneByIdAndNetworkId($id, $network_id)
|
|
|
88 |
{
|
|
|
89 |
$prototype = new Feed();
|
|
|
90 |
$select = $this->sql->select(self::_TABLE);
|
|
|
91 |
$select->where->equalTo('id', $id);
|
|
|
92 |
$select->where->equalTo('network_id', $network_id);
|
|
|
93 |
$select->where->notEqualTo('status', Feed::STATUS_DELETED);
|
|
|
94 |
//$select->getSqlString($this->adapter->platform);
|
|
|
95 |
|
|
|
96 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
97 |
}
|
|
|
98 |
|
| 192 |
efrain |
99 |
|
| 1 |
efrain |
100 |
|
|
|
101 |
/**
|
|
|
102 |
*
|
|
|
103 |
* @param int $id
|
|
|
104 |
* @return Feed
|
|
|
105 |
*/
|
|
|
106 |
public function fetchOneAnyStatus($id)
|
|
|
107 |
{
|
|
|
108 |
$prototype = new Feed();
|
|
|
109 |
$select = $this->sql->select(self::_TABLE);
|
|
|
110 |
$select->where->equalTo('id', $id);
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/**
|
|
|
117 |
*
|
|
|
118 |
* @param int $feed_uuid
|
|
|
119 |
* @return Feed
|
|
|
120 |
*/
|
|
|
121 |
public function fetchOneByUuid($uuid)
|
|
|
122 |
{
|
|
|
123 |
$prototype = new Feed();
|
|
|
124 |
$select = $this->sql->select(self::_TABLE);
|
|
|
125 |
$select->where->equalTo('uuid', $uuid);
|
|
|
126 |
$select->where->notEqualTo('status', Feed::STATUS_DELETED);
|
|
|
127 |
//$select->getSqlString($this->adapter->platform);
|
|
|
128 |
|
|
|
129 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
/**
|
|
|
133 |
*
|
|
|
134 |
* @param int $feed_uuid
|
|
|
135 |
* @return Feed
|
|
|
136 |
*/
|
|
|
137 |
public function fetchOneByUuidAndNetworkId($uuid, $network_id)
|
|
|
138 |
{
|
|
|
139 |
$prototype = new Feed();
|
|
|
140 |
$select = $this->sql->select(self::_TABLE);
|
|
|
141 |
$select->where->equalTo('uuid', $uuid);
|
|
|
142 |
$select->where->notEqualTo('status', Feed::STATUS_DELETED);
|
|
|
143 |
//$select->getSqlString($this->adapter->platform);
|
|
|
144 |
|
|
|
145 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
*
|
|
|
151 |
* @param string $feed_uuid
|
|
|
152 |
* @return Feed
|
|
|
153 |
*/
|
|
|
154 |
public function fetchOneByUuidAnyStatus($uuid)
|
|
|
155 |
{
|
|
|
156 |
$prototype = new Feed();
|
|
|
157 |
$select = $this->sql->select(self::_TABLE);
|
|
|
158 |
$select->where->equalTo('uuid', $uuid);
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
/**
|
|
|
166 |
*
|
|
|
167 |
* @param string $feed_uuid
|
|
|
168 |
* @param int $network_id
|
|
|
169 |
* @return Feed
|
|
|
170 |
*/
|
|
|
171 |
public function fetchOneByUuidAndNetworkIdAnyStatus($uuid, $network_id)
|
|
|
172 |
{
|
|
|
173 |
$prototype = new Feed();
|
|
|
174 |
$select = $this->sql->select(self::_TABLE);
|
|
|
175 |
$select->where->equalTo('uuid', $uuid);
|
|
|
176 |
$select->where->equalTo('network_id', $network_id);
|
|
|
177 |
|
|
|
178 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
/**
|
|
|
184 |
*
|
|
|
185 |
* @return Feed[]
|
|
|
186 |
*/
|
|
|
187 |
public function fetchAllTypeVideo()
|
|
|
188 |
{
|
|
|
189 |
$select = $this->sql->select(self::_TABLE);
|
|
|
190 |
$select->where->equalTo('file_type', Feed::FILE_TYPE_VIDEO);
|
|
|
191 |
|
|
|
192 |
//echo $select->getSqlString($this->adapter->platform);
|
|
|
193 |
|
|
|
194 |
$prototype = new Feed();
|
|
|
195 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
public function fetchAllTypeCalendar($highPerformanceTeamsGroups_id)
|
|
|
199 |
{
|
|
|
200 |
$select = $this->sql->select(self::_TABLE);
|
|
|
201 |
$select->where->equalTo('file_type', Feed::FILE_TYPE_MEETING);
|
|
|
202 |
|
|
|
203 |
$select->where->equalTo('high_performance_group_id',$highPerformanceTeamsGroups_id);
|
|
|
204 |
//echo $select->getSqlString($this->adapter->platform);
|
|
|
205 |
|
|
|
206 |
$prototype = new Feed();
|
|
|
207 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
/*
|
|
|
211 |
public function fetchAllDataTableForo($search, $page = 1, $records_per_page = 10, $order_field= 'added_on', $order_direction = 'DESC', $topic_id)
|
|
|
212 |
{
|
|
|
213 |
$prototype = new Feed();
|
|
|
214 |
$select = $this->sql->select(self::_TABLE);
|
|
|
215 |
$select->where->equalTo('topic_id', $topic_id);
|
|
|
216 |
$select->where->equalTo('status', Feed::STATUS_PUBLISHED);
|
|
|
217 |
if($search) {
|
|
|
218 |
$select->where->like('title', '%' . $search . '%');
|
|
|
219 |
}
|
|
|
220 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
225 |
$resultset = new HydratingResultSet($hydrator, $prototype);
|
|
|
226 |
|
|
|
227 |
$adapter = new DbSelect($select, $this->sql, $resultset);
|
|
|
228 |
$paginator = new Paginator($adapter);
|
|
|
229 |
$paginator->setItemCountPerPage($records_per_page);
|
|
|
230 |
$paginator->setCurrentPageNumber($page);
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
return $paginator;
|
|
|
234 |
}*/
|
|
|
235 |
|
| 192 |
efrain |
236 |
|
| 1 |
efrain |
237 |
/**
|
|
|
238 |
*
|
|
|
239 |
* @param int $shared_feed_id
|
|
|
240 |
* @return int
|
|
|
241 |
*/
|
|
|
242 |
public function fetchCountSharedByFeedId($shared_feed_id)
|
|
|
243 |
{
|
|
|
244 |
$select = $this->sql->select(self::_TABLE);
|
|
|
245 |
$select->columns(['total' => new Expression('COUNT(*)') ]);
|
|
|
246 |
$select->where->equalTo('shared_feed_id', $shared_feed_id);
|
|
|
247 |
|
|
|
248 |
$record = $this->executeFetchOneArray($select);
|
|
|
249 |
return $record['total'];
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
/**
|
|
|
254 |
*
|
|
|
255 |
* @param Feed $feed
|
|
|
256 |
* @return boolean
|
|
|
257 |
*/
|
|
|
258 |
public function update($feed)
|
|
|
259 |
{
|
|
|
260 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
261 |
$values = $hydrator->extract($feed);
|
|
|
262 |
$values = $this->removeEmpty($values);
|
|
|
263 |
|
|
|
264 |
$update = $this->sql->update(self::_TABLE);
|
|
|
265 |
$update->set($values);
|
|
|
266 |
$update->where->equalTo('id', $feed->id);
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
|
|
|
270 |
return $this->executeUpdate($update);
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
/**
|
|
|
274 |
*
|
|
|
275 |
* @param Feed $feed
|
|
|
276 |
* @return boolean
|
|
|
277 |
*/
|
|
|
278 |
public function insert($feed)
|
|
|
279 |
{
|
|
|
280 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
281 |
$values = $hydrator->extract($feed);
|
|
|
282 |
$values = $this->removeEmpty($values);
|
|
|
283 |
|
|
|
284 |
$insert = $this->sql->insert(self::_TABLE);
|
|
|
285 |
$insert->values($values);
|
|
|
286 |
//echo $insert->getSqlString($this->adapter->platform); exit;
|
|
|
287 |
|
|
|
288 |
$response = $this->executeInsert($insert);
|
|
|
289 |
if($response) {
|
|
|
290 |
$feed->id = $this->lastInsertId;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
return $values;
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
/**
|
|
|
297 |
*
|
|
|
298 |
* @param int $id
|
|
|
299 |
* @return int
|
|
|
300 |
*/
|
|
|
301 |
public function fetchTotalComments($id)
|
|
|
302 |
{
|
|
|
303 |
$select = $this->sql->select(self::_TABLE);
|
|
|
304 |
$select->columns(['total_comments']);
|
|
|
305 |
$select->where->equalTo('id', $id);
|
|
|
306 |
|
|
|
307 |
$record = $this->executeFetchOneArray($select);
|
|
|
308 |
return $record['total_comments'];
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
/**
|
|
|
312 |
*
|
|
|
313 |
* @param int $feed_id
|
|
|
314 |
* @return boolean
|
|
|
315 |
*/
|
|
|
316 |
/*
|
|
|
317 |
public function incTotalComments($id)
|
|
|
318 |
{
|
|
|
319 |
|
|
|
320 |
$update = $this->sql->update(self::_TABLE);
|
|
|
321 |
$update->set(['total_comments' => new Expression('total_comments + 1')]);
|
|
|
322 |
$update->where->equalTo('id', $id);
|
|
|
323 |
|
|
|
324 |
return $this->executeUpdate($update);
|
|
|
325 |
}
|
|
|
326 |
*/
|
|
|
327 |
|
|
|
328 |
/**
|
|
|
329 |
*
|
|
|
330 |
* @param int $feed_id
|
|
|
331 |
* @return boolean
|
|
|
332 |
*/
|
|
|
333 |
public function incTotalShared($id)
|
|
|
334 |
{
|
|
|
335 |
$update = $this->sql->update(self::_TABLE);
|
|
|
336 |
$update->set(['total_shared' => new Expression('total_shared + 1')]);
|
|
|
337 |
$update->where->equalTo('id', $id);
|
|
|
338 |
|
|
|
339 |
return $this->executeUpdate($update);
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
/**
|
|
|
343 |
*
|
|
|
344 |
* @param int $id
|
|
|
345 |
* @return int
|
|
|
346 |
*/
|
|
|
347 |
public function fetchTotalShared($id)
|
|
|
348 |
{
|
|
|
349 |
$select = $this->sql->select(self::_TABLE);
|
|
|
350 |
$select->columns(['total_shared']);
|
|
|
351 |
$select->where->equalTo('id', $id);
|
|
|
352 |
|
|
|
353 |
$record = $this->executeFetchOneArray($select);
|
|
|
354 |
return $record['total_shared'];
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
/**
|
|
|
358 |
*
|
|
|
359 |
* @param FastSurvey $fastSurvey
|
|
|
360 |
* @return boolean
|
|
|
361 |
*/
|
|
|
362 |
public function deleteByFastSurvey($fastSurvey)
|
|
|
363 |
{
|
|
|
364 |
$delete = $this->sql->delete(self::_TABLE);
|
|
|
365 |
$delete->where->equalTo('fast_survey_id', $fastSurvey->id);
|
|
|
366 |
|
|
|
367 |
return $this->executeDelete($delete);
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
/**
|
|
|
372 |
*
|
|
|
373 |
* @param int $feed_id
|
|
|
374 |
* @return boolean
|
|
|
375 |
*/
|
|
|
376 |
public function delete($feed_id)
|
|
|
377 |
{
|
|
|
378 |
$update = $this->sql->update(self::_TABLE);
|
|
|
379 |
$update->set([
|
|
|
380 |
'status' => Feed::STATUS_DELETED
|
|
|
381 |
]);
|
|
|
382 |
$update->where->equalTo('id', $feed_id);
|
|
|
383 |
|
|
|
384 |
return $this->executeUpdate($update);
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
|
|
|
388 |
|
|
|
389 |
/**
|
|
|
390 |
*
|
|
|
391 |
* @param int $feed_id
|
|
|
392 |
* @return boolean
|
|
|
393 |
*/
|
|
|
394 |
public function incTotalExternalShared($id)
|
|
|
395 |
{
|
|
|
396 |
$update = $this->sql->update(self::_TABLE);
|
|
|
397 |
$update->set(['total_external_shared' => new Expression('total_external_shared + 1')]);
|
|
|
398 |
$update->where->equalTo('id', $id);
|
|
|
399 |
|
|
|
400 |
return $this->executeUpdate($update);
|
|
|
401 |
}
|
|
|
402 |
|
|
|
403 |
/**
|
|
|
404 |
*
|
|
|
405 |
* @param int $id
|
|
|
406 |
* @return int
|
|
|
407 |
*/
|
|
|
408 |
public function fetchTotalExternalShared($id)
|
|
|
409 |
{
|
|
|
410 |
$select = $this->sql->select(self::_TABLE);
|
|
|
411 |
$select->columns(['total_external_shared']);
|
|
|
412 |
$select->where->equalTo('id', $id);
|
|
|
413 |
|
|
|
414 |
$record = $this->executeFetchOneArray($select);
|
|
|
415 |
return $record['total_external_shared'];
|
|
|
416 |
}
|
|
|
417 |
|
|
|
418 |
}
|