1 |
efrain |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
7 |
use Laminas\View\Model\JsonModel;
|
|
|
8 |
use LeadersLinked\Library\Functions;
|
|
|
9 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
|
|
10 |
use LeadersLinked\Form\Feed\CreateForm;
|
|
|
11 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
12 |
use LeadersLinked\Model\Feed;
|
|
|
13 |
use LeadersLinked\Mapper\FeedMapper;
|
|
|
14 |
use LeadersLinked\Mapper\GroupMapper;
|
|
|
15 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
16 |
use LeadersLinked\Mapper\CommentMapper;
|
|
|
17 |
use LeadersLinked\Mapper\ConnectionMapper;
|
|
|
18 |
use LeadersLinked\Mapper\CompanyFollowerMapper;
|
|
|
19 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
20 |
use Laminas\Paginator\Paginator;
|
|
|
21 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
22 |
use LeadersLinked\Mapper\ContentReactionMapper;
|
|
|
23 |
use LeadersLinked\Model\ContentReaction;
|
|
|
24 |
use LeadersLinked\Form\Feed\CommentForm;
|
|
|
25 |
use LeadersLinked\Model\Comment;
|
|
|
26 |
use LeadersLinked\Form\Feed\CreateGroupCompanyForm;
|
|
|
27 |
use LeadersLinked\Model\CompanyUser;
|
|
|
28 |
use LeadersLinked\Model\FastSurvey;
|
|
|
29 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
30 |
use LeadersLinked\Model\Company;
|
|
|
31 |
use LeadersLinked\Model\Group;
|
|
|
32 |
use LeadersLinked\Mapper\GroupMemberMapper;
|
|
|
33 |
use LeadersLinked\Model\GroupMember;
|
|
|
34 |
use LeadersLinked\Model\Notification;
|
|
|
35 |
use LeadersLinked\Mapper\NotificationMapper;
|
|
|
36 |
use LeadersLinked\Mapper\UserNotificationSettingMapper;
|
|
|
37 |
use LeadersLinked\Mapper\EmailTemplateMapper;
|
|
|
38 |
use LeadersLinked\Model\EmailTemplate;
|
|
|
39 |
use LeadersLinked\Library\QueueEmail;
|
|
|
40 |
use LeadersLinked\Mapper\FastSurveyMapper;
|
|
|
41 |
use LeadersLinked\Mapper\FastSurveyVoteMapper;
|
|
|
42 |
use LeadersLinked\Model\FastSurveyVote;
|
192 |
efrain |
43 |
use LeadersLinked\Mapper\AbuseReportMapper;
|
|
|
44 |
use LeadersLinked\Mapper\UserBlockedMapper;
|
|
|
45 |
use LeadersLinked\Model\AbuseReport;
|
232 |
efrain |
46 |
use LeadersLinked\Model\User;
|
283 |
www |
47 |
use LeadersLinked\Library\Storage;
|
345 |
www |
48 |
use LeadersLinked\Model\VideoConvert;
|
|
|
49 |
use LeadersLinked\Mapper\VideoConvertMapper;
|
1 |
efrain |
50 |
|
|
|
51 |
|
|
|
52 |
class FeedController extends AbstractActionController
|
|
|
53 |
{
|
|
|
54 |
/**
|
|
|
55 |
*
|
|
|
56 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
|
|
57 |
*/
|
|
|
58 |
private $adapter;
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
*
|
|
|
62 |
* @var \LeadersLinked\Cache\CacheInterface
|
|
|
63 |
*/
|
|
|
64 |
private $cache;
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
*
|
|
|
69 |
* @var \Laminas\Log\LoggerInterface
|
|
|
70 |
*/
|
|
|
71 |
private $logger;
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
*
|
|
|
75 |
* @var array
|
|
|
76 |
*/
|
|
|
77 |
private $config;
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
*
|
|
|
82 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
83 |
*/
|
|
|
84 |
private $translator;
|
|
|
85 |
|
345 |
www |
86 |
|
1 |
efrain |
87 |
|
289 |
www |
88 |
|
1 |
efrain |
89 |
/**
|
|
|
90 |
*
|
|
|
91 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
92 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
93 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
|
|
94 |
* @param array $config
|
|
|
95 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
|
|
96 |
*/
|
|
|
97 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
|
|
98 |
{
|
|
|
99 |
$this->adapter = $adapter;
|
|
|
100 |
$this->cache = $cache;
|
|
|
101 |
$this->logger = $logger;
|
|
|
102 |
$this->config = $config;
|
|
|
103 |
$this->translator = $translator;
|
345 |
www |
104 |
|
1 |
efrain |
105 |
}
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
*
|
|
|
109 |
* Generación del listado de perfiles
|
|
|
110 |
* {@inheritDoc}
|
|
|
111 |
* @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
|
|
|
112 |
*/
|
|
|
113 |
public function indexAction()
|
|
|
114 |
{
|
|
|
115 |
|
|
|
116 |
return new JsonModel([
|
|
|
117 |
'success' => false,
|
|
|
118 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
119 |
]);
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
public function commentAction()
|
|
|
123 |
{
|
|
|
124 |
$id = $this->params()->fromRoute('id');
|
|
|
125 |
|
|
|
126 |
$request = $this->getRequest();
|
|
|
127 |
if ($request->isPost()) {
|
|
|
128 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
129 |
$now = $feedMapper->getDatebaseNow();
|
|
|
130 |
|
|
|
131 |
$feed = $feedMapper->fetchOneByUuid($id);
|
|
|
132 |
|
|
|
133 |
if (!$feed) {
|
|
|
134 |
$response = [
|
|
|
135 |
'success' => false,
|
|
|
136 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
137 |
];
|
|
|
138 |
return new JsonModel($response);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
$dataPost = $request->getPost()->toArray();
|
|
|
142 |
$form = new CommentForm();
|
|
|
143 |
$form->setData($dataPost);
|
|
|
144 |
|
|
|
145 |
if ($form->isValid()) {
|
|
|
146 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
147 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
148 |
|
|
|
149 |
$dataPost = (array) $form->getData();
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
$comment = new Comment();
|
|
|
154 |
$comment->network_id = $currentUser->network_id;
|
|
|
155 |
$comment->comment = $dataPost['comment'];
|
|
|
156 |
$comment->user_id = $currentUser->id;
|
|
|
157 |
$comment->feed_id = $feed->id;
|
|
|
158 |
$comment->relational = Comment::RELATIONAL_FEED;
|
|
|
159 |
|
|
|
160 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
161 |
if ($commentMapper->insert($comment)) {
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
if ($feed->type == Feed::TYPE_UPDATE) {
|
|
|
165 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
166 |
$ownerFeed = $userMapper->fetchOne($feed->user_id);
|
|
|
167 |
|
|
|
168 |
$notification = new Notification();
|
|
|
169 |
$notification->type = Notification::TYPE_COMMENT_MY_FEED;
|
|
|
170 |
$notification->feed_id = $feed->id;
|
|
|
171 |
$notification->read = Notification::NO;
|
|
|
172 |
$notification->user_id = $ownerFeed->id;
|
|
|
173 |
$notification->message = 'LABEL_COMMENT_MY_FEED';
|
|
|
174 |
$notification->url = $this->url()->fromRoute('dashboard', ['feed' => $feed->uuid]);
|
|
|
175 |
|
|
|
176 |
$notificationMapper = NotificationMapper::getInstance($this->adapter);
|
|
|
177 |
$notificationMapper->insert($notification);
|
|
|
178 |
|
|
|
179 |
$userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
|
|
|
180 |
$userNotification = $userNotificationMapper->fetchOne($ownerFeed->id);
|
|
|
181 |
|
|
|
182 |
if ($userNotification && $userNotification->comment_my_feed) {
|
|
|
183 |
$emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
|
|
|
184 |
$emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_COMMENT_MY_FEED, $currentUser->network_id);
|
|
|
185 |
|
|
|
186 |
if ($emailTemplate) {
|
|
|
187 |
$arrayCont = [
|
|
|
188 |
'firstname' => $currentUser->first_name,
|
|
|
189 |
'lastname' => $currentUser->last_name,
|
|
|
190 |
'other_user_firstname' => $ownerFeed->first_name,
|
|
|
191 |
'other_user_lastname' => $ownerFeed->last_name,
|
|
|
192 |
'company_name' => '',
|
|
|
193 |
'group_name' => '',
|
|
|
194 |
'content' => '',
|
|
|
195 |
'code' => '',
|
|
|
196 |
'link' => $this->url()->fromRoute('dashboard', ['feed' => $feed->uuid], ['force_canonical' => true])
|
|
|
197 |
];
|
|
|
198 |
|
|
|
199 |
$email = new QueueEmail($this->adapter);
|
|
|
200 |
$email->processEmailTemplate($emailTemplate, $arrayCont, $ownerFeed->email, trim($ownerFeed->first_name . ' ' . $ownerFeed->last_name));
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
|
|
206 |
|
|
|
207 |
$feed->total_comments = $total_comments;
|
|
|
208 |
$feedMapper->update($feed);
|
|
|
209 |
|
|
|
210 |
$response = [
|
|
|
211 |
'success' => true,
|
|
|
212 |
'data' => $this->renderComment($comment->id, $now),
|
|
|
213 |
'total_comments' => $total_comments
|
|
|
214 |
];
|
|
|
215 |
|
|
|
216 |
return new JsonModel($response);
|
|
|
217 |
} else {
|
|
|
218 |
|
|
|
219 |
$response = [
|
|
|
220 |
'success' => false,
|
|
|
221 |
'data' => $commentMapper->getError()
|
|
|
222 |
];
|
|
|
223 |
|
|
|
224 |
return new JsonModel($response);
|
|
|
225 |
}
|
|
|
226 |
} else {
|
|
|
227 |
$message = '';;
|
|
|
228 |
$form_messages = (array) $form->getMessages();
|
|
|
229 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
230 |
foreach ($field_messages as $key => $value) {
|
|
|
231 |
$message = $value;
|
|
|
232 |
}
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
$response = [
|
|
|
236 |
'success' => false,
|
|
|
237 |
'data' => $message
|
|
|
238 |
];
|
|
|
239 |
|
|
|
240 |
return new JsonModel($response);
|
|
|
241 |
}
|
|
|
242 |
} else {
|
|
|
243 |
$response = [
|
|
|
244 |
'success' => false,
|
|
|
245 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
246 |
];
|
|
|
247 |
|
|
|
248 |
return new JsonModel($response);
|
|
|
249 |
}
|
|
|
250 |
}
|
232 |
efrain |
251 |
|
|
|
252 |
public function reactionsAction()
|
|
|
253 |
{
|
|
|
254 |
$id = $this->params()->fromRoute('id');
|
|
|
255 |
|
|
|
256 |
$request = $this->getRequest();
|
|
|
257 |
$request = $this->getRequest();
|
|
|
258 |
if ($request->isGet()) {
|
283 |
www |
259 |
|
232 |
efrain |
260 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
261 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
262 |
|
345 |
www |
263 |
|
|
|
264 |
$storage = \LeadersLinked\Library\Storage::getInstance($this->config, $this->adapter);
|
|
|
265 |
|
232 |
efrain |
266 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
267 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
268 |
if (!$feed) {
|
|
|
269 |
$response = [
|
|
|
270 |
'success' => false,
|
|
|
271 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
272 |
];
|
|
|
273 |
return new JsonModel($response);
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
|
233 |
efrain |
277 |
$userMapper = UserMapper::getInstance($this->adapter);
|
232 |
efrain |
278 |
|
|
|
279 |
$items = [];
|
|
|
280 |
|
|
|
281 |
$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
|
|
282 |
$records = $contentReactionMapper->fetchAllByFeedId($feed->id);
|
289 |
www |
283 |
|
232 |
efrain |
284 |
|
|
|
285 |
foreach($records as $record)
|
|
|
286 |
{
|
|
|
287 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
288 |
if($user && $user->status == User::STATUS_ACTIVE) {
|
283 |
www |
289 |
|
232 |
efrain |
290 |
|
|
|
291 |
array_push($items, [
|
345 |
www |
292 |
'first_name' => $user->first_name,
|
|
|
293 |
'last_name' => $user->last_name,
|
|
|
294 |
'email' => $user->email,
|
|
|
295 |
'image' => $storage->getUserImage($user),
|
|
|
296 |
'reaction' => $record->reaction,
|
232 |
efrain |
297 |
]);
|
|
|
298 |
}
|
|
|
299 |
}
|
|
|
300 |
|
233 |
efrain |
301 |
$response = [
|
|
|
302 |
'success' => true,
|
|
|
303 |
'data' => $items
|
|
|
304 |
];
|
232 |
efrain |
305 |
|
233 |
efrain |
306 |
return new JsonModel($response);
|
232 |
efrain |
307 |
|
|
|
308 |
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
} else {
|
|
|
312 |
$response = [
|
|
|
313 |
'success' => false,
|
|
|
314 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
315 |
];
|
|
|
316 |
|
|
|
317 |
return new JsonModel($response);
|
|
|
318 |
}
|
|
|
319 |
}
|
1 |
efrain |
320 |
|
|
|
321 |
public function shareAction()
|
|
|
322 |
{
|
|
|
323 |
$id = $this->params()->fromRoute('id');
|
|
|
324 |
|
|
|
325 |
$request = $this->getRequest();
|
|
|
326 |
if ($request->isPost()) {
|
|
|
327 |
|
|
|
328 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
329 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
333 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
334 |
if (!$feed) {
|
|
|
335 |
$response = [
|
|
|
336 |
'success' => false,
|
|
|
337 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
338 |
];
|
|
|
339 |
return new JsonModel($response);
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
343 |
$dataPost['company_id'] = $this->params()->fromRoute('company_id');
|
|
|
344 |
$dataPost['group_id'] = $this->params()->fromRoute('group_id');
|
|
|
345 |
$dataPost['shared_feed_id'] = $feed->id;
|
|
|
346 |
|
|
|
347 |
|
|
|
348 |
|
|
|
349 |
|
|
|
350 |
$response = $this->postOrShareFeed($dataPost);
|
|
|
351 |
if ($response['success']) {
|
|
|
352 |
$feedMapper->incTotalShared($feed->id);
|
|
|
353 |
$total_shared = $feedMapper->fetchTotalShared($feed->id);
|
|
|
354 |
|
|
|
355 |
$response['total_shared'] = $total_shared;
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
|
|
|
359 |
return new JsonModel($response);
|
|
|
360 |
} else {
|
|
|
361 |
$response = [
|
|
|
362 |
'success' => false,
|
|
|
363 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
364 |
];
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
return new JsonModel($response);
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
public function commentDeleteAction()
|
|
|
371 |
{
|
|
|
372 |
$request = $this->getRequest();
|
|
|
373 |
if ($request->isPost()) {
|
|
|
374 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
375 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
376 |
|
|
|
377 |
$feed_id = $this->params()->fromRoute('id');
|
|
|
378 |
$comment = $this->params()->fromRoute('comment');
|
|
|
379 |
|
|
|
380 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
381 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($feed_id, $currentUser->network_id);
|
|
|
382 |
|
|
|
383 |
if ($feed) {
|
|
|
384 |
|
|
|
385 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
386 |
$comment = $commentMapper->fetchOneByUuid($comment);
|
|
|
387 |
|
|
|
388 |
if ($comment && $comment->feed_id == $feed->id && $comment->user_id == $currentUser->id) {
|
|
|
389 |
|
|
|
390 |
$comment->status = Comment::STATUS_DELETED;
|
|
|
391 |
|
|
|
392 |
if ($commentMapper->update($comment)) {
|
|
|
393 |
|
|
|
394 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
|
|
395 |
|
|
|
396 |
|
|
|
397 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
398 |
$feed = $feedMapper->fetchOne($comment->feed_id);
|
|
|
399 |
$feed->total_comments = $total_comments;
|
|
|
400 |
$feedMapper->update($feed);
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
|
|
|
404 |
|
|
|
405 |
|
|
|
406 |
$response = [
|
|
|
407 |
'success' => true,
|
|
|
408 |
'data' => 'LABEL_COMMENT_WAS_DELETED',
|
|
|
409 |
'total_comments' => $total_comments
|
|
|
410 |
];
|
|
|
411 |
} else {
|
|
|
412 |
$response = [
|
|
|
413 |
'success' => false,
|
|
|
414 |
'data' => $commentMapper->getError()
|
|
|
415 |
];
|
|
|
416 |
}
|
|
|
417 |
} else {
|
|
|
418 |
$response = [
|
|
|
419 |
'success' => false,
|
|
|
420 |
'data' => 'ERROR_COMMENT_NOT_FOUND'
|
|
|
421 |
];
|
|
|
422 |
}
|
|
|
423 |
} else {
|
|
|
424 |
$response = [
|
|
|
425 |
'success' => false,
|
|
|
426 |
'data' => 'ERROR_COMMENT_NOT_FOUND'
|
|
|
427 |
];
|
|
|
428 |
}
|
|
|
429 |
} else {
|
|
|
430 |
$response = [
|
|
|
431 |
'success' => false,
|
|
|
432 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
433 |
];
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
return new JsonModel($response);
|
|
|
437 |
}
|
|
|
438 |
|
|
|
439 |
public function deleteAction()
|
|
|
440 |
{
|
|
|
441 |
$request = $this->getRequest();
|
|
|
442 |
if ($request->isPost()) {
|
|
|
443 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
444 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
445 |
|
|
|
446 |
$feed_id = $this->params()->fromRoute('id');
|
|
|
447 |
|
|
|
448 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
449 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($feed_id, $currentUser->network_id);
|
|
|
450 |
|
|
|
451 |
if ($feed) {
|
|
|
452 |
|
|
|
453 |
if ($feed->user_id && $feed->user_id == $currentUser->id) {
|
|
|
454 |
|
|
|
455 |
return new JsonModel($this->deleteFeed($feed));
|
|
|
456 |
} else if ($feed->group_id) {
|
|
|
457 |
|
|
|
458 |
$groupMapper = GroupMapper::getInstance($this->adapter);
|
|
|
459 |
$group = $groupMapper->fetchOne($feed->group_id);
|
|
|
460 |
if ($group && $group->user_id == $currentUser->id) {
|
|
|
461 |
return new JsonModel($this->deleteFeed($feed));
|
|
|
462 |
}
|
|
|
463 |
} else if ($feed->company_id) {
|
|
|
464 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
465 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($feed->company_id, $currentUser->id);
|
|
|
466 |
if ($companyUser) {
|
|
|
467 |
if (in_array($companyUser->type, [CompanyUser::TYPE_OWNER, CompanyUser::TYPE_ADMINISTRATOR, CompanyUser::TYPE_MANAGER])) {
|
|
|
468 |
return new JsonModel($this->deleteFeed($feed));
|
|
|
469 |
}
|
|
|
470 |
}
|
|
|
471 |
}
|
|
|
472 |
|
|
|
473 |
$response = [
|
|
|
474 |
'success' => false,
|
|
|
475 |
'data' => ' ERROR_UNAUTHORIZED'
|
|
|
476 |
];
|
|
|
477 |
} else {
|
|
|
478 |
$response = [
|
|
|
479 |
'success' => false,
|
|
|
480 |
'data' => 'ERROR_FEED_NOT_FOUND'
|
|
|
481 |
];
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
return new JsonModel($response);
|
|
|
485 |
} else {
|
|
|
486 |
$response = [
|
|
|
487 |
'success' => false,
|
|
|
488 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
489 |
];
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
return new JsonModel($response);
|
|
|
493 |
}
|
|
|
494 |
|
|
|
495 |
public function addAction()
|
|
|
496 |
{
|
|
|
497 |
$request = $this->getRequest();
|
|
|
498 |
if ($request->isPost()) {
|
|
|
499 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
500 |
$dataPost['company_id'] = $this->params()->fromRoute('company_id');
|
|
|
501 |
$dataPost['group_id'] = $this->params()->fromRoute('group_id');
|
|
|
502 |
$response = $this->postOrShareFeed($dataPost);
|
|
|
503 |
|
|
|
504 |
|
|
|
505 |
return new JsonModel($response);
|
|
|
506 |
} else {
|
|
|
507 |
$response = [
|
|
|
508 |
'success' => false,
|
|
|
509 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
510 |
];
|
|
|
511 |
}
|
|
|
512 |
|
|
|
513 |
return new JsonModel($response);
|
|
|
514 |
}
|
|
|
515 |
|
|
|
516 |
public function postOrShareFeed($dataPost)
|
|
|
517 |
{
|
|
|
518 |
|
|
|
519 |
|
|
|
520 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
521 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
522 |
|
|
|
523 |
$companyId = empty($dataPost['company_id']) ? '' : $dataPost['company_id'];
|
|
|
524 |
$groupId = empty($dataPost['group_id']) ? '' : $dataPost['group_id'];
|
|
|
525 |
|
|
|
526 |
|
|
|
527 |
if ($groupId || $companyId) {
|
|
|
528 |
$form = new CreateGroupCompanyForm($this->adapter);
|
|
|
529 |
} else {
|
|
|
530 |
$form = new CreateForm($this->adapter);
|
|
|
531 |
}
|
|
|
532 |
$form->setData($dataPost);
|
|
|
533 |
if ($form->isValid()) {
|
|
|
534 |
|
|
|
535 |
|
|
|
536 |
|
|
|
537 |
|
|
|
538 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
539 |
$feed = new Feed();
|
|
|
540 |
$hydrator->hydrate($dataPost, $feed);
|
|
|
541 |
|
|
|
542 |
$company = null;
|
|
|
543 |
$group = null;
|
|
|
544 |
|
|
|
545 |
if ($companyId) {
|
|
|
546 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
547 |
$now = $companyMapper->getDatebaseNow();
|
|
|
548 |
|
|
|
549 |
$company = $companyMapper->fetchOneByUuidAndNetworkId($companyId, $currentUser->network_id);
|
|
|
550 |
|
|
|
551 |
|
|
|
552 |
if (!$company) {
|
|
|
553 |
return [
|
|
|
554 |
'success' => false,
|
|
|
555 |
'data' => 'ERROR_COMPANY_NOT_FOUND'
|
|
|
556 |
];
|
|
|
557 |
}
|
|
|
558 |
|
|
|
559 |
if ($company->status != Company::STATUS_ACTIVE) {
|
|
|
560 |
return [
|
|
|
561 |
'success' => false,
|
|
|
562 |
'data' => 'ERROR_COMPANY_IS_NOT_ACTIVE'
|
|
|
563 |
];
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
567 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
|
|
|
568 |
|
|
|
569 |
|
|
|
570 |
if (!$companyUser || $companyUser->status != CompanyUser::STATUS_ACCEPTED) {
|
|
|
571 |
return [
|
|
|
572 |
'success' => false,
|
|
|
573 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
574 |
];
|
|
|
575 |
}
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
if ($groupId) {
|
|
|
579 |
$groupMapper = GroupMapper::getInstance($this->adapter);
|
|
|
580 |
$now = $groupMapper->getDatebaseNow();
|
|
|
581 |
|
|
|
582 |
$group = $groupMapper->fetchOneByUuidAndNetworkId($groupId, $currentUser->network_id);
|
|
|
583 |
|
|
|
584 |
if (!$group) {
|
|
|
585 |
return [
|
|
|
586 |
'success' => false,
|
|
|
587 |
'data' => 'ERROR_GROUP_NOT_FOUND'
|
|
|
588 |
];
|
|
|
589 |
}
|
|
|
590 |
|
|
|
591 |
if ($group->status != Group::STATUS_ACTIVE) {
|
|
|
592 |
return [
|
|
|
593 |
'success' => false,
|
|
|
594 |
'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
|
|
|
595 |
];
|
|
|
596 |
}
|
|
|
597 |
|
|
|
598 |
$groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
|
|
|
599 |
$groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $currentUser->id);
|
|
|
600 |
if (!$groupMember || !in_array($groupMember->status, [GroupMember::STATUS_ACCEPTED, GroupMember::STATUS_AUTO_JOIN])) {
|
|
|
601 |
return [
|
|
|
602 |
'success' => false,
|
|
|
603 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
604 |
];
|
|
|
605 |
}
|
|
|
606 |
}
|
|
|
607 |
|
|
|
608 |
$feed->network_id = $currentUser->network_id;
|
|
|
609 |
$feed->company_id = $company ? $company->id : null;
|
|
|
610 |
$feed->group_id = $group ? $group->id : null;
|
|
|
611 |
$feed->user_id = $currentUser->id;
|
|
|
612 |
|
|
|
613 |
if ($companyId) {
|
|
|
614 |
$feed->type = Feed::TYPE_COMPANY;
|
|
|
615 |
} else if ($groupId) {
|
|
|
616 |
$feed->type = Feed::TYPE_GROUP;
|
|
|
617 |
} else {
|
|
|
618 |
$feed->type = Feed::TYPE_UPDATE;
|
|
|
619 |
}
|
|
|
620 |
|
|
|
621 |
$posted_or_shared = $dataPost['posted_or_shared'];
|
|
|
622 |
if ($posted_or_shared != Feed::POSTED && $posted_or_shared != Feed::SHARED) {
|
|
|
623 |
return [
|
|
|
624 |
'success' => false,
|
|
|
625 |
'data' => 'ERROR_SUPPLY_VALID_SHARING_STATUS'
|
|
|
626 |
];
|
|
|
627 |
}
|
|
|
628 |
$feed->posted_or_shared = $posted_or_shared;
|
|
|
629 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
630 |
$now = $feedMapper->getDatebaseNow();
|
|
|
631 |
|
|
|
632 |
$shared_with = isset($dataPost['shared_with']) ? $dataPost['shared_with'] : Feed::SHARE_WITH_PUBLIC;
|
|
|
633 |
if ($shared_with != Feed::SHARE_WITH_PUBLIC && $shared_with != Feed::SHARE_WITH_CONNECTIONS) {
|
|
|
634 |
return [
|
|
|
635 |
'status' => false,
|
|
|
636 |
'error' => 'ERROR_SUPPLY_VALID_SHARING_WITH_TYPE',
|
|
|
637 |
];
|
|
|
638 |
}
|
|
|
639 |
|
|
|
640 |
$feed->shared_with = $shared_with;
|
|
|
641 |
if (Feed::SHARED == $feed->posted_or_shared) {
|
|
|
642 |
$shared_feed_id = empty($dataPost['shared_feed_id']) ? 0 : $dataPost['shared_feed_id'];
|
|
|
643 |
|
|
|
644 |
|
|
|
645 |
$sharedFeed = $feedMapper->fetchOneByIdAndNetworkId($shared_feed_id, $currentUser->network_id);
|
|
|
646 |
if (!$sharedFeed) {
|
|
|
647 |
return [
|
|
|
648 |
'status' => false,
|
|
|
649 |
'error' => 'ERROR_POST_SHARE',
|
|
|
650 |
];
|
|
|
651 |
}
|
|
|
652 |
|
|
|
653 |
$feed->shared_feed_id = $sharedFeed->id;
|
|
|
654 |
$feed->shared_company_id = $sharedFeed->shared_company_id;
|
|
|
655 |
$feed->shared_group_id = $sharedFeed->shared_group_id;
|
|
|
656 |
$feed->shared_job_id = $sharedFeed->shared_job_id;
|
|
|
657 |
} else {
|
|
|
658 |
$sharedFeed = null;
|
|
|
659 |
}
|
|
|
660 |
|
|
|
661 |
$feed->status = Feed::STATUS_PUBLISHED;
|
|
|
662 |
$feed->total_comments = 0;
|
|
|
663 |
$feed->total_shared = 0;
|
|
|
664 |
|
|
|
665 |
$result = $feedMapper->insert($feed);
|
|
|
666 |
if ($result) {
|
|
|
667 |
|
|
|
668 |
if ($sharedFeed && $sharedFeed->type == Feed::TYPE_UPDATE) {
|
|
|
669 |
|
|
|
670 |
|
|
|
671 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
672 |
$ownerFeed = $userMapper->fetchOne($sharedFeed->user_id);
|
|
|
673 |
|
|
|
674 |
$notification = new Notification();
|
|
|
675 |
$notification->type = Notification::TYPE_SHARE_MY_FEED;
|
|
|
676 |
$notification->read = Notification::NO;
|
|
|
677 |
$notification->user_id = $ownerFeed->id;
|
|
|
678 |
$notification->feed_id = $feed->id;
|
|
|
679 |
$notification->message = 'LABEL_SHARE_MY_FEED';
|
|
|
680 |
$notification->url = $this->url()->fromRoute('dashboard', ['feed' => $sharedFeed->uuid]);
|
|
|
681 |
|
|
|
682 |
$notificationMapper = NotificationMapper::getInstance($this->adapter);
|
|
|
683 |
$notificationMapper->insert($notification);
|
|
|
684 |
|
|
|
685 |
$userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
|
|
|
686 |
$userNotification = $userNotificationMapper->fetchOne($ownerFeed->id);
|
|
|
687 |
|
|
|
688 |
if ($userNotification && $userNotification->share_my_feed) {
|
|
|
689 |
$emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
|
|
|
690 |
$emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_SHARE_MY_FEED, $currentUser->network_id);
|
|
|
691 |
|
|
|
692 |
if ($emailTemplate) {
|
|
|
693 |
$arrayCont = [
|
|
|
694 |
'firstname' => $currentUser->first_name,
|
|
|
695 |
'lastname' => $currentUser->last_name,
|
|
|
696 |
'other_user_firstname' => $ownerFeed->first_name,
|
|
|
697 |
'other_user_lastname' => $ownerFeed->last_name,
|
|
|
698 |
'company_name' => '',
|
|
|
699 |
'group_name' => '',
|
|
|
700 |
'content' => '',
|
|
|
701 |
'code' => '',
|
|
|
702 |
'link' => $this->url()->fromRoute('dashboard', ['feed' => $feed->uuid], ['force_canonical' => true])
|
|
|
703 |
];
|
|
|
704 |
|
|
|
705 |
$email = new QueueEmail($this->adapter);
|
|
|
706 |
$email->processEmailTemplate($emailTemplate, $arrayCont, $ownerFeed->email, trim($ownerFeed->first_name . ' ' . $ownerFeed->last_name));
|
|
|
707 |
}
|
|
|
708 |
}
|
|
|
709 |
}
|
|
|
710 |
|
|
|
711 |
|
|
|
712 |
$feed = $feedMapper->fetchOne($feed->id);
|
302 |
www |
713 |
|
345 |
www |
714 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
|
|
715 |
$storage->setFiles($this->getRequest()->getFiles()->toArray());
|
|
|
716 |
|
|
|
717 |
if($storage->setCurrentFilename('file')) {
|
|
|
718 |
$file_type = $storage->getFileType();
|
|
|
719 |
$source_filename = $storage->getTmpFilename();
|
|
|
720 |
$filename = $storage->getFilename();
|
283 |
www |
721 |
|
334 |
www |
722 |
|
345 |
www |
723 |
if ($file_type == Storage::FILE_TYPE_DOCUMENT) {
|
283 |
www |
724 |
|
345 |
www |
725 |
$target_filename = $storage->composePathToFilename(Storage::TYPE_FEED, $feed->uuid, $filename);
|
334 |
www |
726 |
|
|
|
727 |
|
345 |
www |
728 |
if ($storage->putFile($source_filename,$target_filename)) {
|
|
|
729 |
$feed->file_type = $file_type;
|
334 |
www |
730 |
$feed->file_name = $filename;
|
302 |
www |
731 |
$feedMapper->update($feed);
|
|
|
732 |
}
|
283 |
www |
733 |
|
345 |
www |
734 |
} else if ($file_type == Storage::FILE_TYPE_IMAGE) {
|
|
|
735 |
$filename = $storage->getFilenamePNG();
|
|
|
736 |
$target_filename = $storage->composePathToFilename(Storage::TYPE_FEED, $feed->uuid, $filename);
|
|
|
737 |
|
598 |
stevensc |
738 |
// list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.feed_image_size']);
|
302 |
www |
739 |
|
598 |
stevensc |
740 |
if($storage->uploadImageWithOutChangeSize($source_filename, $target_filename)) {
|
345 |
www |
741 |
$feed->file_type = $file_type;
|
|
|
742 |
$feed->file_name = $filename;
|
|
|
743 |
$feedMapper->update($feed);
|
|
|
744 |
}
|
|
|
745 |
} else if ($file_type == Storage::FILE_TYPE_VIDEO) {
|
334 |
www |
746 |
|
345 |
www |
747 |
$source_filename = $storage->getTmpFilename();
|
|
|
748 |
$filename = $storage->getFilename();
|
334 |
www |
749 |
|
345 |
www |
750 |
$target_filename = $storage->composePathToFilename(Storage::TYPE_FEED, $feed->uuid, $filename);
|
334 |
www |
751 |
|
345 |
www |
752 |
if($storage->moveUploadedFile($source_filename, $target_filename )) {
|
|
|
753 |
$feed->file_type = $file_type;
|
|
|
754 |
$feed->file_name = $filename;
|
302 |
www |
755 |
|
|
|
756 |
|
345 |
www |
757 |
$filename = $storage->getFilenamePNG();
|
|
|
758 |
$source_filename = $target_filename;
|
|
|
759 |
$target_filename = $storage->composePathToFilename(Storage::TYPE_FEED, $feed->uuid, $filename);
|
302 |
www |
760 |
|
345 |
www |
761 |
if($storage->extractPosterFromVideo($source_filename, $target_filename)) {
|
|
|
762 |
|
|
|
763 |
$feed->file_image_preview = $filename;
|
302 |
www |
764 |
}
|
|
|
765 |
|
334 |
www |
766 |
|
345 |
www |
767 |
if($feedMapper->update($feed)) {
|
|
|
768 |
|
|
|
769 |
$videoConvert = new VideoConvert();
|
|
|
770 |
$videoConvert->uuid = $feed->uuid;
|
|
|
771 |
$videoConvert->filename = $feed->file_name;
|
|
|
772 |
$videoConvert->type = VideoConvert::TYPE_FEED;
|
|
|
773 |
|
|
|
774 |
$videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
|
|
|
775 |
$videoConvertMapper->insert($videoConvert);
|
|
|
776 |
}
|
1 |
efrain |
777 |
}
|
345 |
www |
778 |
|
1 |
efrain |
779 |
}
|
334 |
www |
780 |
|
1 |
efrain |
781 |
}
|
|
|
782 |
|
|
|
783 |
return [
|
|
|
784 |
'success' => true,
|
|
|
785 |
'data' => $this->renderFeed($feed->id, $now)
|
|
|
786 |
];
|
|
|
787 |
} else {
|
|
|
788 |
return [
|
|
|
789 |
'success' => false,
|
|
|
790 |
'data' => $feedMapper->getError()
|
|
|
791 |
];
|
|
|
792 |
}
|
|
|
793 |
} else {
|
|
|
794 |
$messages = [];
|
|
|
795 |
$form_messages = (array) $form->getMessages();
|
|
|
796 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
797 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
798 |
}
|
|
|
799 |
|
|
|
800 |
return [
|
|
|
801 |
'success' => false,
|
|
|
802 |
'data' => $messages
|
|
|
803 |
];
|
|
|
804 |
}
|
|
|
805 |
}
|
|
|
806 |
|
|
|
807 |
public function saveReactionAction()
|
|
|
808 |
{
|
|
|
809 |
$id = $this->params()->fromRoute('id');
|
|
|
810 |
// $reaction = $this->params()->fromRoute('reaction');
|
|
|
811 |
$reaction = $this->params()->fromPost('reaction');
|
|
|
812 |
|
|
|
813 |
$request = $this->getRequest();
|
|
|
814 |
if ($request->isPost()) {
|
|
|
815 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
816 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
817 |
|
|
|
818 |
|
|
|
819 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
820 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
821 |
if (!$feed) {
|
|
|
822 |
$response = [
|
|
|
823 |
'success' => false,
|
|
|
824 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
825 |
];
|
|
|
826 |
return new JsonModel($response);
|
|
|
827 |
}
|
|
|
828 |
|
|
|
829 |
$reactions = [
|
|
|
830 |
ContentReaction::REACTION_RECOMMENDED,
|
|
|
831 |
ContentReaction::REACTION_SUPPORT,
|
|
|
832 |
ContentReaction::REACTION_LOVE,
|
|
|
833 |
ContentReaction::REACTION_INTEREST,
|
|
|
834 |
ContentReaction::REACTION_FUN
|
|
|
835 |
|
|
|
836 |
];
|
|
|
837 |
if(!in_array($reaction, $reactions)) {
|
|
|
838 |
$response = [
|
|
|
839 |
'success' => false,
|
|
|
840 |
'data' => 'ERROR_REACTION_NOT_FOUND'
|
|
|
841 |
];
|
|
|
842 |
return new JsonModel($response);
|
|
|
843 |
}
|
|
|
844 |
|
|
|
845 |
|
|
|
846 |
$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
|
|
847 |
$contentReaction = $contentReactionMapper->fetchOneByFeedIdAndUserId($feed->id, $currentUser->id);
|
|
|
848 |
|
|
|
849 |
if ($contentReaction) {
|
|
|
850 |
$contentReaction->reaction = $reaction;
|
|
|
851 |
$result = $contentReactionMapper->update($contentReaction);
|
|
|
852 |
} else {
|
|
|
853 |
$contentReaction = new ContentReaction();
|
|
|
854 |
$contentReaction->user_id = $currentUser->id;
|
|
|
855 |
$contentReaction->feed_id = $feed->id;
|
|
|
856 |
$contentReaction->relational = ContentReaction::RELATIONAL_FEED;
|
|
|
857 |
$contentReaction->reaction = $reaction;
|
|
|
858 |
|
|
|
859 |
$result = $contentReactionMapper->insert($contentReaction);
|
|
|
860 |
}
|
|
|
861 |
|
|
|
862 |
|
|
|
863 |
|
|
|
864 |
if ($result) {
|
|
|
865 |
|
|
|
866 |
$reactions = $contentReactionMapper->fetchCountByFeedId($feed->id);
|
|
|
867 |
$response = [
|
|
|
868 |
'success' => true,
|
|
|
869 |
'data' => [
|
|
|
870 |
'reactions' => $reactions
|
|
|
871 |
]
|
|
|
872 |
];
|
|
|
873 |
} else {
|
|
|
874 |
$response = [
|
|
|
875 |
'success' => false,
|
|
|
876 |
'data' => $contentReactionMapper->getError()
|
|
|
877 |
];
|
|
|
878 |
}
|
|
|
879 |
return new JsonModel($response);
|
|
|
880 |
}
|
|
|
881 |
|
|
|
882 |
$response = [
|
|
|
883 |
'success' => false,
|
|
|
884 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
885 |
];
|
|
|
886 |
return new JsonModel($response);
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
public function deleteReactionAction()
|
|
|
890 |
{
|
|
|
891 |
$id = $this->params()->fromRoute('id');
|
|
|
892 |
|
|
|
893 |
$request = $this->getRequest();
|
|
|
894 |
if ($request->isPost()) {
|
|
|
895 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
896 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
897 |
|
|
|
898 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
899 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
900 |
if (!$feed) {
|
|
|
901 |
$response = [
|
|
|
902 |
'success' => false,
|
|
|
903 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
904 |
];
|
|
|
905 |
return new JsonModel($response);
|
|
|
906 |
}
|
|
|
907 |
|
|
|
908 |
$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
|
|
909 |
$contentReaction = $contentReactionMapper->fetchOneByFeedIdAndUserId($feed->id, $currentUser->id);
|
|
|
910 |
|
|
|
911 |
if (!$contentReaction) {
|
|
|
912 |
$response = [
|
|
|
913 |
'success' => false,
|
|
|
914 |
'data' => 'ERROR_DUPLICATE_ACTION'
|
|
|
915 |
];
|
|
|
916 |
return new JsonModel($response);
|
|
|
917 |
}
|
|
|
918 |
|
|
|
919 |
if ($contentReactionMapper->deleteByFeedIdAndUserId($feed->id, $currentUser->id)) {
|
|
|
920 |
$reactions = $contentReactionMapper->fetchCountByFeedId($feed->id);
|
|
|
921 |
|
|
|
922 |
|
|
|
923 |
$response = [
|
|
|
924 |
'success' => true,
|
|
|
925 |
'data' => [
|
|
|
926 |
'reactions' => $reactions
|
|
|
927 |
]
|
|
|
928 |
];
|
|
|
929 |
} else {
|
|
|
930 |
$response = [
|
|
|
931 |
'success' => false,
|
|
|
932 |
'data' => $contentReactionMapper->getError()
|
|
|
933 |
];
|
|
|
934 |
}
|
|
|
935 |
return new JsonModel($response);
|
|
|
936 |
}
|
|
|
937 |
|
|
|
938 |
$response = [
|
|
|
939 |
'success' => false,
|
|
|
940 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
941 |
];
|
|
|
942 |
return new JsonModel($response);
|
|
|
943 |
}
|
|
|
944 |
|
|
|
945 |
/*
|
|
|
946 |
public function likeAction()
|
|
|
947 |
{
|
|
|
948 |
$id = $this->params()->fromRoute('id');
|
|
|
949 |
|
|
|
950 |
$request = $this->getRequest();
|
|
|
951 |
if ($request->isPost()) {
|
|
|
952 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
953 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
954 |
|
|
|
955 |
|
|
|
956 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
957 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
958 |
if (!$feed) {
|
|
|
959 |
$response = [
|
|
|
960 |
'success' => false,
|
|
|
961 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
962 |
];
|
|
|
963 |
return new JsonModel($response);
|
|
|
964 |
}
|
|
|
965 |
|
|
|
966 |
$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
|
|
967 |
$contentReaction = $contentReactionMapper->fetchOneByFeedIdAndUserId($feed->id, $currentUser->id);
|
|
|
968 |
|
|
|
969 |
if ($contentReaction) {
|
|
|
970 |
$response = [
|
|
|
971 |
'success' => false,
|
|
|
972 |
'data' => 'ERROR_DUPLICATE_ACTION'
|
|
|
973 |
];
|
|
|
974 |
return new JsonModel($response);
|
|
|
975 |
}
|
|
|
976 |
|
|
|
977 |
$contentReaction = new Like();
|
|
|
978 |
$contentReaction->user_id = $currentUser->id;
|
|
|
979 |
$contentReaction->feed_id = $feed->id;
|
|
|
980 |
$contentReaction->relational = Like::RELATIONAL_FEED;
|
|
|
981 |
|
|
|
982 |
if ($contentReactionMapper->insert($contentReaction)) {
|
|
|
983 |
|
|
|
984 |
$contentReactions = $contentReactionMapper->fetchCountLikeByFeedId($feed->id);
|
|
|
985 |
|
|
|
986 |
|
|
|
987 |
|
|
|
988 |
if ($feed->type == Feed::TYPE_UPDATE) {
|
|
|
989 |
|
|
|
990 |
|
|
|
991 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
992 |
$ownerFeed = $userMapper->fetchOne($feed->user_id);
|
|
|
993 |
|
|
|
994 |
$notification = new Notification();
|
|
|
995 |
$notification->type = Notification::TYPE_LIKE_MY_FEED;
|
|
|
996 |
$notification->read = Notification::NO;
|
|
|
997 |
$notification->user_id = $feed->user_id;
|
|
|
998 |
$notification->feed_id = $feed->id;
|
|
|
999 |
$notification->message = 'LABEL_LIKE_MY_FEED';
|
|
|
1000 |
$notification->url = $this->url()->fromRoute('dashboard', ['feed' => $feed->uuid]);
|
|
|
1001 |
|
|
|
1002 |
$notificationMapper = NotificationMapper::getInstance($this->adapter);
|
|
|
1003 |
$notificationMapper->insert($notification);
|
|
|
1004 |
|
|
|
1005 |
$userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
|
|
|
1006 |
$userNotification = $userNotificationMapper->fetchOne($ownerFeed->id);
|
|
|
1007 |
|
|
|
1008 |
if ($userNotification && $userNotification->like_my_feed) {
|
|
|
1009 |
$emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
|
|
|
1010 |
$emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_LIKE_MY_FEED, $currentUser->network_id);
|
|
|
1011 |
|
|
|
1012 |
if ($emailTemplate) {
|
|
|
1013 |
$arrayCont = [
|
|
|
1014 |
'firstname' => $currentUser->first_name,
|
|
|
1015 |
'lastname' => $currentUser->last_name,
|
|
|
1016 |
'other_user_firstname' => $ownerFeed->first_name,
|
|
|
1017 |
'other_user_lastname' => $ownerFeed->last_name,
|
|
|
1018 |
'company_name' => '',
|
|
|
1019 |
'group_name' => '',
|
|
|
1020 |
'content' => '',
|
|
|
1021 |
'code' => '',
|
|
|
1022 |
'link' => $this->url()->fromRoute('dashboard', ['feed' => $feed->uuid], ['force_canonical' => true])
|
|
|
1023 |
];
|
|
|
1024 |
|
|
|
1025 |
$email = new QueueEmail($this->adapter);
|
|
|
1026 |
$email->processEmailTemplate($emailTemplate, $arrayCont, $ownerFeed->email, trim($ownerFeed->first_name . ' ' . $ownerFeed->last_name));
|
|
|
1027 |
}
|
|
|
1028 |
}
|
|
|
1029 |
}
|
|
|
1030 |
|
|
|
1031 |
|
|
|
1032 |
|
|
|
1033 |
|
|
|
1034 |
|
|
|
1035 |
|
|
|
1036 |
|
|
|
1037 |
|
|
|
1038 |
$response = [
|
|
|
1039 |
'success' => true,
|
|
|
1040 |
'data' => [
|
|
|
1041 |
'likes' => $contentReactions
|
|
|
1042 |
]
|
|
|
1043 |
];
|
|
|
1044 |
} else {
|
|
|
1045 |
$response = [
|
|
|
1046 |
'success' => false,
|
|
|
1047 |
'data' => $contentReactionMapper->getError()
|
|
|
1048 |
];
|
|
|
1049 |
}
|
|
|
1050 |
return new JsonModel($response);
|
|
|
1051 |
}
|
|
|
1052 |
|
|
|
1053 |
$response = [
|
|
|
1054 |
'success' => false,
|
|
|
1055 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1056 |
];
|
|
|
1057 |
return new JsonModel($response);
|
|
|
1058 |
}
|
|
|
1059 |
|
|
|
1060 |
public function unlikeAction()
|
|
|
1061 |
{
|
|
|
1062 |
$id = $this->params()->fromRoute('id');
|
|
|
1063 |
|
|
|
1064 |
$request = $this->getRequest();
|
|
|
1065 |
if ($request->isPost()) {
|
|
|
1066 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1067 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1068 |
|
|
|
1069 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
1070 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
1071 |
if (!$feed) {
|
|
|
1072 |
$response = [
|
|
|
1073 |
'success' => false,
|
|
|
1074 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
1075 |
];
|
|
|
1076 |
return new JsonModel($response);
|
|
|
1077 |
}
|
|
|
1078 |
|
|
|
1079 |
$contentReactionMapper = LikeMapper::getInstance($this->adapter);
|
|
|
1080 |
$contentReaction = $contentReactionMapper->fetchOneByFeedIdAndUserId($feed->id, $currentUser->id);
|
|
|
1081 |
|
|
|
1082 |
if (!$contentReaction) {
|
|
|
1083 |
$response = [
|
|
|
1084 |
'success' => false,
|
|
|
1085 |
'data' => 'ERROR_DUPLICATE_ACTION'
|
|
|
1086 |
];
|
|
|
1087 |
return new JsonModel($response);
|
|
|
1088 |
}
|
|
|
1089 |
|
|
|
1090 |
if ($contentReactionMapper->deleteByFeedIdAndUserId($feed->id, $currentUser->id)) {
|
|
|
1091 |
$contentReactions = $contentReactionMapper->fetchCountLikeByFeedId($feed->id);
|
|
|
1092 |
|
|
|
1093 |
|
|
|
1094 |
$response = [
|
|
|
1095 |
'success' => true,
|
|
|
1096 |
'data' => [
|
|
|
1097 |
'likes' => $contentReactions
|
|
|
1098 |
]
|
|
|
1099 |
];
|
|
|
1100 |
} else {
|
|
|
1101 |
$response = [
|
|
|
1102 |
'success' => false,
|
|
|
1103 |
'data' => $contentReactionMapper->getError()
|
|
|
1104 |
];
|
|
|
1105 |
}
|
|
|
1106 |
return new JsonModel($response);
|
|
|
1107 |
}
|
|
|
1108 |
|
|
|
1109 |
$response = [
|
|
|
1110 |
'success' => false,
|
|
|
1111 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1112 |
];
|
|
|
1113 |
return new JsonModel($response);
|
|
|
1114 |
}*/
|
|
|
1115 |
|
|
|
1116 |
public function timelineAction()
|
|
|
1117 |
{
|
602 |
stevensc |
1118 |
$request = $this->getRequest();
|
1 |
efrain |
1119 |
|
|
|
1120 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1121 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1122 |
|
|
|
1123 |
$type = $this->params()->fromRoute('type');
|
602 |
stevensc |
1124 |
$id = $type == 'user' ? $currentUser->id : $this->params()->fromRoute('id');
|
|
|
1125 |
$feedUuid = $this->params()->fromRoute('feed');
|
1 |
efrain |
1126 |
|
|
|
1127 |
$feedHighlighted = 0;
|
|
|
1128 |
|
|
|
1129 |
if ($feedUuid) {
|
|
|
1130 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
1131 |
$now = $feedMapper->getDatebaseNow();
|
|
|
1132 |
|
|
|
1133 |
$feed = $feedMapper->fetchOneByUuidAndNetworkIdAnyStatus($feedUuid, $currentUser->network_id);
|
|
|
1134 |
|
|
|
1135 |
if ($feed) {
|
|
|
1136 |
$feedHighlighted = $feed->id;
|
|
|
1137 |
}
|
|
|
1138 |
}
|
|
|
1139 |
|
|
|
1140 |
|
|
|
1141 |
|
|
|
1142 |
if ($request->isGet()) {
|
192 |
efrain |
1143 |
$userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
|
|
|
1144 |
$user_blocked_ids = $userBlockedMapper->fetchAllBlockedReturnIds($currentUser->id);
|
|
|
1145 |
|
|
|
1146 |
$abuseReportMapper = AbuseReportMapper::getInstance($this->adapter);
|
|
|
1147 |
$abuse_report_feed_ids = $abuseReportMapper->fetchAllDataByUserReportingIdAndTypeReturnIds($currentUser->id, AbuseReport::TYPE_FEED);
|
|
|
1148 |
|
|
|
1149 |
$abuse_report_comment_ids = $abuseReportMapper->fetchAllDataByUserReportingIdAndTypeReturnIds($currentUser->id, AbuseReport::TYPE_COMMENT);
|
|
|
1150 |
|
1 |
efrain |
1151 |
$exclude_feed_ids = [];
|
|
|
1152 |
|
|
|
1153 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
1154 |
|
|
|
1155 |
$selectNotUserCompany = $queryMapper->getSql()->select();
|
|
|
1156 |
$selectNotUserCompany->columns(['company_id']);
|
|
|
1157 |
$selectNotUserCompany->from(['cu' => CompanyUserMapper::_TABLE]);
|
|
|
1158 |
|
|
|
1159 |
$selectNotUserCompany->where->equalTo('user_id', $currentUser->id);
|
|
|
1160 |
$selectNotUserCompany->where->in('status', [CompanyUser::STATUS_ACCEPTED, CompanyUser::STATUS_ADMIN_WILL_ADD]);
|
|
|
1161 |
|
|
|
1162 |
$select = $queryMapper->getSql()->select();
|
|
|
1163 |
$select->columns(['id']);
|
|
|
1164 |
$select->from(['f' => FeedMapper::_TABLE]);
|
|
|
1165 |
$select->join(['fs' => FastSurveyMapper::_TABLE], 'fs.id = f.fast_survey_id', []);
|
|
|
1166 |
$select->where->equalTo('f.file_type', Feed::FILE_TYPE_FAST_SURVEY);
|
|
|
1167 |
$select->where->equalTo('f.network_id', $currentUser->network_id);
|
|
|
1168 |
$select->where->equalTo('f.status', Feed::STATUS_PUBLISHED);
|
|
|
1169 |
$select->where->equalTo('fs.privacy', FastSurvey::PRIVACY_COMPANY);
|
|
|
1170 |
$select->where->notIn('fs.company_id', $selectNotUserCompany);
|
|
|
1171 |
|
|
|
1172 |
$records = $queryMapper->fetchAll($select);
|
|
|
1173 |
foreach($records as $record)
|
|
|
1174 |
{
|
|
|
1175 |
array_push($exclude_feed_ids, $record['id']);
|
|
|
1176 |
}
|
|
|
1177 |
|
|
|
1178 |
|
|
|
1179 |
$page = (int) $this->params()->fromQuery('page');
|
|
|
1180 |
if ($type == 'user') {
|
|
|
1181 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
|
|
1182 |
$now = $connectionMapper->getDatebaseNow();
|
|
|
1183 |
|
|
|
1184 |
$records = $connectionMapper->fetchAllConnectionsByUser($id);
|
|
|
1185 |
$connectionIds = [0];
|
|
|
1186 |
foreach ($records as $record) {
|
|
|
1187 |
if ($currentUser->id == $record->request_from) {
|
|
|
1188 |
array_push($connectionIds, $record->request_to);
|
|
|
1189 |
} else {
|
|
|
1190 |
array_push($connectionIds, $record->request_from);
|
|
|
1191 |
}
|
|
|
1192 |
}
|
|
|
1193 |
array_push($connectionIds, 1);
|
|
|
1194 |
|
|
|
1195 |
$companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
|
|
|
1196 |
$records = $companyFollowerMapper->fetchAllByFollowerId($currentUser->id);
|
|
|
1197 |
|
|
|
1198 |
$companyIds = [0];
|
|
|
1199 |
foreach ($records as $record) {
|
|
|
1200 |
if (!in_array($record->company_id, $companyIds)) {
|
|
|
1201 |
array_push($companyIds, $record->company_id);
|
|
|
1202 |
}
|
|
|
1203 |
}
|
|
|
1204 |
|
|
|
1205 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1206 |
$companyUsers = $companyUserMapper->fetchAllByUserId($currentUser->id);
|
|
|
1207 |
|
|
|
1208 |
foreach ($companyUsers as $companyUser) {
|
|
|
1209 |
if ($companyUser->status == CompanyUser::STATUS_ACCEPTED) {
|
|
|
1210 |
if (!in_array($companyUser->company_id, $companyIds)) {
|
|
|
1211 |
array_push($companyIds, $companyUser->company_id);
|
|
|
1212 |
}
|
|
|
1213 |
}
|
|
|
1214 |
}
|
|
|
1215 |
|
|
|
1216 |
|
|
|
1217 |
$groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
|
|
|
1218 |
$groupMembers = $groupMemberMapper->fetchAllByUserId($currentUser->id);
|
|
|
1219 |
|
|
|
1220 |
$groupIds = [0];
|
|
|
1221 |
|
|
|
1222 |
foreach ($groupMembers as $groupMember) {
|
|
|
1223 |
if ($groupMember->status == GroupMember::STATUS_ACCEPTED) {
|
|
|
1224 |
if (!in_array($groupMember->group_id, $groupIds)) {
|
|
|
1225 |
array_push($groupIds, $groupMember->group_id);
|
|
|
1226 |
}
|
|
|
1227 |
}
|
|
|
1228 |
}
|
|
|
1229 |
|
|
|
1230 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
1231 |
$select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
|
|
|
1232 |
$select->columns(['id']);
|
|
|
1233 |
$select->where->equalTo('network_id', $currentUser->network_id);
|
|
|
1234 |
$select->where->equalTo('status', Feed::STATUS_PUBLISHED)
|
|
|
1235 |
->AND->NEST
|
|
|
1236 |
->OR->NEST->equalTo('user_id', $id)->and->equalTo('type', Feed::TYPE_UPDATE)->UNNEST
|
|
|
1237 |
->OR->NEST->and->equalTo('type', Feed::TYPE_UPDATE)->and->equalTo('shared_with', Feed::SHARE_WITH_PUBLIC)->UNNEST
|
|
|
1238 |
->OR->NEST->in('user_id', $connectionIds)->and->equalTo('type', Feed::TYPE_UPDATE)->and->equalTo('shared_with', Feed::SHARE_WITH_CONNECTIONS)->UNNEST
|
|
|
1239 |
->OR->NEST->or->in('company_id', $companyIds)->and->equalTo('type', Feed::TYPE_COMPANY)->UNNEST
|
|
|
1240 |
->OR->NEST->or->in('group_id', $groupIds)->and->equalTo('type', Feed::TYPE_GROUP)->UNNEST
|
|
|
1241 |
->UNNEST;
|
|
|
1242 |
|
|
|
1243 |
if($exclude_feed_ids) {
|
|
|
1244 |
$select->where->notIn('id', $exclude_feed_ids);
|
|
|
1245 |
}
|
192 |
efrain |
1246 |
if($abuse_report_feed_ids) {
|
|
|
1247 |
$select->where->notIn('id', $abuse_report_feed_ids);
|
|
|
1248 |
}
|
|
|
1249 |
if($user_blocked_ids) {
|
|
|
1250 |
$select->where->notIn('user_id', $user_blocked_ids);
|
|
|
1251 |
}
|
1 |
efrain |
1252 |
|
|
|
1253 |
|
|
|
1254 |
$select->order('added_on desc');
|
|
|
1255 |
}
|
|
|
1256 |
if ($type == 'company') {
|
|
|
1257 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1258 |
$now = $companyMapper->getDatebaseNow();
|
|
|
1259 |
|
|
|
1260 |
$company = $companyMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
1261 |
|
|
|
1262 |
if (!$company || $company->status != Company::STATUS_ACTIVE) {
|
|
|
1263 |
$id = 0;
|
|
|
1264 |
} else {
|
|
|
1265 |
$companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
|
|
|
1266 |
$companyFollower = $companyFollowerMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
|
|
|
1267 |
if ($companyFollower) {
|
|
|
1268 |
$id = $company->id;
|
|
|
1269 |
} else {
|
|
|
1270 |
|
|
|
1271 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1272 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
|
|
|
1273 |
|
|
|
1274 |
if (!$companyUser || $companyUser->status != CompanyUser::STATUS_ACCEPTED) {
|
|
|
1275 |
$id = 0;
|
|
|
1276 |
} else {
|
|
|
1277 |
$id = $company->id;
|
|
|
1278 |
}
|
|
|
1279 |
}
|
|
|
1280 |
}
|
|
|
1281 |
|
|
|
1282 |
|
|
|
1283 |
|
|
|
1284 |
$select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
|
|
|
1285 |
$select->columns(['id']);
|
|
|
1286 |
$select->where->equalTo('network_id', $currentUser->network_id);
|
|
|
1287 |
$select->where->equalTo('status', Feed::STATUS_PUBLISHED);
|
|
|
1288 |
$select->where->equalTo('company_id', $id);
|
|
|
1289 |
$select->where->and->equalTo('type', Feed::TYPE_COMPANY);
|
|
|
1290 |
|
|
|
1291 |
if($exclude_feed_ids) {
|
|
|
1292 |
$select->where->notIn('id', $exclude_feed_ids);
|
|
|
1293 |
}
|
192 |
efrain |
1294 |
if($abuse_report_feed_ids) {
|
|
|
1295 |
$select->where->notIn('id', $abuse_report_feed_ids);
|
|
|
1296 |
}
|
|
|
1297 |
if($user_blocked_ids) {
|
|
|
1298 |
$select->where->notIn('user_id', $user_blocked_ids);
|
|
|
1299 |
}
|
1 |
efrain |
1300 |
|
|
|
1301 |
$select->order('added_on desc');
|
|
|
1302 |
}
|
|
|
1303 |
if ($type == 'group') {
|
|
|
1304 |
$groupMapper = GroupMapper::getInstance($this->adapter);
|
|
|
1305 |
$now = $groupMapper->getDatebaseNow();
|
|
|
1306 |
|
|
|
1307 |
$group = $groupMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
1308 |
|
|
|
1309 |
$id = 0;
|
|
|
1310 |
|
|
|
1311 |
if ($group && $group->status == Group::STATUS_ACTIVE) {
|
|
|
1312 |
$groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
|
|
|
1313 |
$groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $currentUser->id);
|
|
|
1314 |
if ($groupMember) {
|
|
|
1315 |
|
|
|
1316 |
|
|
|
1317 |
if (
|
|
|
1318 |
$groupMember->status == GroupMember::STATUS_ACCEPTED ||
|
|
|
1319 |
$groupMember->status == GroupMember::STATUS_AUTO_JOIN
|
|
|
1320 |
) {
|
|
|
1321 |
|
|
|
1322 |
$id = $groupMember->group_id;
|
|
|
1323 |
}
|
|
|
1324 |
}
|
|
|
1325 |
}
|
|
|
1326 |
|
|
|
1327 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
1328 |
$select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
|
|
|
1329 |
$select->columns(['id']);
|
|
|
1330 |
$select->where->equalTo('network_id', $currentUser->network_id);
|
|
|
1331 |
$select->where->equalTo('status', Feed::STATUS_PUBLISHED);
|
|
|
1332 |
$select->where->equalTo('group_id', $id);
|
|
|
1333 |
$select->where->nest()->equalTo('type', Feed::TYPE_GROUP)
|
|
|
1334 |
->or->equalTo('type', Feed::TYPE_UPDATE)->unnest();
|
|
|
1335 |
|
|
|
1336 |
if($exclude_feed_ids) {
|
|
|
1337 |
$select->where->notIn('id', $exclude_feed_ids);
|
|
|
1338 |
}
|
192 |
efrain |
1339 |
if($abuse_report_feed_ids) {
|
|
|
1340 |
$select->where->notIn('id', $abuse_report_feed_ids);
|
|
|
1341 |
}
|
|
|
1342 |
if($user_blocked_ids) {
|
|
|
1343 |
$select->where->notIn('user_id', $user_blocked_ids);
|
|
|
1344 |
}
|
1 |
efrain |
1345 |
|
|
|
1346 |
$select->order('added_on desc');
|
|
|
1347 |
}
|
|
|
1348 |
|
|
|
1349 |
$dbSelect = new DbSelect($select, $this->adapter);
|
|
|
1350 |
$paginator = new Paginator($dbSelect);
|
|
|
1351 |
$paginator->setCurrentPageNumber($page ? $page : 1);
|
|
|
1352 |
$paginator->setItemCountPerPage(10);
|
|
|
1353 |
|
|
|
1354 |
$items = [];
|
|
|
1355 |
|
|
|
1356 |
|
|
|
1357 |
if ($feedHighlighted) {
|
|
|
1358 |
|
|
|
1359 |
|
192 |
efrain |
1360 |
$items[] = $this->renderFeed($feedHighlighted, $now, $feedHighlighted, $user_blocked_ids , $abuse_report_comment_ids);
|
1 |
efrain |
1361 |
}
|
|
|
1362 |
|
|
|
1363 |
$feeds = $paginator->getCurrentItems();
|
|
|
1364 |
foreach ($feeds as $feed) {
|
192 |
efrain |
1365 |
$items[] = $this->renderFeed($feed->id, $now, $feedHighlighted, $user_blocked_ids , $abuse_report_comment_ids);
|
1 |
efrain |
1366 |
}
|
|
|
1367 |
|
|
|
1368 |
$response = [
|
|
|
1369 |
'success' => true,
|
|
|
1370 |
'data' => [
|
|
|
1371 |
'total' => [
|
|
|
1372 |
'count' => $paginator->getTotalItemCount(),
|
|
|
1373 |
'pages' => $paginator->getPages()->pageCount,
|
|
|
1374 |
],
|
|
|
1375 |
'current' => [
|
|
|
1376 |
'items' => $items,
|
|
|
1377 |
'page' => $paginator->getCurrentPageNumber(),
|
|
|
1378 |
'count' => $paginator->getCurrentItemCount(),
|
|
|
1379 |
]
|
|
|
1380 |
]
|
|
|
1381 |
];
|
|
|
1382 |
|
|
|
1383 |
|
|
|
1384 |
|
|
|
1385 |
/*
|
|
|
1386 |
if($feedHighlighted) {
|
|
|
1387 |
|
|
|
1388 |
|
|
|
1389 |
$items[] = $this->renderFeed($feedHighlighted, $now, $feedHighlighted);
|
|
|
1390 |
|
|
|
1391 |
$response = [
|
|
|
1392 |
'success' => true,
|
|
|
1393 |
'data' => [
|
|
|
1394 |
'total' => [
|
|
|
1395 |
'count' => 1,
|
|
|
1396 |
'pages' => 1,
|
|
|
1397 |
],
|
|
|
1398 |
'current' => [
|
|
|
1399 |
'items' => $items,
|
|
|
1400 |
'page' => 1,
|
|
|
1401 |
'count' => 1,
|
|
|
1402 |
]
|
|
|
1403 |
]
|
|
|
1404 |
];
|
|
|
1405 |
} else {
|
|
|
1406 |
|
|
|
1407 |
|
|
|
1408 |
|
|
|
1409 |
$feeds = $paginator->getCurrentItems();
|
|
|
1410 |
foreach($feeds as $feed)
|
|
|
1411 |
{
|
|
|
1412 |
$items[] = $this->renderFeed($feed->id, $now, $feedHighlighted);
|
|
|
1413 |
}
|
|
|
1414 |
|
|
|
1415 |
$response = [
|
|
|
1416 |
'success' => true,
|
|
|
1417 |
'data' => [
|
|
|
1418 |
'total' => [
|
|
|
1419 |
'count' => $paginator->getTotalItemCount(),
|
|
|
1420 |
'pages' => $paginator->getPages()->pageCount,
|
|
|
1421 |
],
|
|
|
1422 |
'current' => [
|
|
|
1423 |
'items' => $items,
|
|
|
1424 |
'page' => $paginator->getCurrentPageNumber(),
|
|
|
1425 |
'count' => $paginator->getCurrentItemCount(),
|
|
|
1426 |
]
|
|
|
1427 |
]
|
|
|
1428 |
];
|
|
|
1429 |
}*/
|
|
|
1430 |
|
|
|
1431 |
|
|
|
1432 |
|
|
|
1433 |
return new JsonModel($response);
|
|
|
1434 |
}
|
|
|
1435 |
|
|
|
1436 |
$response = [
|
|
|
1437 |
'success' => false,
|
|
|
1438 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1439 |
];
|
|
|
1440 |
|
|
|
1441 |
|
|
|
1442 |
return new JsonModel($response);
|
|
|
1443 |
}
|
|
|
1444 |
|
|
|
1445 |
|
|
|
1446 |
|
|
|
1447 |
|
|
|
1448 |
/**
|
|
|
1449 |
*
|
|
|
1450 |
* @param int $feed_id
|
192 |
efrain |
1451 |
* @param int[] $user_blocked_ids
|
|
|
1452 |
* @param int[] $abuse_report_comment_ids
|
1 |
efrain |
1453 |
* @return array
|
|
|
1454 |
*/
|
192 |
efrain |
1455 |
private function renderFeed($feed_id, $now, $feedHighlighted = 0, $user_blocked_ids = [], $abuse_report_comment_ids = [])
|
1 |
efrain |
1456 |
{
|
283 |
www |
1457 |
|
1 |
efrain |
1458 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1459 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1460 |
|
347 |
www |
1461 |
//$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
1462 |
// $network = $currentNetworkPlugin->getNetwork();
|
1 |
efrain |
1463 |
|
|
|
1464 |
//$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1465 |
|
|
|
1466 |
//$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
1467 |
|
|
|
1468 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1469 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
1470 |
$feed = $feedMapper->fetchOneAnyStatus($feed_id);
|
|
|
1471 |
|
602 |
stevensc |
1472 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
1 |
efrain |
1473 |
|
|
|
1474 |
/*
|
|
|
1475 |
$contentReactionMapper = LikeMapper::getInstance($this->adapter);
|
|
|
1476 |
$contentReaction = $contentReactionMapper->fetchOneByFeedIdAndUserId($feed->id, $currentUser->id);
|
|
|
1477 |
$contentReactions = $contentReactionMapper->fetchCountLikeByFeedId($feed->id);
|
|
|
1478 |
*/
|
|
|
1479 |
$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
|
|
|
1480 |
$reactions = $contentReactionMapper->fetchCountByFeedId($feed->id);
|
|
|
1481 |
$reaction = $contentReactionMapper->fetchOneByFeedIdAndUserId($feed->id, $currentUser->id);
|
|
|
1482 |
|
|
|
1483 |
|
|
|
1484 |
$params = [
|
|
|
1485 |
'id' => $feed->uuid
|
|
|
1486 |
];
|
|
|
1487 |
if ($feed->company_id) {
|
|
|
1488 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1489 |
$company = $companyMapper->fetchOne($feed->company_id);
|
|
|
1490 |
|
|
|
1491 |
$params['company_id'] = $company->uuid;
|
|
|
1492 |
} else {
|
|
|
1493 |
$company = null;
|
|
|
1494 |
}
|
|
|
1495 |
if ($feed->group_id) {
|
|
|
1496 |
$groupMapper = GroupMapper::getInstance($this->adapter);
|
|
|
1497 |
$group = $groupMapper->fetchOne($feed->group_id);
|
|
|
1498 |
|
|
|
1499 |
$params['group_id'] = $group->uuid;
|
|
|
1500 |
} else {
|
|
|
1501 |
$group = null;
|
|
|
1502 |
}
|
|
|
1503 |
|
|
|
1504 |
|
|
|
1505 |
$timestamp = time();
|
|
|
1506 |
|
|
|
1507 |
list($usec, $sec) = explode(' ', microtime());
|
|
|
1508 |
$seed = intval($sec + ((float) $usec * 100000));
|
|
|
1509 |
mt_srand($seed, MT_RAND_MT19937);
|
|
|
1510 |
$rand = mt_rand();
|
|
|
1511 |
|
|
|
1512 |
|
|
|
1513 |
|
|
|
1514 |
$password = md5('user-' . $currentUser->uuid . '-feed-' . $feed->uuid . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $currentUser->share_key);
|
|
|
1515 |
|
|
|
1516 |
|
|
|
1517 |
$share_params = [
|
|
|
1518 |
'type' => 'feed',
|
|
|
1519 |
'code' => $feed->uuid,
|
|
|
1520 |
'user' => $currentUser->uuid,
|
|
|
1521 |
'timestamp' => $timestamp,
|
|
|
1522 |
'rand' => $rand,
|
|
|
1523 |
'password' => $password,
|
|
|
1524 |
];
|
|
|
1525 |
|
|
|
1526 |
|
|
|
1527 |
$share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params, ['force_canonical' => true]);
|
|
|
1528 |
|
|
|
1529 |
|
|
|
1530 |
$share_external_url = $this->url()->fromRoute('shorter/generate', ['code' => $feed->uuid, 'type' => 'feed'], ['force_canonical' => true]);
|
|
|
1531 |
|
|
|
1532 |
$item = [
|
|
|
1533 |
'feed_unique' => uniqid(),
|
|
|
1534 |
'feed_uuid' => $feed->uuid,
|
|
|
1535 |
'feed_my_reaction' => $reaction ? $reaction->reaction : '',
|
|
|
1536 |
'feed_delete_url' => '',
|
|
|
1537 |
'feed_content_type' => $feed->file_type ? $feed->file_type : '',
|
|
|
1538 |
'feed_reactions' => $reactions,
|
232 |
efrain |
1539 |
'feed_reactions_url' => $this->url()->fromRoute('feed/reactions', ['id' => $feed->uuid], ['force_canonical' => true]),
|
192 |
efrain |
1540 |
'feed_save_reaction_url' => $this->url()->fromRoute('feed/save-reaction', ['id' => $feed->uuid], ['force_canonical' => true]),
|
1 |
efrain |
1541 |
'feed_highlighted' => $feed->id == $feedHighlighted ? 1 : 0,
|
192 |
efrain |
1542 |
'feed_abuse_report_url' => $feed->user_id == $currentUser->id ? '' : $this->url()->fromRoute('helpers/abuse-report', ['type' => 'feed', 'id' => $feed->uuid], ['force_canonical' => true]),
|
1 |
efrain |
1543 |
//'is_liked' => $contentReaction ? 1 : 0,
|
|
|
1544 |
//'like_url' => $this->url()->fromRoute('post/like', ['id' => $post->uuid]),
|
|
|
1545 |
//'unlike_url' => $this->url()->fromRoute('post/unlike', ['id' => $post->uuid]),
|
|
|
1546 |
|
|
|
1547 |
];
|
|
|
1548 |
|
|
|
1549 |
$fastSurveyVote = '';
|
|
|
1550 |
if($feed->file_type == Feed::FILE_TYPE_FAST_SURVEY) {
|
|
|
1551 |
|
|
|
1552 |
$fastSurveyVoteMapper = FastSurveyVoteMapper::getInstance($this->adapter);
|
|
|
1553 |
$fastSurveyVote = $fastSurveyVoteMapper->fetchOneByFastSurveyIdAndUserId($feed->fast_survey_id, $currentUser->id);
|
|
|
1554 |
|
|
|
1555 |
|
|
|
1556 |
|
|
|
1557 |
$item['feed_save_reaction_url'] = '';
|
|
|
1558 |
$item['feed_delete_reaction_url'] = '';
|
|
|
1559 |
$item['feed_share_url'] = '';
|
|
|
1560 |
$item['feed_share_external_url'] = '';
|
|
|
1561 |
$item['feed_increment_external_counter_url'] = '';
|
|
|
1562 |
|
345 |
www |
1563 |
$item['feed_vote_url'] = $fastSurveyVote ? '' : $this->url()->fromRoute('feed/vote', ['id' => $feed->uuid], ['force_canonical' => true]);
|
1 |
efrain |
1564 |
|
|
|
1565 |
} else {
|
247 |
efrain |
1566 |
$item['feed_save_reaction_url'] = $this->url()->fromRoute('feed/save-reaction', $params, ['force_canonical' => true]);
|
|
|
1567 |
$item['feed_delete_reaction_url'] = $this->url()->fromRoute('feed/delete-reaction', $params, ['force_canonical' => true]);
|
|
|
1568 |
$item['feed_share_url'] = $this->url()->fromRoute('feed/share', $params, ['force_canonical' => true]);
|
1 |
efrain |
1569 |
$item['feed_share_external_url'] = $share_external_url;
|
|
|
1570 |
$item['feed_increment_external_counter_url'] = $share_increment_external_counter_url;
|
|
|
1571 |
$item['feed_vote_url'] = '';
|
|
|
1572 |
}
|
|
|
1573 |
|
|
|
1574 |
|
|
|
1575 |
if ($feed->posted_or_shared == Feed::POSTED) {
|
|
|
1576 |
|
|
|
1577 |
if ($feed->type == Feed::TYPE_COMPANY) {
|
283 |
www |
1578 |
|
|
|
1579 |
|
1 |
efrain |
1580 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1581 |
$company = $companyMapper->fetchOne($feed->company_id);
|
283 |
www |
1582 |
|
247 |
efrain |
1583 |
$item['owner_url'] = $this->url()->fromRoute('company/view', ['id' => $company->uuid], ['force_canonical' => true]);
|
345 |
www |
1584 |
$item['owner_image'] = $storage->getCompanyImage($company);
|
1 |
efrain |
1585 |
$item['owner_name'] = $company->name;
|
283 |
www |
1586 |
|
1 |
efrain |
1587 |
} else if ($feed->type == Feed::TYPE_GROUP) {
|
|
|
1588 |
$groupMapper = GroupMapper::getInstance($this->adapter);
|
|
|
1589 |
$group = $groupMapper->fetchOne($feed->group_id);
|
283 |
www |
1590 |
|
|
|
1591 |
|
1 |
efrain |
1592 |
$item['owner_url'] = '';
|
345 |
www |
1593 |
$item['owner_image'] = $storage->getGroupImage($group);
|
1 |
efrain |
1594 |
$item['owner_name'] = $group->name;
|
|
|
1595 |
|
|
|
1596 |
if ($group->user_id == $currentUser->id) {
|
247 |
efrain |
1597 |
$item['feed_delete_url'] = $this->url()->fromRoute('feed/delete', $params, ['force_canonical' => true]);
|
1 |
efrain |
1598 |
}
|
|
|
1599 |
} else {
|
|
|
1600 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1601 |
$user = $userMapper->fetchOne($feed->user_id);
|
283 |
www |
1602 |
|
|
|
1603 |
|
1 |
efrain |
1604 |
$item['owner_url'] = $this->url()->fromRoute('profile/view', ['id' => $user->uuid]);
|
345 |
www |
1605 |
$item['owner_image'] = $storage->getUserImage($user);
|
1 |
efrain |
1606 |
$item['owner_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
1607 |
|
|
|
1608 |
if ($feed->user_id == $currentUser->id) {
|
247 |
efrain |
1609 |
$item['feed_delete_url'] = $this->url()->fromRoute('feed/delete', $params, ['force_canonical' => true]);
|
1 |
efrain |
1610 |
}
|
|
|
1611 |
}
|
|
|
1612 |
} else {
|
|
|
1613 |
if ($feed->user_id == $currentUser->id) {
|
247 |
efrain |
1614 |
$item['feed_delete_url'] = $this->url()->fromRoute('feed/delete', $params, ['force_canonical' => true]);
|
1 |
efrain |
1615 |
}
|
|
|
1616 |
}
|
|
|
1617 |
|
|
|
1618 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1619 |
$user = $userMapper->fetchOne($feed->user_id);
|
192 |
efrain |
1620 |
|
|
|
1621 |
|
1 |
efrain |
1622 |
|
|
|
1623 |
if ($feed->posted_or_shared == Feed::SHARED) {
|
283 |
www |
1624 |
|
192 |
efrain |
1625 |
$item['owner_url'] = $this->url()->fromRoute('profile/view', ['id' => $user->uuid],['force_canonical' => true]);
|
345 |
www |
1626 |
$item['owner_image'] = $storage->getUserImage($user);
|
1 |
efrain |
1627 |
$item['owner_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
1628 |
}
|
|
|
1629 |
|
|
|
1630 |
if($feed->file_type == Feed::FILE_TYPE_FAST_SURVEY) {
|
|
|
1631 |
$fastSurveyMapper = FastSurveyMapper:: getInstance($this->adapter);
|
|
|
1632 |
$fastSurvey = $fastSurveyMapper->fetchOne($feed->fast_survey_id);
|
|
|
1633 |
|
|
|
1634 |
$owner_description = [
|
|
|
1635 |
'question' => $fastSurvey->question,
|
|
|
1636 |
'number_of_answers' => $fastSurvey->number_of_answers,
|
|
|
1637 |
'answer1' => $fastSurvey->answer1,
|
|
|
1638 |
'answer2' => $fastSurvey->answer2,
|
|
|
1639 |
'answer3' => $fastSurvey->answer3,
|
|
|
1640 |
'answer4' => $fastSurvey->answer4,
|
|
|
1641 |
'answer5' => $fastSurvey->answer5,
|
|
|
1642 |
'result_type' => $fastSurvey->result_type,
|
|
|
1643 |
|
|
|
1644 |
];
|
|
|
1645 |
|
|
|
1646 |
if($fastSurvey->expire_on > $now) {
|
|
|
1647 |
$owner_description['active'] = $fastSurveyVote ? 0 : 1;
|
|
|
1648 |
$owner_description['time_remaining'] = Functions::getDateDiff($now, $fastSurvey->expire_on);
|
|
|
1649 |
|
|
|
1650 |
} else {
|
|
|
1651 |
|
|
|
1652 |
|
|
|
1653 |
$owner_description['active'] = 0;
|
|
|
1654 |
$owner_description['time_remaining'] = 0;
|
|
|
1655 |
}
|
|
|
1656 |
|
|
|
1657 |
if($fastSurvey->result_type == FastSurvey::RESULT_TYPE_PUBLIC && $fastSurveyVote) {
|
|
|
1658 |
$owner_description['votes1'] = $fastSurvey->votes1;
|
|
|
1659 |
$owner_description['votes2'] = $fastSurvey->votes2;
|
|
|
1660 |
$owner_description['votes3'] = $fastSurvey->votes3;
|
|
|
1661 |
$owner_description['votes4'] = $fastSurvey->votes4;
|
|
|
1662 |
$owner_description['votes5'] = $fastSurvey->votes5;
|
|
|
1663 |
}
|
|
|
1664 |
|
|
|
1665 |
|
|
|
1666 |
|
|
|
1667 |
$item['owner_description'] = $owner_description;
|
|
|
1668 |
} else {
|
|
|
1669 |
$item['owner_description'] = $feed->description;
|
|
|
1670 |
}
|
345 |
www |
1671 |
|
|
|
1672 |
|
|
|
1673 |
|
1 |
efrain |
1674 |
$item['owner_feed_type'] = $feed->type;
|
|
|
1675 |
|
|
|
1676 |
$item['owner_shared'] = $feed->total_shared;
|
|
|
1677 |
$item['owner_external_shared'] = $feed->total_external_shared;
|
|
|
1678 |
$item['owner_comments'] = $feed->total_comments;
|
|
|
1679 |
|
|
|
1680 |
|
|
|
1681 |
$item['owner_time_elapse'] = Functions::timeAgo($feed->added_on, $now);
|
|
|
1682 |
|
345 |
www |
1683 |
$path = $storage->getPathFeed();
|
|
|
1684 |
if ($feed->file_type == Storage::FILE_TYPE_IMAGE) {
|
|
|
1685 |
$item['owner_file_image'] = $storage->getGenericImage($path, $feed->uuid, $feed->file_name);
|
1 |
efrain |
1686 |
}
|
345 |
www |
1687 |
if ($feed->file_type == Storage::FILE_TYPE_DOCUMENT) {
|
|
|
1688 |
$item['owner_file_document'] = $storage->getGenericFile($path, $feed->uuid, $feed->file_name);
|
|
|
1689 |
}
|
|
|
1690 |
if ($feed->file_type == Storage::FILE_TYPE_VIDEO) {
|
283 |
www |
1691 |
|
345 |
www |
1692 |
|
|
|
1693 |
|
|
|
1694 |
$item['owner_file_image_preview'] = $item['owner_file_image'] = $storage->getGenericImage($path, $feed->uuid, $feed->file_image_preview);
|
|
|
1695 |
$item['owner_file_video'] = $storage->getGenericFile($path, $feed->uuid, $feed->file_name);
|
1 |
efrain |
1696 |
}
|
|
|
1697 |
|
|
|
1698 |
if ($feed->posted_or_shared == Feed::SHARED) {
|
|
|
1699 |
$sharedFeed = $feedMapper->fetchOneAnyStatus($feed->shared_feed_id);
|
|
|
1700 |
|
|
|
1701 |
$item['shared_description'] = $sharedFeed->description;
|
|
|
1702 |
$item['shared_time_elapse'] = Functions::timeAgo($sharedFeed->added_on, $now);
|
|
|
1703 |
|
345 |
www |
1704 |
if ($sharedFeed->file_type == Storage::FILE_TYPE_IMAGE) {
|
|
|
1705 |
$item['shared_file_image'] = $storage->getGenericImage($path, $sharedFeed->uuid, $sharedFeed->file_name);
|
1 |
efrain |
1706 |
}
|
345 |
www |
1707 |
if ($sharedFeed->file_type == Storage::FILE_TYPE_DOCUMENT) {
|
|
|
1708 |
$item['shared_file_document'] = $storage->getGenericFile($path, $sharedFeed->uuid, $sharedFeed->file_name);
|
1 |
efrain |
1709 |
}
|
345 |
www |
1710 |
if ($sharedFeed->file_type == Storage::FILE_TYPE_VIDEO) {
|
347 |
www |
1711 |
$path = $storage->getPathFeed();
|
345 |
www |
1712 |
$item['shared_file_image_preview'] = $storage->getGenericImage($path, $sharedFeed->uuid, $sharedFeed->file_image_preview);
|
|
|
1713 |
$item['shared_file_video'] = $storage->getGenericFile($path, $sharedFeed->uuid, $sharedFeed->file_name);
|
283 |
www |
1714 |
|
1 |
efrain |
1715 |
}
|
|
|
1716 |
|
|
|
1717 |
$item['shared_content_type'] = $sharedFeed->file_type ? $sharedFeed->file_type : '';
|
|
|
1718 |
|
|
|
1719 |
if ($feed->company_id) {
|
|
|
1720 |
|
|
|
1721 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1722 |
$sharedCompany = $companyMapper->fetchOne($feed->company_id);
|
283 |
www |
1723 |
|
|
|
1724 |
|
1 |
efrain |
1725 |
$item['shared_url'] = $this->url()->fromRoute('company/view', ['id' => $sharedCompany->uuid]);
|
345 |
www |
1726 |
$item['shared_image'] = $storage->getCompanyImage($sharedCompany);
|
1 |
efrain |
1727 |
$item['shared_name'] = $sharedCompany->name;
|
|
|
1728 |
} else if ($feed->group_id) {
|
|
|
1729 |
$groupMapper = GroupMapper::getInstance($this->adapter);
|
|
|
1730 |
$sharedGroup = $groupMapper->fetchOne($feed->group_id);
|
283 |
www |
1731 |
|
|
|
1732 |
|
1 |
efrain |
1733 |
$item['shared_url'] = '';
|
345 |
www |
1734 |
$item['shared_image'] = $storage->getGroupImage($sharedGroup);
|
1 |
efrain |
1735 |
$item['shared_name'] = $sharedGroup->name;
|
|
|
1736 |
} else {
|
|
|
1737 |
$sharedUser = $userMapper->fetchOne($sharedFeed->user_id);
|
283 |
www |
1738 |
|
1 |
efrain |
1739 |
$item['shared_url'] = $this->url()->fromRoute('profile/view', ['id' => $sharedUser->uuid]);
|
347 |
www |
1740 |
$item['shared_image'] = $storage->getUserImage($sharedUser);
|
1 |
efrain |
1741 |
$item['shared_name'] = $sharedUser->first_name . ' ' . $sharedUser->last_name;
|
|
|
1742 |
}
|
|
|
1743 |
}
|
|
|
1744 |
|
|
|
1745 |
|
|
|
1746 |
|
|
|
1747 |
if($feed->file_type == Feed::FILE_TYPE_FAST_SURVEY) {
|
|
|
1748 |
$item['comment_add_url'] = '';
|
|
|
1749 |
$item['comments'] = [];
|
|
|
1750 |
} else {
|
|
|
1751 |
|
283 |
www |
1752 |
$item['comment_add_url'] = $this->url()->fromRoute('feed/comment', ['id' => $feed->uuid],['force_canonical' => true]);
|
1 |
efrain |
1753 |
$item['comments'] = [];
|
|
|
1754 |
|
|
|
1755 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
192 |
efrain |
1756 |
$records = $commentMapper->fetchAllPublishedByFeedId($feed->id , $user_blocked_ids, $abuse_report_comment_ids);
|
1 |
efrain |
1757 |
|
|
|
1758 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1759 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($feed->company_id);
|
|
|
1760 |
|
|
|
1761 |
$comments = [];
|
|
|
1762 |
foreach ($records as $record) {
|
|
|
1763 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
1764 |
|
|
|
1765 |
|
|
|
1766 |
if ($user->id == $currentUser->id) {
|
283 |
www |
1767 |
$link_delete = $this->url()->fromRoute('feed/comment/delete', ['id' => $feed->uuid, 'comment' => $record->uuid],['force_canonical' => true]);
|
1 |
efrain |
1768 |
} else {
|
|
|
1769 |
$link_delete = '';
|
|
|
1770 |
}
|
283 |
www |
1771 |
|
1 |
efrain |
1772 |
array_push($comments , [
|
|
|
1773 |
'unique' => uniqid(),
|
283 |
www |
1774 |
'user_url' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid],['force_canonical' => true]),
|
1 |
efrain |
1775 |
'user_name' => $user->first_name . ' ' . $user->last_name,
|
|
|
1776 |
'company' => $owner,
|
347 |
www |
1777 |
'user_image' => $storage->getUserImage($user),
|
1 |
efrain |
1778 |
'time_elapsed' => Functions::timeAgo($record->added_on, $now),
|
|
|
1779 |
'comment' => $record->comment,
|
194 |
efrain |
1780 |
'link_abuse_report' => $user->id == $currentUser->id ? '' : $this->url()->fromRoute('helpers/abuse-report', ['type' => 'comment', 'id' => $record->uuid], ['force_canonical' => true]),
|
1 |
efrain |
1781 |
'link_delete' => $link_delete
|
|
|
1782 |
]);
|
|
|
1783 |
}
|
|
|
1784 |
|
|
|
1785 |
$item['comments'] = $comments;
|
|
|
1786 |
}
|
|
|
1787 |
|
|
|
1788 |
|
|
|
1789 |
return $item;
|
|
|
1790 |
}
|
|
|
1791 |
|
|
|
1792 |
/**
|
|
|
1793 |
*
|
|
|
1794 |
* @param int $comment_id
|
|
|
1795 |
* @return array
|
|
|
1796 |
*/
|
|
|
1797 |
private function renderComment($comment_id, $now)
|
|
|
1798 |
{
|
347 |
www |
1799 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
|
|
1800 |
|
192 |
efrain |
1801 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1802 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1803 |
|
1 |
efrain |
1804 |
$item = [];
|
|
|
1805 |
|
|
|
1806 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
1807 |
$record = $commentMapper->fetchOne($comment_id);
|
|
|
1808 |
|
|
|
1809 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
1810 |
$feed = $feedMapper->fetchOne($record->feed_id);
|
|
|
1811 |
|
|
|
1812 |
if ($record) {
|
289 |
www |
1813 |
|
283 |
www |
1814 |
|
1 |
efrain |
1815 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1816 |
|
|
|
1817 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
1818 |
|
|
|
1819 |
$item['unique'] = uniqid();
|
347 |
www |
1820 |
$item['user_image'] = $storage->getUserImage($user);
|
1 |
efrain |
1821 |
$item['user_url'] = $this->url()->fromRoute('profile', ['id' => $user->uuid]);
|
|
|
1822 |
$item['user_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
1823 |
$item['time_elapsed'] = Functions::timeAgo($record->added_on, $now);
|
|
|
1824 |
$item['comment'] = $record->comment;
|
192 |
efrain |
1825 |
$item['link_abuse_report'] = $user->id == $currentUser ? '' : $this->url()->fromRoute('helpers/abuse-report', ['type' => 'comment', 'id' => $record->uuid], ['force_canonical' => true]);
|
1 |
efrain |
1826 |
$item['link_delete'] = $this->url()->fromRoute('feed/comment/delete', ['id' => $feed->uuid, 'comment' => $record->uuid]);
|
|
|
1827 |
}
|
|
|
1828 |
return $item;
|
|
|
1829 |
}
|
|
|
1830 |
|
|
|
1831 |
/**
|
|
|
1832 |
*
|
|
|
1833 |
* @param string $path
|
|
|
1834 |
* @return boolean
|
|
|
1835 |
*/
|
|
|
1836 |
private function deletePath($path)
|
|
|
1837 |
{
|
|
|
1838 |
try {
|
|
|
1839 |
if (is_dir($path)) {
|
|
|
1840 |
if ($dh = opendir($path)) {
|
|
|
1841 |
while (($file = readdir($dh)) !== false) {
|
|
|
1842 |
if ($file == '.' || $file == '..') {
|
|
|
1843 |
continue;
|
|
|
1844 |
}
|
|
|
1845 |
unlink($path . DIRECTORY_SEPARATOR . $file);
|
|
|
1846 |
}
|
|
|
1847 |
closedir($dh);
|
|
|
1848 |
}
|
|
|
1849 |
|
|
|
1850 |
rmdir($path);
|
|
|
1851 |
}
|
|
|
1852 |
return true;
|
|
|
1853 |
} catch (\Throwable $e) {
|
|
|
1854 |
error_log($e->getTraceAsString());
|
|
|
1855 |
return false;
|
|
|
1856 |
}
|
|
|
1857 |
}
|
|
|
1858 |
|
|
|
1859 |
|
|
|
1860 |
/**
|
|
|
1861 |
*
|
|
|
1862 |
* @param Feed $feed
|
|
|
1863 |
* @return array
|
|
|
1864 |
*/
|
|
|
1865 |
private function deleteFeed($feed)
|
|
|
1866 |
{
|
|
|
1867 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
1868 |
$feed->status = Feed::STATUS_DELETED;
|
|
|
1869 |
if ($feedMapper->update($feed)) {
|
|
|
1870 |
$response = [
|
|
|
1871 |
'success' => true,
|
|
|
1872 |
'data' => 'LABEL_FEED_WAS_DELETED'
|
|
|
1873 |
];
|
|
|
1874 |
} else {
|
|
|
1875 |
$response = [
|
|
|
1876 |
'success' => false,
|
|
|
1877 |
'data' => $feedMapper->getError()
|
|
|
1878 |
];
|
|
|
1879 |
}
|
|
|
1880 |
|
|
|
1881 |
|
|
|
1882 |
/*$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
1883 |
if($commentMapper->deleteAllByFeedId($feed->id)) {
|
|
|
1884 |
if($feedMapper->delete($feed->id)) {
|
|
|
1885 |
$target_path = $this->config['leaderslinked.fullpath.feed'] . DIRECTORY_SEPARATOR . $feed->id;
|
|
|
1886 |
if(file_exists($target_path)) {
|
|
|
1887 |
$this->deletePath($target_path);
|
|
|
1888 |
}
|
|
|
1889 |
|
|
|
1890 |
$response = [
|
|
|
1891 |
'success' => true,
|
|
|
1892 |
'data' => 'LABEL_FEED_WAS_DELETED'
|
|
|
1893 |
];
|
|
|
1894 |
|
|
|
1895 |
} else {
|
|
|
1896 |
$response = [
|
|
|
1897 |
'success' => false,
|
|
|
1898 |
'data' => $feedMapper->getError()
|
|
|
1899 |
];
|
|
|
1900 |
}
|
|
|
1901 |
} else {
|
|
|
1902 |
$response = [
|
|
|
1903 |
'success' => false,
|
|
|
1904 |
'data' => $commentMapper->getError()
|
|
|
1905 |
];
|
|
|
1906 |
|
|
|
1907 |
}*/
|
|
|
1908 |
|
|
|
1909 |
return $response;
|
|
|
1910 |
}
|
|
|
1911 |
|
|
|
1912 |
|
|
|
1913 |
public function voteAction()
|
|
|
1914 |
{
|
|
|
1915 |
$id = $this->params()->fromRoute('id');
|
|
|
1916 |
|
|
|
1917 |
|
|
|
1918 |
$request = $this->getRequest();
|
|
|
1919 |
if ($request->isPost()) {
|
|
|
1920 |
|
|
|
1921 |
|
|
|
1922 |
|
|
|
1923 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1924 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1925 |
|
|
|
1926 |
|
|
|
1927 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
1928 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
1929 |
if (!$feed) {
|
|
|
1930 |
$response = [
|
|
|
1931 |
'success' => false,
|
|
|
1932 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
1933 |
];
|
|
|
1934 |
return new JsonModel($response);
|
|
|
1935 |
}
|
|
|
1936 |
|
|
|
1937 |
|
|
|
1938 |
if($feed->file_type != Feed::FILE_TYPE_FAST_SURVEY) {
|
|
|
1939 |
$response = [
|
|
|
1940 |
'success' => false,
|
|
|
1941 |
'data' => 'ERROR_FAST_SURVEY_FEED_IS_NOT_FAST_SURVEY'
|
|
|
1942 |
];
|
|
|
1943 |
return new JsonModel($response);
|
|
|
1944 |
}
|
|
|
1945 |
|
|
|
1946 |
$fastSurveyMapper = FastSurveyMapper::getInstance($this->adapter);
|
|
|
1947 |
$fastSurvey = $fastSurveyMapper->fetchOne($feed->fast_survey_id);
|
|
|
1948 |
if(!$fastSurvey) {
|
|
|
1949 |
$response = [
|
|
|
1950 |
'success' => false,
|
|
|
1951 |
'data' => 'ERROR_FAST_SURVEY_NOT_FOUND'
|
|
|
1952 |
];
|
|
|
1953 |
return new JsonModel($response);
|
|
|
1954 |
}
|
|
|
1955 |
|
|
|
1956 |
$now = $fastSurveyMapper->getDatebaseNow();
|
|
|
1957 |
if($fastSurvey->expire_on <= $now) {
|
|
|
1958 |
$response = [
|
|
|
1959 |
'success' => false,
|
|
|
1960 |
'data' => 'ERROR_FAST_SURVEY_IS_EXPIRED'
|
|
|
1961 |
];
|
|
|
1962 |
return new JsonModel($response);
|
|
|
1963 |
}
|
|
|
1964 |
|
|
|
1965 |
|
|
|
1966 |
if($fastSurvey->privacy == FastSurvey::PRIVACY_COMPANY) {
|
|
|
1967 |
|
|
|
1968 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1969 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($fastSurvey->company_id, $currentUser->id);
|
|
|
1970 |
if(!$companyUser || !in_array($companyUser->status, [CompanyUser::STATUS_ACCEPTED, CompanyUser::STATUS_ADMIN_WILL_ADD])) {
|
|
|
1971 |
$response = [
|
|
|
1972 |
'success' => false,
|
|
|
1973 |
'data' => 'ERROR_FAST_SURVEY_UNAUTHORIZED'
|
|
|
1974 |
];
|
|
|
1975 |
return new JsonModel($response);
|
|
|
1976 |
}
|
|
|
1977 |
|
|
|
1978 |
}
|
|
|
1979 |
|
|
|
1980 |
|
|
|
1981 |
|
|
|
1982 |
$vote = intval($this->params()->fromPost('vote', 0), 10);
|
|
|
1983 |
if($vote < 1 || $vote > 5 || $vote > $fastSurvey->number_of_answers) {
|
|
|
1984 |
$response = [
|
|
|
1985 |
'success' => false,
|
|
|
1986 |
'data' => 'ERROR_FAST_SURVEY_VOTE_IS_INVALID'
|
|
|
1987 |
];
|
|
|
1988 |
return new JsonModel($response);
|
|
|
1989 |
}
|
|
|
1990 |
|
|
|
1991 |
$fastSurveyVoteMapper = FastSurveyVoteMapper::getInstance($this->adapter);
|
|
|
1992 |
$fastSurveyVote = $fastSurveyVoteMapper->fetchOneByFastSurveyIdAndUserId($fastSurvey->id, $currentUser->id);
|
|
|
1993 |
if($fastSurveyVote) {
|
|
|
1994 |
$response = [
|
|
|
1995 |
'success' => false,
|
|
|
1996 |
'data' => 'ERROR_FAST_SURVEY_VOTE_IS_ALREADY_FOUND'
|
|
|
1997 |
];
|
|
|
1998 |
return new JsonModel($response);
|
|
|
1999 |
}
|
|
|
2000 |
|
|
|
2001 |
$fastSurveyVote = new FastSurveyVote();
|
|
|
2002 |
$fastSurveyVote->fast_survey_id = $fastSurvey->id;
|
|
|
2003 |
$fastSurveyVote->user_id = $currentUser->id;
|
|
|
2004 |
$fastSurveyVote->vote = $vote;
|
|
|
2005 |
|
|
|
2006 |
|
|
|
2007 |
if ($fastSurveyVoteMapper->insert($fastSurveyVote)) {
|
|
|
2008 |
|
|
|
2009 |
$response = [
|
|
|
2010 |
'success' => true,
|
|
|
2011 |
'data' => $this->renderFeed($feed->id, $now)
|
|
|
2012 |
];
|
|
|
2013 |
} else {
|
|
|
2014 |
$response = [
|
|
|
2015 |
'success' => false,
|
|
|
2016 |
'data' => $fastSurveyVoteMapper->getError()
|
|
|
2017 |
];
|
|
|
2018 |
}
|
|
|
2019 |
return new JsonModel($response);
|
|
|
2020 |
}
|
|
|
2021 |
|
|
|
2022 |
$response = [
|
|
|
2023 |
'success' => false,
|
|
|
2024 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
2025 |
];
|
|
|
2026 |
return new JsonModel($response);
|
|
|
2027 |
}
|
|
|
2028 |
}
|