Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 676 Rev 677
Línea 130... Línea 130...
130
                'success' => false,
130
                'success' => false,
131
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
131
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
132
            ]);
132
            ]);
133
        }
133
        }
Línea 134... Línea -...
134
 
-
 
135
        // ========================================
-
 
136
        // INICIALIZACIÓN Y OBTENCIÓN DE DATOS BÁSICOS
-
 
137
        // ========================================
-
 
138
        
134
 
139
        // Obtener el usuario actual autenticado
135
        // Obtener el usuario actual autenticado
140
        $currentUserPlugin = $this->plugin('currentUserPlugin');
136
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 141... Línea 137...
141
        $currentUser = $currentUserPlugin->getUser();
137
        $currentUser = $currentUserPlugin->getUser();
142
 
138
 
143
        // Obtener la fecha actual de la base de datos para cálculos de tiempo
139
        // Obtener la fecha actual de la base de datos para cálculos de tiempo
Línea 144... Línea -...
144
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
145
        $now = $userMapper->getDatebaseNow();
-
 
146
 
-
 
147
        // ========================================
-
 
148
        // OBTENCIÓN DE USUARIOS BLOQUEADOS
140
        $userMapper = UserMapper::getInstance($this->adapter);
149
        // ========================================
141
        $now = $userMapper->getDatebaseNow();
150
        
142
 
Línea 151... Línea 143...
151
        // Obtener IDs de usuarios que el usuario actual ha bloqueado
143
        // Obtener IDs de usuarios que el usuario actual ha bloqueado
152
        $userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
144
        $userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
Línea 153... Línea -...
153
        $user_blocked_ids = $userBlockedMapper->fetchAllBlockedReturnIds($currentUser->id);
-
 
154
 
-
 
155
        // Obtener IDs de usuarios que han bloqueado al usuario actual
-
 
156
        $user_blocked_me_ids = $userBlockedMapper->fetchAllUserBlockMeReturnIds($currentUser->id);
-
 
157
 
145
        $user_blocked_ids = $userBlockedMapper->fetchAllBlockedReturnIds($currentUser->id);
158
        // ========================================
146
 
159
        // INICIALIZACIÓN DE MAPPER Y VARIABLES
147
        // Obtener IDs de usuarios que han bloqueado al usuario actual
160
        // ========================================
148
        $user_blocked_me_ids = $userBlockedMapper->fetchAllUserBlockMeReturnIds($currentUser->id);
Línea 161... Línea -...
161
        
-
 
162
        $conversationMapper = ConversationMapper::getInstance($this->adapter);
-
 
163
        $messageMapper = MessageMapper::getInstance($this->adapter);
-
 
164
        $conversations = [];
-
 
165
        $selected_user_id = 0;
149
 
166
 
150
        $conversationMapper = ConversationMapper::getInstance($this->adapter);
167
        // ========================================
-
 
168
        // PROCESAMIENTO DE USUARIO/EMPRESA SELECCIONADO
-
 
169
        // ========================================
-
 
170
        
-
 
171
        $id = $this->params()->fromRoute('id');
151
        $messageMapper = MessageMapper::getInstance($this->adapter);
172
        if ($id) {
152
        $conversations = [];
Línea 173... Línea 153...
173
            // ========================================
153
        $selected_user_id = 0;
174
            // BÚSQUEDA COMO EMPRESA PRIMERO
154
 
Línea 221... Línea 201...
221
                            'filename' => $company->image
201
                            'filename' => $company->image
222
                        ], ['force_canonical' => true]),
202
                        ], ['force_canonical' => true]),
223
                        'profile' => $this->url()->fromRoute('company/view', ['id' => $company->uuid]),
203
                        'profile' => $this->url()->fromRoute('company/view', ['id' => $company->uuid]),
224
                        'last_message' => $timeElapsedString,
204
                        'last_message' => $timeElapsedString,
225
                        'count_unread' => $unread,
205
                        'count_unread' => $unread,
