4808 |
efrain |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
*
|
|
|
4 |
* Controlador: Mis Perfiles
|
|
|
5 |
*
|
|
|
6 |
*/
|
|
|
7 |
declare(strict_types=1);
|
|
|
8 |
|
|
|
9 |
namespace LeadersLinked\Controller;
|
|
|
10 |
|
|
|
11 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
12 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
13 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
14 |
use Laminas\Log\LoggerInterface;
|
|
|
15 |
use Laminas\View\Model\JsonModel;
|
|
|
16 |
use Laminas\Paginator\Paginator;
|
|
|
17 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
18 |
use Laminas\View\Model\ViewModel;
|
|
|
19 |
|
|
|
20 |
use LeadersLinked\Library\Functions;
|
|
|
21 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
|
|
22 |
use LeadersLinked\Model\Post;
|
|
|
23 |
use LeadersLinked\Mapper\PostMapper;
|
|
|
24 |
use LeadersLinked\Mapper\GroupMapper;
|
|
|
25 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
26 |
use LeadersLinked\Mapper\CommentMapper;
|
|
|
27 |
use LeadersLinked\Mapper\ConnectionMapper;
|
|
|
28 |
use LeadersLinked\Mapper\CompanyFollowerMapper;
|
|
|
29 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
30 |
|
|
|
31 |
use LeadersLinked\Mapper\LikeMapper;
|
|
|
32 |
use LeadersLinked\Model\Like;
|
|
|
33 |
use LeadersLinked\Model\Comment;
|
|
|
34 |
use LeadersLinked\Model\CompanyUser;
|
|
|
35 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
36 |
use LeadersLinked\Model\Company;
|
|
|
37 |
use LeadersLinked\Model\Group;
|
|
|
38 |
use LeadersLinked\Mapper\GroupMemberMapper;
|
|
|
39 |
use LeadersLinked\Model\GroupMember;
|
|
|
40 |
use LeadersLinked\Model\Notification;
|
|
|
41 |
use LeadersLinked\Mapper\NotificationMapper;
|
|
|
42 |
use LeadersLinked\Mapper\UserNotificationSettingMapper;
|
|
|
43 |
use LeadersLinked\Mapper\EmailTemplateMapper;
|
|
|
44 |
use LeadersLinked\Model\EmailTemplate;
|
|
|
45 |
use LeadersLinked\Library\QueueEmail;
|
|
|
46 |
use LeadersLinked\Mapper\UtilMapper;
|
|
|
47 |
use LeadersLinked\Form\Post\CommentForm;
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
class PostController extends AbstractActionController
|
|
|
52 |
{
|
|
|
53 |
/**
|
|
|
54 |
*
|
|
|
55 |
* @var AdapterInterface
|
|
|
56 |
*/
|
|
|
57 |
private $adapter;
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
*
|
|
|
62 |
* @var AbstractAdapter
|
|
|
63 |
*/
|
|
|
64 |
private $cache;
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
*
|
|
|
68 |
* @var LoggerInterface
|
|
|
69 |
*/
|
|
|
70 |
private $logger;
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
*
|
|
|
75 |
* @var array
|
|
|
76 |
*/
|
|
|
77 |
private $config;
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
*
|
|
|
81 |
* @param AdapterInterface $adapter
|
|
|
82 |
* @param AbstractAdapter $cache
|
|
|
83 |
* @param LoggerInterface $logger
|
|
|
84 |
* @param array $config
|
|
|
85 |
*/
|
|
|
86 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
87 |
{
|
|
|
88 |
$this->adapter = $adapter;
|
|
|
89 |
$this->cache = $cache;
|
|
|
90 |
$this->logger = $logger;
|
|
|
91 |
$this->config = $config;
|
|
|
92 |
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
*
|
|
|
97 |
* Generación del listado de perfiles
|
|
|
98 |
* {@inheritDoc}
|
|
|
99 |
* @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
|
|
|
100 |
*/
|
|
|
101 |
public function indexAction()
|
|
|
102 |
{
|
|
|
103 |
|
|
|
104 |
return new JsonModel([
|
|
|
105 |
'success' => false,
|
|
|
106 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
107 |
]);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
public function viewAction()
|
|
|
111 |
{
|
|
|
112 |
$request = $this->getRequest();
|
|
|
113 |
if ($request->isGet()) {
|
|
|
114 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
115 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
$id = $this->params()->fromRoute('id');
|
|
|
119 |
|
|
|
120 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
121 |
$post = $postMapper->fetchOneByUuid($id);
|
|
|
122 |
|
|
|
123 |
if (!$post || $post->status != Post::STATUS_ACTIVE) {
|
|
|
124 |
$flashMessenger = $this->plugin('FlashMessenger');
|
|
|
125 |
|
|
|
126 |
if (!$id) {
|
|
|
127 |
$flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
|
|
|
128 |
return $this->redirect()->toRoute('dashboard');
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
$timestamp = time();
|
|
|
135 |
|
|
|
136 |
list($usec, $sec) = explode(' ', microtime());
|
|
|
137 |
$seed = intval($sec + ((float) $usec * 100000));
|
|
|
138 |
mt_srand($seed, MT_RAND_MT19937);
|
|
|
139 |
$rand = mt_rand();
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
$password = md5('user-' . $currentUser->uuid . '-post-' . $post->uuid . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $currentUser->share_key) ;
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
$share_params = [
|
|
|
147 |
'type' => 'post',
|
|
|
148 |
'code' => $post->uuid,
|
|
|
149 |
'user' => $currentUser->uuid,
|
|
|
150 |
'timestamp' => $timestamp,
|
|
|
151 |
'rand' => $rand,
|
|
|
152 |
'password' => $password,
|
|
|
153 |
];
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
$share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter',$share_params , ['force_canonical' => true]);
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
$share_external_url = $this->url()->fromRoute('shorter/generate', ['code' => $post->uuid, 'type' => 'post' ] , ['force_canonical' => true]);
|
|
|
161 |
|
|
|
162 |
$likeMapper = LikeMapper::getInstance($this->adapter);
|
|
|
163 |
$like = $likeMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
167 |
$viewModel = new ViewModel();
|
|
|
168 |
$viewModel->setTemplate('leaders-linked/post/view.phtml');
|
|
|
169 |
$viewModel->setVariables([
|
|
|
170 |
'post' => $post,
|
|
|
171 |
'id' => $post->id,
|
|
|
172 |
'uuid' => $post->uuid,
|
|
|
173 |
'title' => $post->title,
|
|
|
174 |
'description' => $post->description,
|
|
|
175 |
'url' => $post->url,
|
|
|
176 |
'date' => $post->date,
|
|
|
177 |
'status' => $post->status,
|
|
|
178 |
'image' => $post->image,
|
|
|
179 |
'file' => $post->file,
|
|
|
180 |
'added_on' => $post->added_on,
|
|
|
181 |
'share_external_url' => $share_external_url,
|
|
|
182 |
'total_share_external' => $post->total_external_shared,
|
|
|
183 |
'share_increment_external_counter_url' => $share_increment_external_counter_url,
|
|
|
184 |
'comments_url' => $this->url()->fromRoute('post/comments', ['id' => $post->uuid]),
|
|
|
185 |
'comments_add_url' => $this->url()->fromRoute('post/comments/add', ['id' => $post->uuid]),
|
|
|
186 |
'is_liked' => $like ? 1 : 0,
|
|
|
187 |
'like_url' => $this->url()->fromRoute('post/like', ['id' => $post->uuid]),
|
|
|
188 |
'unlike_url' => $this->url()->fromRoute('post/unlike', ['id' => $post->uuid]),
|
|
|
189 |
|
|
|
190 |
]);
|
|
|
191 |
return $viewModel;
|
|
|
192 |
|
|
|
193 |
} else {
|
|
|
194 |
$response = [
|
|
|
195 |
'success' => false,
|
|
|
196 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
197 |
];
|
|
|
198 |
|
|
|
199 |
return new JsonModel($response);
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public function commentsAddAction()
|
|
|
204 |
{
|
|
|
205 |
$id = $this->params()->fromRoute('id');
|
|
|
206 |
|
|
|
207 |
$request = $this->getRequest();
|
|
|
208 |
if($request->isPost()) {
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
213 |
$post = $postMapper->fetchOneByUuid($id);
|
|
|
214 |
if(!$post) {
|
|
|
215 |
$response = [
|
|
|
216 |
'success' => false,
|
|
|
217 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
218 |
];
|
|
|
219 |
return new JsonModel($response);
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
$dataPost = $request->getPost()->toArray();
|
|
|
223 |
$form = new CommentForm();
|
|
|
224 |
$form->setData($dataPost);
|
|
|
225 |
|
|
|
226 |
if($form->isValid()) {
|
|
|
227 |
$utilMapper = UtilMapper::getInstance($this->adapter);
|
|
|
228 |
$now = $utilMapper->getDatebaseNow();
|
|
|
229 |
|
|
|
230 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
231 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
232 |
|
|
|
233 |
$dataPost = (array) $form->getData();
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
$comment = new Comment();
|
|
|
238 |
$comment->network_id = $currentUser->network_id;
|
|
|
239 |
$comment->comment = $dataPost['comment'];
|
|
|
240 |
$comment->user_id = $currentUser->id;
|
|
|
241 |
$comment->post_id = $post->id;
|
|
|
242 |
$comment->relational = Comment::RELATIONAL_POST;
|
|
|
243 |
|
|
|
244 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
245 |
if($commentMapper->insert($comment)) {
|
|
|
246 |
|
|
|
247 |
$total_comments = $commentMapper->fetchCountCommentByPostId($comment->post_id);
|
|
|
248 |
|
|
|
249 |
$post->total_comments = $total_comments;
|
|
|
250 |
$postMapper->update($post);
|
|
|
251 |
|
|
|
252 |
$response = [
|
|
|
253 |
'success' => true,
|
|
|
254 |
'data' => $this->renderComment($comment->id, $now),
|
|
|
255 |
'total_comments' => $total_comments
|
|
|
256 |
];
|
|
|
257 |
|
|
|
258 |
return new JsonModel($response);
|
|
|
259 |
|
|
|
260 |
} else {
|
|
|
261 |
|
|
|
262 |
$response = [
|
|
|
263 |
'success' => false,
|
|
|
264 |
'data' => $commentMapper->getError()
|
|
|
265 |
];
|
|
|
266 |
|
|
|
267 |
return new JsonModel($response);
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
} else {
|
|
|
271 |
$message = '';;
|
|
|
272 |
$form_messages = (array) $form->getMessages();
|
|
|
273 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
274 |
{
|
|
|
275 |
foreach( $field_messages as $key => $value)
|
|
|
276 |
{
|
|
|
277 |
$message = $value;
|
|
|
278 |
}
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
$response = [
|
|
|
282 |
'success' => false,
|
|
|
283 |
'data' => $message
|
|
|
284 |
];
|
|
|
285 |
|
|
|
286 |
return new JsonModel($response);
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
|
|
|
290 |
} else {
|
|
|
291 |
$response = [
|
|
|
292 |
'success' => false,
|
|
|
293 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
294 |
];
|
|
|
295 |
|
|
|
296 |
return new JsonModel($response);
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
public function commentsDeleteAction()
|
|
|
305 |
{
|
|
|
306 |
$request = $this->getRequest();
|
|
|
307 |
if($request->isPost()) {
|
|
|
308 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
309 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
310 |
|
|
|
311 |
$post_id = $this->params()->fromRoute('id');
|
|
|
312 |
$comment = $this->params()->fromRoute('comment');
|
|
|
313 |
|
|
|
314 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
315 |
$post = $postMapper->fetchOneByUuidAndNetworkId($post_id, $currentUser->network_id);
|
|
|
316 |
|
|
|
317 |
if($post) {
|
|
|
318 |
|
|
|
319 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
320 |
$comment = $commentMapper->fetchOneByUuid($comment);
|
|
|
321 |
|
|
|
322 |
if($comment && $comment->post_id == $post->id && $comment->user_id == $currentUser->id) {
|
|
|
323 |
|
|
|
324 |
$comment->status = Comment::STATUS_DELETED;
|
|
|
325 |
|
|
|
326 |
if($commentMapper->update($comment)) {
|
|
|
327 |
|
|
|
328 |
$total_comments = $commentMapper->fetchCountCommentByPostId($comment->post_id);
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
332 |
$post = $postMapper->fetchOne($comment->post_id);
|
|
|
333 |
$post->total_comments = $total_comments;
|
|
|
334 |
$postMapper->update($post);
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
|
340 |
$response = [
|
|
|
341 |
'success' => true,
|
|
|
342 |
'data' => 'LABEL_COMMENT_WAS_DELETED',
|
|
|
343 |
'total_comments' => $total_comments
|
|
|
344 |
];
|
|
|
345 |
|
|
|
346 |
} else {
|
|
|
347 |
$response = [
|
|
|
348 |
'success' => false,
|
|
|
349 |
'data' => $commentMapper->getError()
|
|
|
350 |
];
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
} else {
|
|
|
354 |
$response = [
|
|
|
355 |
'success' => false,
|
|
|
356 |
'data' => 'ERROR_COMMENT_NOT_FOUND'
|
|
|
357 |
];
|
|
|
358 |
}
|
|
|
359 |
} else {
|
|
|
360 |
$response = [
|
|
|
361 |
'success' => false,
|
|
|
362 |
'data' => 'ERROR_COMMENT_NOT_FOUND'
|
|
|
363 |
];
|
|
|
364 |
}
|
|
|
365 |
} else {
|
|
|
366 |
$response = [
|
|
|
367 |
'success' => false,
|
|
|
368 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
369 |
];
|
|
|
370 |
}
|
|
|
371 |
|
|
|
372 |
return new JsonModel($response);
|
|
|
373 |
}
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
public function likeAction()
|
|
|
379 |
{
|
|
|
380 |
$id = $this->params()->fromRoute('id');
|
|
|
381 |
|
|
|
382 |
$request = $this->getRequest();
|
|
|
383 |
if($request->isPost()) {
|
|
|
384 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
385 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
386 |
|
|
|
387 |
|
|
|
388 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
389 |
$post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
390 |
if(!$post) {
|
|
|
391 |
$response = [
|
|
|
392 |
'success' => false,
|
|
|
393 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
394 |
];
|
|
|
395 |
return new JsonModel($response);
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
$likeMapper = LikeMapper::getInstance($this->adapter);
|
|
|
399 |
$like = $likeMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
|
|
|
400 |
|
|
|
401 |
if($like) {
|
|
|
402 |
$response = [
|
|
|
403 |
'success' => false,
|
|
|
404 |
'data' => 'ERROR_DUPLICATE_ACTION'
|
|
|
405 |
];
|
|
|
406 |
return new JsonModel($response);
|
|
|
407 |
}
|
|
|
408 |
|
|
|
409 |
$like = new Like();
|
|
|
410 |
$like->user_id = $currentUser->id;
|
|
|
411 |
$like->post_id = $post->id;
|
|
|
412 |
$like->relational = Like::RELATIONAL_POST;
|
|
|
413 |
|
|
|
414 |
if($likeMapper->insert($like))
|
|
|
415 |
{
|
|
|
416 |
|
|
|
417 |
$likes = $likeMapper->fetchCountLikeByPostId($post->id);
|
|
|
418 |
$response = [
|
|
|
419 |
'success' => true,
|
|
|
420 |
'data' => [
|
|
|
421 |
'likes' => $likes
|
|
|
422 |
]
|
|
|
423 |
];
|
|
|
424 |
} else {
|
|
|
425 |
$response = [
|
|
|
426 |
'success' => false,
|
|
|
427 |
'data' => $likeMapper->getError()
|
|
|
428 |
];
|
|
|
429 |
}
|
|
|
430 |
return new JsonModel($response);
|
|
|
431 |
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
$response = [
|
|
|
435 |
'success' => false,
|
|
|
436 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
437 |
];
|
|
|
438 |
return new JsonModel($response);
|
|
|
439 |
}
|
|
|
440 |
|
|
|
441 |
public function unlikeAction()
|
|
|
442 |
{
|
|
|
443 |
$id = $this->params()->fromRoute('id');
|
|
|
444 |
|
|
|
445 |
$request = $this->getRequest();
|
|
|
446 |
if($request->isPost()) {
|
|
|
447 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
448 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
449 |
|
|
|
450 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
451 |
$post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
|
|
452 |
if(!$post) {
|
|
|
453 |
$response = [
|
|
|
454 |
'success' => false,
|
|
|
455 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
456 |
];
|
|
|
457 |
return new JsonModel($response);
|
|
|
458 |
}
|
|
|
459 |
|
|
|
460 |
$likeMapper = LikeMapper::getInstance($this->adapter);
|
|
|
461 |
$like = $likeMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
|
|
|
462 |
|
|
|
463 |
if(!$like) {
|
|
|
464 |
$response = [
|
|
|
465 |
'success' => false,
|
|
|
466 |
'data' => 'ERROR_DUPLICATE_ACTION'
|
|
|
467 |
];
|
|
|
468 |
return new JsonModel($response);
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
if($likeMapper->deleteByPostIdAndUserId($post->id, $currentUser->id))
|
|
|
472 |
{
|
|
|
473 |
$likes = $likeMapper->fetchCountLikeByPostId($post->id);
|
|
|
474 |
|
|
|
475 |
|
|
|
476 |
$response = [
|
|
|
477 |
'success' => true,
|
|
|
478 |
'data' => [
|
|
|
479 |
'likes' => $likes
|
|
|
480 |
]
|
|
|
481 |
];
|
|
|
482 |
} else {
|
|
|
483 |
$response = [
|
|
|
484 |
'success' => false,
|
|
|
485 |
'data' => $likeMapper->getError()
|
|
|
486 |
];
|
|
|
487 |
}
|
|
|
488 |
return new JsonModel($response);
|
|
|
489 |
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
$response = [
|
|
|
493 |
'success' => false,
|
|
|
494 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
495 |
];
|
|
|
496 |
return new JsonModel($response);
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
public function commentsAction()
|
|
|
500 |
{
|
|
|
501 |
$id = $this->params()->fromRoute('id');
|
|
|
502 |
|
|
|
503 |
$request = $this->getRequest();
|
|
|
504 |
if($request->isGet()) {
|
|
|
505 |
$utilMapper = UtilMapper::getInstance($this->adapter);
|
|
|
506 |
$now = $utilMapper->getDatebaseNow();
|
|
|
507 |
|
|
|
508 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
509 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
510 |
|
|
|
511 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
512 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
513 |
|
|
|
514 |
|
|
|
515 |
$id = $this->params()->fromRoute('id');
|
|
|
516 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
517 |
$post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentNetwork->id);
|
|
|
518 |
if(!$post) {
|
|
|
519 |
$data = [
|
|
|
520 |
'success' => false,
|
|
|
521 |
'data' => 'ERROR_UNAUTHORIZED',
|
|
|
522 |
];
|
|
|
523 |
|
|
|
524 |
return new JsonModel($data);
|
|
|
525 |
|
|
|
526 |
}
|
|
|
527 |
|
|
|
528 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
529 |
$records = $commentMapper->fetchAllPublishedByPostId($post->id);
|
|
|
530 |
|
|
|
531 |
$comments = [];
|
|
|
532 |
foreach($records as $record)
|
|
|
533 |
{
|
|
|
534 |
$comment = $this->renderComment($record->id, $now);
|
|
|
535 |
array_push($comments, $comment);
|
|
|
536 |
}
|
|
|
537 |
|
|
|
538 |
$response = [
|
|
|
539 |
'success' => true,
|
|
|
540 |
'data' => $comments
|
|
|
541 |
];
|
|
|
542 |
|
|
|
543 |
return new JsonModel($response);
|
|
|
544 |
} else {
|
|
|
545 |
|
|
|
546 |
|
|
|
547 |
|
|
|
548 |
$response = [
|
|
|
549 |
'success' => false,
|
|
|
550 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
551 |
];
|
|
|
552 |
|
|
|
553 |
|
|
|
554 |
return new JsonModel($response);
|
|
|
555 |
}
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
|
|
|
559 |
|
|
|
560 |
/**
|
|
|
561 |
*
|
|
|
562 |
* @param int $comment_id
|
|
|
563 |
* @return array
|
|
|
564 |
*/
|
|
|
565 |
private function renderComment($comment_id, $now)
|
|
|
566 |
{
|
|
|
567 |
$item = [];
|
|
|
568 |
|
|
|
569 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
570 |
$record = $commentMapper->fetchOne($comment_id);
|
|
|
571 |
|
|
|
572 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
573 |
$post = $postMapper->fetchOne($record->post_id);
|
|
|
574 |
|
|
|
575 |
if($record) {
|
|
|
576 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
577 |
|
|
|
578 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
579 |
|
|
|
580 |
$item['unique'] = uniqid();
|
|
|
581 |
$item['user_image'] = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image ]);
|
4894 |
stevensc |
582 |
$item['user_url'] = $this->url()->fromRoute('profile/view', ['id' => $user->uuid]);
|
4808 |
efrain |
583 |
$item['user_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
584 |
$item['time_elapsed'] = Functions::timeAgo($record->added_on, $now);
|
|
|
585 |
$item['comment'] = $record->comment;
|
|
|
586 |
$item['link_delete'] = $this->url()->fromRoute('post/comments/delete',['id' => $post->uuid, 'comment' => $record->uuid ]);
|
|
|
587 |
}
|
|
|
588 |
return $item;
|
|
|
589 |
}
|
|
|
590 |
|
|
|
591 |
|
|
|
592 |
|
|
|
593 |
|
|
|
594 |
|
|
|
595 |
|
|
|
596 |
}
|