Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 3138 Rev 3262
Línea 212... Línea 212...
212
        }
212
        }
Línea 213... Línea 213...
213
 
213
 
214
        return new JsonModel($response);
214
        return new JsonModel($response);
Línea 215... Línea -...
215
    }
-
 
216
 
-
 
217
    public function notificationsAction()
-
 
218
    {
-
 
219
        $request = $this->getRequest();
-
 
220
        if ($request->isGet()) {
-
 
221
 
-
 
222
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
223
            $currentUser = $currentUserPlugin->getUser();
-
 
224
 
-
 
225
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
226
            $user = $userMapper->fetchOne($currentUser->id);
-
 
227
 
-
 
228
            $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
-
 
229
            $userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
-
 
230
 
-
 
231
            $headers  = $request->getHeaders();
-
 
232
 
-
 
233
            $isJson = false;
-
 
234
            if ($headers->has('Accept')) {
-
 
235
                $accept = $headers->get('Accept');
-
 
236
 
-
 
237
                $prioritized = $accept->getPrioritized();
-
 
238
 
-
 
239
                foreach ($prioritized as $key => $value) {
-
 
240
                    $raw = trim($value->getRaw());
-
 
241
 
-
 
242
                    if (!$isJson) {
-
 
243
                        $isJson = strpos($raw, 'json');
-
 
244
                    }
-
 
245
                }
-
 
246
            }
-
 
247
 
-
 
248
            if ($isJson) {
-
 
249
                
-
 
250
                $utilMapper = UtilMapper::getInstance($this->adapter);
-
 
251
                $now = $utilMapper->getDatebaseNow();
-
 
252
 
-
 
253
 
-
 
254
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
-
 
255
                $records = $notificationMapper->fetchAllsReadByUserId($currentUser->id);
-
 
256
 
-
 
257
                $items = [];
-
 
258
                foreach ($records as $record) {
-
 
259
 
-
 
260
                    array_push($items, [
-
 
261
                        'message' => $record->message,
-
 
262
                        'link' => $record->url,
-
 
263
                        'time_elapsed' => Functions::timeAgo( $record->added_on, $now),
-
 
264
                        'time' => $record->added_on
-
 
265
                    ]);
-
 
266
                }
-
 
267
 
-
 
268
                usort($items, function ($a, $b) {
-
 
269
                    
-
 
270
                    if ($a['time'] == $b['time']) {
-
 
271
                        return 0;
-
 
272
                    } else {
-
 
273
                        return $a['time'] < $b['time'] ? -1 : 1;
-
 
274
                    }
-
 
275
                
-
 
276
                });
-
 
277
 
-
 
278
                $response = [
-
 
279
                    'success' => true,
-
 
280
                    'data' => $items
-
 
281
                ];
-
 
282
            } else {
-
 
283
 
-
 
284
                if ($user->location_id) {
-
 
285
                    $locationMapper = LocationMapper::getInstance($this->adapter);
-
 
286
                    $location = $locationMapper->fetchOne($user->location_id);
-
 
287
 
-
 
288
                    $country = $location->country;
-
 
289
                } else {
-
 
290
                    $country = '';
-
 
291
                }
-
 
292
 
-
 
293
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
-
 
294
                $visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
-
 
295
 
-
 
296
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
-
 
297
                $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
-
 
298
 
-
 
299
                $this->layout()->setTemplate('layout/layout.phtml');
-
 
300
                $viewModel = new ViewModel();
-
 
301
                $viewModel->setVariables([
-
 
302
                    'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
-
 
303
                    'fullname' => trim($user->first_name . ' ' . $user->last_name),
-
 
304
                    'description' => empty($userProfile->description) ? '' :  trim($userProfile->description),
-
 
305
                    'country' => $country,
-
 
306
                    'visits' => $visits,
-
 
307
                    'connections' => $connections
-
 
308
                ]);
-
 
309
 
-
 
310
                $viewModel->setTemplate('leaders-linked/home/notifications.phtml');
-
 
311
                return $viewModel;
-
 
312
            }
-
 
313
        } else {
-
 
314
            $response = [
-
 
315
                'success' => false,
-
 
316
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
317
            ];
-
 
318
        }
-
 
319
 
-
 
320
        return new JsonModel($response);
-
 
321
    }