226
                        'messages_link' => $this->url()->fromRoute('inmail/messages', ['id' => $company->uuid]),
206
                        'messages_link' => $this->url()->fromRoute('inmail/messages/get-messages', ['id' => $company->uuid]),
227
                        'send_link' => $this->url()->fromRoute('inmail/messages/send', ['id' => $company->uuid]),
207
                        'send_link' => $this->url()->fromRoute('inmail/messages/send', ['id' => $company->uuid]),
228
                        'selected' => 1, // Marcar como seleccionado
208
                        'selected' => 1, // Marcar como seleccionado
229
                        'delete_link' => $this->url()->fromRoute('inmail/messages/delete', ['id' => $company->uuid]),
209
                        'delete_link' => $this->url()->fromRoute('inmail/messages/delete', ['id' => $company->uuid]),
230
                    ]);
210
                    ]);
231
                }
211
                }
232
            } 
212
            } 
233
            // ========================================
-
 
234
            // BÚSQUEDA COMO USUARIO INDIVIDUAL
-
 
235
            // ========================================
-
 
236
            else {
213
            else {
237
                $user = $userMapper->fetchOneByUuid($id);
214
                $user = $userMapper->fetchOneByUuid($id);
238
                if ($user) {
215
                if ($user) {
239
                    // Verificar que no haya bloqueos entre usuarios
216
                    // Verificar que no haya bloqueos entre usuarios
240
                    if (!in_array($user->id, $user_blocked_ids) && 
217
                    if (!in_array($user->id, $user_blocked_ids) && 
Línea 273... Línea 250...
273
                                'filename' => $user->image
250
                                'filename' => $user->image
274
                            ], ['force_canonical' => true]),
251
                            ], ['force_canonical' => true]),
275
                            'profile' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
252
                            'profile' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
276
                            'last_message' => $timeElapsedString,
253
                            'last_message' => $timeElapsedString,
277
                            'count_unread' => $unread,
254
                            'count_unread' => $unread,
278
                            'messages_link' => $this->url()->fromRoute('inmail/messages', ['id' => $user->uuid]),
255
                            'messages_link' => $this->url()->fromRoute('inmail/messages/get-messages', ['id' => $user->uuid]),
279
                            'send_link' => $this->url()->fromRoute('inmail/messages/send', ['id' => $user->uuid]),
256
                            'send_link' => $this->url()->fromRoute('inmail/messages/send', ['id' => $user->uuid]),
280
                            'selected' => 1, // Marcar como seleccionado
257
                            'selected' => 1, // Marcar como seleccionado
281
                            'delete_link' => $this->url()->fromRoute('inmail/messages/delete', ['id' => $user->uuid]),
258
                            'delete_link' => $this->url()->fromRoute('inmail/messages/delete', ['id' => $user->uuid]),
282
                        ]);
259
                        ]);
283
                    }
260
                    }
Línea 296... Línea 273...
296
                if ($record->receiver_id == $currentUser->id && $record->sender_id == $selected_user_id) {
273
                if ($record->receiver_id == $currentUser->id && $record->sender_id == $selected_user_id) {
297
                    continue;
274
                    continue;
298
                }
275
                }
299
            }
276
            }
Línea 300... Línea -...
300
 
-
 
301
            // ========================================
-
 
302
            // DETERMINACIÓN DEL OTRO USUARIO EN LA CONVERSACIÓN
-
 
303
            // ========================================
-
 
304
            
277
 
305
            if ($record->sender_id == $currentUser->id) {
278
            if ($record->sender_id == $currentUser->id) {
306
                $user = $userMapper->fetchOne($record->receiver_id);
279
                $user = $userMapper->fetchOne($record->receiver_id);
307
            }
280
            }
308
            if ($record->receiver_id == $currentUser->id) {
281
            if ($record->receiver_id == $currentUser->id) {
Línea 312... Línea 285...
312
                if (in_array($user->id, $user_blocked_ids) || in_array($user->id, $user_blocked_me_ids)) {
285
                if (in_array($user->id, $user_blocked_ids) || in_array($user->id, $user_blocked_me_ids)) {
313
                    continue;
286
                    continue;
314
                }
287
                }
315
            }
288
            }
