Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4894 | Rev 5576 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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