Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 2959 Rev 2960
Línea 315... Línea 315...
315
        }
315
        }
Línea 316... Línea 316...
316
 
316
 
317
        return new JsonModel($response);
317
        return new JsonModel($response);
Línea -... Línea 318...
-
 
318
    }
-
 
319
 
-
 
320
    public function lastNotificationsAction()
-
 
321
    {
-
 
322
        $request = $this->getRequest();
-
 
323
        if ($request->isGet()) {
-
 
324
 
-
 
325
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
326
            $currentUser = $currentUserPlugin->getUser();
-
 
327
 
-
 
328
            $notificationMapper = NotificationMapper::getInstance($this->adapter);
-
 
329
            $records = $notificationMapper->fetchAllsUnreadByUserId($currentUser->id);
-
 
330
 
-
 
331
            $items = [];
-
 
332
            foreach ($records as $record) {
-
 
333
                $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
-
 
334
 
-
 
335
                array_push($items, [
-
 
336
                    'message' => $record->message,
-
 
337
                    'link' => $record->url,
-
 
338
                    'time_elapsed' => Functions::timeElapsedString($dt->getTimestamp()),
-
 
339
                    'time' => $dt->getTimestamp()
-
 
340
                ]);
-
 
341
            }
-
 
342
 
-
 
343
            usort($items, function ($a, $b) {
-
 
344
 
-
 
345
                if ($a['time'] == $b['time']) {
-
 
346
                    return 0;
-
 
347
                } else {
-
 
348
                    return $a['time'] < $b['time'] ? -1 : 1;
-
 
349
                }
-
 
350
            });
-
 
351
 
-
 
352
            $count = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
-
 
353
 
-
 
354
            $response = [
-
 
355
                'success' => true,
-
 
356
                'data' => $items,
-
 
357
                'unreadNotificationsCount' => $count
-
 
358
            ];
-
 
359
            
-
 
360
        } else {
-
 
361
            $response = [
-
 
362
                'success' => false,
-
 
363
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
364
            ];
-
 
365
        }
-
 
366
 
Línea 318... Línea 367...
318
    }
367
        return new JsonModel($response);
319
 
368
    }
Línea 320... Línea 369...
320
 
369