Línea 316... Línea -...
316
 
-
 
317
            // ========================================
-
 
318
            // CÁLCULO DE TIEMPO Y MENSAJES NO LEÍDOS
-
 
319
            // ========================================
-
 
320
            
289
 
321
            $timeElapsedString = '';
290
            $timeElapsedString = '';
322
            $unread = $messageMapper->fetchCountUnreadMessagesByConversationIdAndReceiverId(
291
            $unread = $messageMapper->fetchCountUnreadMessagesByConversationIdAndReceiverId(
323
                $record->id, 
292
                $record->id, 
324
                $currentUser->id
293
                $currentUser->id
Línea 330... Línea 299...
330
 
299
 
331
            if ($lastMessage) {
300
            if ($lastMessage) {
332
                $timeElapsedString = $this->timeAgo($lastMessage, $now);
301
                $timeElapsedString = $this->timeAgo($lastMessage, $now);
Línea 333... Línea -...
333
            }
-
 
334
 
-
 
335
            // ========================================
-
 
336
            // AGREGAR CONVERSACIÓN A LA LISTA
-
 
337
            // ========================================
302
            }
338
            
303
 
339
            array_push($conversations, [
304
            array_push($conversations, [
340
                'uuid' => $user->uuid,
305
                'uuid' => $user->uuid,
341
                'name' => trim($user->first_name . ' ' . $user->last_name),
306
                'name' => trim($user->first_name . ' ' . $user->last_name),
Línea 345... Línea 310...
345
                    'filename' => $user->image
310
                    'filename' => $user->image
346
                ], ['force_canonical' => true]),
311
                ], ['force_canonical' => true]),
347
                'profile' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
312
                'profile' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
348
                'last_message' => $timeElapsedString,
313
                'last_message' => $timeElapsedString,
349
                'count_unread' => $unread,
314
                'count_unread' => $unread,
350
                'messages_link' => $this->url()->fromRoute('inmail/messages', ['id' => $user->uuid]),
315
                'messages_link' => $this->url()->fromRoute('inmail/messages/get-messages', ['id' => $user->uuid]),
351
                'send_link' => $this->url()->fromRoute('inmail/messages/send', ['id' => $user->uuid]),
316
                'send_link' => $this->url()->fromRoute('inmail/messages/send', ['id' => $user->uuid]),
352
                'selected' => 0, // No seleccionado
317
                'selected' => 0, // No seleccionado
353
                'delete_link' => $this->url()->fromRoute('inmail/messages/delete', ['id' => $user->uuid]),
318
                'delete_link' => $this->url()->fromRoute('inmail/messages/delete', ['id' => $user->uuid]),
354
            ]);
319
            ]);
355
        }
320
        }
Línea 356... Línea -...
356
 
-
 
357
        // ========================================
-
 
358
        // ORDENAMIENTO DE CONVERSACIONES
-
 
359
        // ========================================
-
 
360
        
321
 
361
        // Ordenar por: seleccionados primero, luego por fecha del último mensaje
322
        // Ordenar por: seleccionados primero, luego por fecha del último mensaje
362
        usort($conversations, function ($a, $b) {
323
        usort($conversations, function ($a, $b) {
363
            if ($a['selected'] == $b['selected']) {
324
            if ($a['selected'] == $b['selected']) {
364
                if ($a['last_message'] == $b['last_message']) {
325
                if ($a['last_message'] == $b['last_message']) {
Línea 369... Línea 330...
369
            } else {
330
            } else {
370
                return $a['selected'] < $b['selected'] ? -1 : 1;
331
                return $a['selected'] < $b['selected'] ? -1 : 1;
371
            }
332
            }
372
        });
333
        });
Línea 373... Línea -...
373
 
-
 
374
        // ========================================
-
 
375
        // RESPUESTA FINAL
-
 
376
        // ========================================
-
 
377
        
334
 
378
        return new JsonModel([
335
        return new JsonModel([
379
            'success' => true,
336
            'success' => true,
380
            'data' => $conversations
337
            'data' => $conversations
381
        ]);
338
        ]);
Línea 418... Línea 375...
418
     *   data: mensaje de error
375
     *   data: mensaje de error
419
     * ]
376
     * ]
