Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 4632 Rev 5373
Línea 105... Línea 105...
105
                    }
105
                    }
106
                }
106
                }
107
            }
107
            }
Línea 108... Línea 108...
108
 
108
 
109
            if ($isJson) {
109
            if ($isJson) {
110
                
110
 
111
                $utilMapper = UtilMapper::getInstance($this->adapter);
111
                $utilMapper = UtilMapper::getInstance($this->adapter);
Línea 112... Línea 112...
112
                $now = $utilMapper->getDatebaseNow();
112
                $now = $utilMapper->getDatebaseNow();
113
 
113
 
114
 
114
 
115
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
115
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
Línea 116... Línea 116...
116
                $records = $notificationMapper->fetchAllByUserId($currentUser->id);
116
                $records = $notificationMapper->fetchAllByUserId($currentUser->id);
117
                
117
 
118
      
118
 
119
 
119
 
120
                $items = [];
120
                $items = [];
121
                foreach ($records as $record) {
121
                foreach ($records as $record) {
122
                    
122
 
Línea 123... Línea 123...
123
                    /*
123
                    /*
124
                    if($record->read == Notification::NO) {
124
                    if($record->read == Notification::NO) {
125
                       $notificationMapper->markAsReadById($record->id);
125
                       $notificationMapper->markAsReadById($record->id);
126
                    }*/
126
                    }*/
127
 
127
 
128
                    array_push($items, [
128
                    array_push($items, [
129
                        'message' => $record->message,
129
                        'message' => $record->message,
130
                        'link' => $record->url,
130
                        'link' => $record->url,
Línea 131... Línea 131...
131
                        'link_delete' => $this->url()->fromRoute('notifications/delete', ['id' => $record->uuid]),
131
                        'link_delete' => $this->url()->fromRoute('notifications/delete', ['id' => $record->uuid]),
132
                        'time_elapsed' => Functions::timeAgo( $record->added_on, $now),
132
                        'time_elapsed' => Functions::timeAgo($record->added_on, $now),
133
                        'time' => $record->added_on
133
                        'time' => $record->added_on
134
                    ]);
134
                    ]);
135
                }
135
                }
136
 
136
 
137
                usort($items, function ($a, $b) {
137
                usort($items, function ($a, $b) {
138
                    
-
 
139
                    if ($a['time'] == $b['time']) {
138
 
Línea 140... Línea 139...
140
                        return 0;
139
                    if ($a['time'] == $b['time']) {
141
                    } else {
140
                        return 0;
142
                        return $a['time'] < $b['time'] ? -1 : 1;
141
                    } else {
Línea 171... Línea 170...
171
                    'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
170
                    'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
172
                    'fullname' => trim($user->first_name . ' ' . $user->last_name),
171
                    'fullname' => trim($user->first_name . ' ' . $user->last_name),
173
                    'description' => empty($userProfile->description) ? '' :  trim($userProfile->description),
172
                    'description' => empty($userProfile->description) ? '' :  trim($userProfile->description),
174
                    'country' => $country,
173
                    'country' => $country,
175
                    'visits' => $visits,
174
                    'visits' => $visits,
176
                    'connections' => $connections
175
                    'connections' => $connections,
-
 
176
                    'uuid' => $user->uuid,
177
                ]);
177
                ]);
Línea 178... Línea 178...
178
 
178
 
179
                $viewModel->setTemplate('leaders-linked/notifications/index.phtml');
179
                $viewModel->setTemplate('leaders-linked/notifications/index.phtml');
180
                return $viewModel;
180
                return $viewModel;
Línea 191... Línea 191...
191
 
191
 
192
    public function unreadsAction()
192
    public function unreadsAction()
193
    {
193
    {
194
        $request = $this->getRequest();
194
        $request = $this->getRequest();
195
        if ($request->isGet()) {
195
        if ($request->isGet()) {
196
            
196
 
197
            $utilMapper = UtilMapper::getInstance($this->adapter);
197
            $utilMapper = UtilMapper::getInstance($this->adapter);
Línea 198... Línea 198...
198
            $now = $utilMapper->getDatebaseNow();
198
            $now = $utilMapper->getDatebaseNow();
199
 
199
 
Línea 229... Línea 229...
229
            $response = [
229
            $response = [
230
                'success' => true,
230
                'success' => true,
231
                'data' => [
231
                'data' => [
232
                    'notifications' =>  $items,
232
                    'notifications' =>  $items,
233
                    'total' => $total,
233
                    'total' => $total,
234
                 ],
234
                ],
235
                
235
 
236
            ];
236
            ];
237
            
-
 
238
        } else {
237
        } else {
239
            $response = [
238
            $response = [
240
                'success' => false,
239
                'success' => false,
241
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
240
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
242
            ];
241
            ];
Línea 250... Línea 249...
250
 
249
 
Línea 251... Línea 250...
251
        $request = $this->getRequest();
250
        $request = $this->getRequest();
Línea 252... Línea 251...
252
 
251
 
253
        if ($request->isPost()) {
252
        if ($request->isPost()) {
254
 
253
 
255
            
254
 
Línea 256... Línea 255...
256
            
255
 
Línea 272... Línea 271...
272
                $response = [
271
                $response = [
273
                    'success' => false,
272
                    'success' => false,
274
                    'data' => $notificationMapper->getError()
273
                    'data' => $notificationMapper->getError()
275
                ];
274
                ];
276
            }
275
            }
277
 
-
 
278
 
-
 
279
        }else{
276
        } else {
280
            $response = [
277
            $response = [
281
                'success' => false,
278
                'success' => false,
282
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
279
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
283
            ];
280
            ];
284
 
-
 
285
        }
281
        }
Línea 286... Línea 282...
286
 
282
 
287
        return new JsonModel($response);
283
        return new JsonModel($response);
288
    }
284
    }
289
    
285
 
290
    public function markReadAction()
286
    public function markReadAction()
291
    {
287
    {
292
        
288
 
293
        $request = $this->getRequest();
289
        $request = $this->getRequest();
294
        
290
 
295
        if ($request->isPost()) {
291
        if ($request->isPost()) {
296
            
292
 
297
            $uuid = $this->params()->fromRoute('id');
293
            $uuid = $this->params()->fromRoute('id');
298
            
294
 
299
            $currentUserPlugin = $this->plugin('currentUserPlugin');
295
            $currentUserPlugin = $this->plugin('currentUserPlugin');
300
            $currentUser = $currentUserPlugin->getUser();
296
            $currentUser = $currentUserPlugin->getUser();
301
            
297
 
302
            
298
 
303
            $notificationMapper = NotificationMapper::getInstance($this->adapter);
299
            $notificationMapper = NotificationMapper::getInstance($this->adapter);
304
            $notification = $notificationMapper->fetchOneByUuid($uuid);
300
            $notification = $notificationMapper->fetchOneByUuid($uuid);
305
            
301
 
306
            if(!$notification) {
302
            if (!$notification) {
307
                $response = [
303
                $response = [
308
                    'success' => false,
304
                    'success' => false,
309
                    'data' => 'ERROR_NOTIFICATION_NOT_FOUND'
305
                    'data' => 'ERROR_NOTIFICATION_NOT_FOUND'
310
                ];
306
                ];
311
                
307
 
312
                return new JsonModel($response);
-
 
313
            
308
                return new JsonModel($response);
314
            }
309
            }
315
            
310
 
316
            if($currentUser->id != $notification->user_id) {
311
            if ($currentUser->id != $notification->user_id) {
317
                $response = [
312
                $response = [
318
                    'success' => false,
313
                    'success' => false,
319
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_NOTIFICATION'
314
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_NOTIFICATION'
320
                ];
315
                ];
321
                
316
 
322
                return new JsonModel($response);
317
                return new JsonModel($response);
Línea 323... Línea 318...
323
            }
318
            }
324
 
319
 
Línea 333... Línea 328...
333
                $response = [
328
                $response = [
334
                    'success' => false,
329
                    'success' => false,
335
                    'data' => $notificationMapper->getError()
330
                    'data' => $notificationMapper->getError()
336
                ];
331
                ];
337
            }
332
            }
338
            
-
 
339
            
-
 
340
        }else{
333
        } else {
341
            $response = [
334
            $response = [
342
                'success' => false,
335
                'success' => false,
343
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
336
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
344
            ];
337
            ];
345
            
-
 
346
        }
338
        }
347
        
339
 
348
        return new JsonModel($response);
340
        return new JsonModel($response);
349
    }
341
    }
350
    
342
 
351
    public function deleteAction()
343
    public function deleteAction()
352
    {
344
    {
353
        
345
 
354
        $request = $this->getRequest();
346
        $request = $this->getRequest();
355
        
347
 
356
        if ($request->isPost()) {
348
        if ($request->isPost()) {
357
            
349
 
358
            $uuid = $this->params()->fromRoute('id');
350
            $uuid = $this->params()->fromRoute('id');
359
            
351
 
360
            $currentUserPlugin = $this->plugin('currentUserPlugin');
352
            $currentUserPlugin = $this->plugin('currentUserPlugin');
361
            $currentUser = $currentUserPlugin->getUser();
353
            $currentUser = $currentUserPlugin->getUser();
362
            
354
 
363
            
355
 
364
            $notificationMapper = NotificationMapper::getInstance($this->adapter);
356
            $notificationMapper = NotificationMapper::getInstance($this->adapter);
365
            $notification = $notificationMapper->fetchOneByUuid($uuid);
357
            $notification = $notificationMapper->fetchOneByUuid($uuid);
366
            
358
 
367
            if(!$notification) {
359
            if (!$notification) {
368
                $response = [
360
                $response = [
369
                    'success' => false,
361
                    'success' => false,
370
                    'data' => 'ERROR_NOTIFICATION_NOT_FOUND'
362
                    'data' => 'ERROR_NOTIFICATION_NOT_FOUND'
371
                ];
363
                ];
372
                
364
 
373
                return new JsonModel($response);
365
                return new JsonModel($response);
374
                
-
 
375
            }
366
            }
376
            
367
 
377
            if($currentUser->id != $notification->user_id) {
368
            if ($currentUser->id != $notification->user_id) {
378
                $response = [
369
                $response = [
379
                    'success' => false,
370
                    'success' => false,
380
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_NOTIFICATION'
371
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THIS_NOTIFICATION'
381
                ];
372
                ];
382
                
373
 
383
                return new JsonModel($response);
374
                return new JsonModel($response);
384
            }
375
            }
385
            
376
 
386
            $result = $notificationMapper->deleteById($notification->id);
377
            $result = $notificationMapper->deleteById($notification->id);
387
            if ($result) {
378
            if ($result) {
388
                $this->logger->info('Se borro una notificación del usuario: ' . $currentUser->id, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
379
                $this->logger->info('Se borro una notificación del usuario: ' . $currentUser->id, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
389
                $response = [
380
                $response = [
390
                    'success' => true,
381
                    'success' => true,
Línea 394... Línea 385...
394
                $response = [
385
                $response = [
395
                    'success' => false,
386
                    'success' => false,
396
                    'data' => $notificationMapper->getError()
387
                    'data' => $notificationMapper->getError()
397
                ];
388
                ];
398
            }
389
            }
399
            
-
 
400
            
-
 
401
        }else{
390
        } else {
402
            $response = [
391
            $response = [
403
                'success' => false,
392
                'success' => false,
404
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
393
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
405
            ];
394
            ];
406
            
-
 
407
        }
395
        }
408
        
396
 
409
        return new JsonModel($response);
397
        return new JsonModel($response);
410
    }
398
    }
411
    
399
 
412
    
400
 
413
    public function clearAction()
401
    public function clearAction()
414
    {
402
    {
415
        
403
 
416
        $request = $this->getRequest();
404
        $request = $this->getRequest();
417
        
405
 
418
        if ($request->isPost()) {
406
        if ($request->isPost()) {
419
            
407
 
420
            
408
 
421
            $currentUserPlugin = $this->plugin('currentUserPlugin');
409
            $currentUserPlugin = $this->plugin('currentUserPlugin');
422
            $currentUser = $currentUserPlugin->getUser();
410
            $currentUser = $currentUserPlugin->getUser();
423
            
411
 
424
            
412
 
425
            $notificationMapper = NotificationMapper::getInstance($this->adapter);
413
            $notificationMapper = NotificationMapper::getInstance($this->adapter);
426
           
414
 
427
            $result = $notificationMapper->deleteAllByUserId($currentUser->id);
415
            $result = $notificationMapper->deleteAllByUserId($currentUser->id);
428
            if ($result) {
416
            if ($result) {
429
                $this->logger->info('Se borraron todas las notificaciones del usuario: ' . $currentUser->id, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
417
                $this->logger->info('Se borraron todas las notificaciones del usuario: ' . $currentUser->id, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
430
                $response = [
418
                $response = [
431
                    'success' => true,
419
                    'success' => true,
Línea 435... Línea 423...
435
                $response = [
423
                $response = [
436
                    'success' => false,
424
                    'success' => false,
437
                    'data' => $notificationMapper->getError()
425
                    'data' => $notificationMapper->getError()
438
                ];
426
                ];
439
            }
427
            }
440
            
-
 
441
            
-
 
442
        }else{
428
        } else {
443
            $response = [
429
            $response = [
444
                'success' => false,
430
                'success' => false,
445
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
431
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
446
            ];
432
            ];
447
            
-
 
448
        }
433
        }
449
        
434
 
450
        return new JsonModel($response);
435
        return new JsonModel($response);
451
    }
436
    }
452
 
-
 
453
}
437
}