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