420
     * 
377
     * 
421
     * @return \Laminas\View\Model\JsonModel
378
     * @return \Laminas\View\Model\JsonModel
422
     */
379
     */
423
    public function messagesAction()
380
    public function getMessagesAction()
424
    {
381
    {
425
        $request = $this->getRequest();
382
        $request = $this->getRequest();
Línea 426... Línea 383...
426
        
383
        
427
        // Verificar que la petición sea GET
384
        // Verificar que la petición sea GET
428
        if (!$request->isGet()) {
385
        if (!$request->isGet()) {
429
            return new JsonModel([
386
            return new JsonModel([
430
                'success' => false,
387
                'success' => false,
431
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
388
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
432
            ]);
389
            ]);
433
        }
-
 
434
 
-
 
435
        // ========================================
-
 
436
        // INICIALIZACIÓN Y VALIDACIÓN DE PARÁMETROS
-
 
Línea 437... Línea 390...
437
        // ========================================
390
        }
438
        
391
        
439
        // Obtener parámetros de la petición
392
        // Obtener parámetros de la petición
Línea 454... Línea 407...
454
 
407
 
455
        // Obtener la fecha actual de la base de datos para cálculos de tiempo
408
        // Obtener la fecha actual de la base de datos para cálculos de tiempo
456
        $userMapper = UserMapper::getInstance($this->adapter);
409
        $userMapper = UserMapper::getInstance($this->adapter);
Línea 457... Línea -...
457
        $now = $userMapper->getDatebaseNow();
-
 
458
 
-
 
459
        // ========================================
-
 
460
        // VALIDACIÓN DEL USUARIO DESTINATARIO
-
 
461
        // ========================================
410
        $now = $userMapper->getDatebaseNow();
462
        
411
 
463
        // Buscar el usuario destinatario por UUID
412
        // Buscar el usuario destinatario por UUID
464
        $user = $userMapper->fetchOneByUuid($id);
413
        $user = $userMapper->fetchOneByUuid($id);
465
        if (!$user) {
414
        if (!$user) {
466
            return new JsonModel([
415
            return new JsonModel([
467
                'success' => false,
416
                'success' => false,
468
                'data' => 'ERROR_REQUEST_IS_INVALID'
417
                'data' => 'ERROR_REQUEST_IS_INVALID'
Línea 469... Línea -...
469
            ]);
-
 
470
        }
-
 
471
 
-
 
472
        // ========================================
-
 
473
        // OBTENCIÓN DE REPORTES DE ABUSO
418
            ]);
474
        // ========================================
419
        }
475
        
420
 
476
        // Obtener IDs de mensajes reportados por el usuario actual
421
        // Obtener IDs de mensajes reportados por el usuario actual
477
        $abuseReportMapper = AbuseReportMapper::getInstance($this->adapter);
422
        $abuseReportMapper = AbuseReportMapper::getInstance($this->adapter);
478
        $abuse_report_message_ids = $abuseReportMapper->fetchAllDataByUserReportingIdAndTypeReturnIds(
423
        $abuse_report_message_ids = $abuseReportMapper->fetchAllDataByUserReportingIdAndTypeReturnIds(
Línea 479... Línea -...
479
            $currentUser->id, 
-
 
480
            AbuseReport::TYPE_INMAIL_MESSAGE
-
 
481
        );
-
 
482
 
-
 
483
        // ========================================
424
            $currentUser->id, 
484
        // BÚSQUEDA DE LA CONVERSACIÓN
425
            AbuseReport::TYPE_INMAIL_MESSAGE
Línea 485... Línea 426...
485
        // ========================================
426
        );
486
        
427
 
Línea 487... Línea 428...
487
        $conversationMapper = ConversationMapper::getInstance($this->adapter);
428
        $conversationMapper = ConversationMapper::getInstance($this->adapter);
Línea 488... Línea -...
488
        $messageMapper = MessageMapper::getInstance($this->adapter);
-
 
489
        
-
 
490
        // Buscar la conversación entre los dos usuarios
-
 
491
        $conversation = $conversationMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
-
 
492
        
429
        $messageMapper = MessageMapper::getInstance($this->adapter);
493
        $messages = [];
430
        
494
        
431
        // Buscar la conversación entre los dos usuarios
Línea 495... Línea 432...
495
        // ========================================
432
        $conversation = $conversationMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
496
        // PROCESAMIENTO DE MENSAJES
433
        
497
        // ========================================
434
        $messages = [];
Línea 498... Línea -...
498
        
-
 
499
        if ($conversation) {
-
 
500
            // Obtener mensajes paginados de la conversación
-
 
501
            $records = $messageMapper->getAllMessagesPaginatorByConversationId($conversation->id, $page);
-
 
502
 
435
        
503
            foreach ($records as $record) {
436
        if ($conversation) {
504
                // Calcular tiempo transcurrido desde el envío del mensaje
437
            // Obtener mensajes paginados de la conversación
505
                $timeElapsedString = $this->timeAgo($record->added_on, $now);
438
            $records = $messageMapper->getAllMessagesPaginatorByConversationId($conversation->id, $page);
506
 
439
 
Línea 535... Línea 468...
535
                        ], ['force_canonical' => true]) : '',
468
                        ], ['force_canonical' => true]) : '',
536
                        'date' => $timeElapsedString,
469
                        'date' => $timeElapsedString,
537
                        'url_abuse_report' => '', // No se puede reportar mensajes propios
470
                        'url_abuse_report' => '', // No se puede reportar mensajes propios
538
                    ]);