-
 
322
 
-
 
323
    public function lastNotificationsAction()
-
 
324
    {
-
 
325
        $request = $this->getRequest();
-
 
326
        if ($request->isGet()) {
-
 
327
            
-
 
328
            $utilMapper = UtilMapper::getInstance($this->adapter);
-
 
329
            $now = $utilMapper->getDatebaseNow();
-
 
330
 
-
 
331
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
332
            $currentUser = $currentUserPlugin->getUser();
-
 
333
 
-
 
334
            $notificationMapper = NotificationMapper::getInstance($this->adapter);
-
 
335
            $records = $notificationMapper->fetchAllsUnreadByUserId($currentUser->id);
-
 
336
 
-
 
337
            $items = [];
-
 
338
            foreach ($records as $record) {
-
 
339
                array_push($items, [
-
 
340
                    'message' => $record->message,
-
 
341
                    'link' => $record->url,
-
 
342
                    'time_elapsed' => Functions::timeAgo($record->added_on, $now),
-
 
343
                    'time' => $record->added_on
-
 
344
                ]);
-
 
345
            }
-
 
346
 
-
 
347
            usort($items, function ($a, $b) {
-
 
348
 
-
 
349
                if ($a['time'] == $b['time']) {
-
 
350
                    return 0;
-
 
351
                } else {
-
 
352
                    return $a['time'] < $b['time'] ? -1 : 1;
-
 
353
                }
-
 
354
            });
-
 
355
 
-
 
356
            $count = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
-
 
357
 
-
 
358
            $response = [
-
 
359
                'success' => true,
-
 
360
                'data' => $items,
-
 
361
                'unreadNotificationsCount' => $count
215
    }
362
            ];
-
 
363
            
-
 
364
        } else {
-
 
365
            $response = [
-
 
366
                'success' => false,
-
 
367
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
368
            ];
-
 
369
        }
-
 
370
 
-
 
371
        return new JsonModel($response);
-
 
372
    }
-
 
373
 
-
 
374
    public function markReadAction()
-
 
375
    {
-
 
376
 
-
 
377
        $request = $this->getRequest();
-
 
378
 
-
 
379
        if ($request->isPost()) {
-
 
380
 
-
 
381
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
382
            $currentUser = $currentUserPlugin->getUser();
-
 
383
 
-
 
384
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
385
 
-
 
386
            $notificationMapper = NotificationMapper::getInstance($this->adapter);
-
 
387
 
-
 
388
            $result = $notificationMapper->markAllNotificationsAsReadByUserId($currentUser->id);
-
 
389
 
-
 
390
            if ($result) {
-
 
391
                $this->logger->info('Se marco como leidas las notificaciones de usuario: ' . $currentUser->id, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
392
                $response = [
-
 
393
                    'success' => true,
-
 
394
                    'data' => 'LABEL_RECORD_UPDATED'
-
 
395
                ];
-
 
396
            } else {
-
 
397
                $response = [
-
 
398
                    'success' => false,
-
 
399
                    'data' => $notificationMapper->getError()
-
 
400
                ];
-
 
401
            }
-
 
402
 
-
 
403
 
-
 
404
        }else{
-
 
405
            $response = [
-
 
406
                'success' => false,
-
 
407
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
408
            ];
-
 
409
 
-
 
410
        }
-
 
411
 
-
 
412
        return new JsonModel($response);
-
 
413
    }
216
 
414
 
217
   
415
    public function postAction()
218
    public function postAction()
Línea 416... Línea 219...
416
    {
219
    {