471
                    ]);
539
                } 
472
                } 
540
                // ========================================
-
 
541
                // MENSAJES RECIBIDOS DEL OTRO USUARIO
-
 
542
                // ========================================
-
 
543
                else {
473
                else {
544
                    // Verificar si el mensaje ha sido reportado por abuso
474
                    // Verificar si el mensaje ha sido reportado por abuso
545
                    if (in_array($record->id, $abuse_report_message_ids)) {
475
                    if (in_array($record->id, $abuse_report_message_ids)) {
546
                        // Mensaje reportado - mostrar mensaje de contenido reportado
476
                        // Mensaje reportado - mostrar mensaje de contenido reportado
547
                        array_push($messages, [
477
                        array_push($messages, [
Línea 606... Línea 536...
606
                        $messageMapper->markAsRead($record->id);
536
                        $messageMapper->markAsRead($record->id);
607
                    }
537
                    }
608
                }
538
                }
609
            }
539
            }
Línea 610... Línea -...
610
 
-
 
611
            // ========================================
-
 
612
            // RESPUESTA CON MENSAJES Y PAGINACIÓN
-
 
613
            // ========================================
-
 
614
            
540
 
615
            return new JsonModel([
541
            return new JsonModel([
616
                'success' => true,
542
                'success' => true,
617
                'data' => $messages,
543
                'data' => $messages,
618
                'pagination' => $records->getPages()
544
                'pagination' => $records->getPages()
619
            ]);
545
            ]);
Línea 620... Línea -...
620
        }
-
 
621
 
-
 
622
        // ========================================
-
 
623
        // RESPUESTA CUANDO NO EXISTE CONVERSACIÓN
-
 
624
        // ========================================
546
        }
625
        
547
 
626
        return new JsonModel([
548
        return new JsonModel([
627
            'success' => true,
549
            'success' => true,
628
            'data' => $messages,
550
            'data' => $messages,