Tracking: Improve message tracking (remove duplicate and add seeing sent/received) (#5237)

pull/5880/head
juancp-contidosdixitais 1 year ago committed by GitHub
parent 4fb383d07b
commit 20ec8e75c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 51
      main/inc/lib/message.lib.php
  2. 6
      main/mySpace/myStudents.php

@ -3049,6 +3049,57 @@ class MessageManager
return $userList; return $userList;
} }
/**
* Retrieves a list of users with whom the specified user has exchanged messages within an optional date range.
*
* @param int $userId The user ID for whom to retrieve message exchange.
* @param string|null $startDate Start date to filter the messages (optional).
* @param string|null $endDate End date to filter the messages (optional).
*
* @return array Array of user information for each user with whom the specified user has exchanged messages.
*/
public static function getMessageExchangeWithUser($userId, $startDate = null, $endDate = null)
{
$messagesTable = Database::get_main_table(TABLE_MESSAGE);
$userId = (int) $userId;
if ($startDate !== null) {
$startDate = Database::escape_string($startDate);
}
if ($endDate !== null) {
$endDate = Database::escape_string($endDate);
}
$sql = "SELECT DISTINCT user_sender_id AS user_id
FROM $messagesTable
WHERE user_receiver_id = $userId" .
($startDate ? " AND send_date >= '$startDate'" : "") .
($endDate ? " AND send_date <= '$endDate'" : "") .
" UNION
SELECT DISTINCT user_receiver_id
FROM $messagesTable
WHERE user_sender_id = $userId" .
($startDate ? " AND send_date >= '$startDate'" : "") .
($endDate ? " AND send_date <= '$endDate'" : "");
$result = Database::query($sql);
$users = Database::store_result($result);
$userList = [];
foreach ($users as $userData) {
$userId = $userData['user_id'];
if (empty($userId)) {
continue;
}
$userInfo = api_get_user_info($userId);
if ($userInfo) {
$userList[$userId] = $userInfo;
}
}
return $userList;
}
/** /**
* @param int $userId * @param int $userId
* @param int $otherUserId * @param int $otherUserId

@ -2405,11 +2405,11 @@ if (!empty($sessionId)) {
$allow = api_get_configuration_value('allow_user_message_tracking'); $allow = api_get_configuration_value('allow_user_message_tracking');
if ($allow && (api_is_drh() || api_is_platform_admin())) { if ($allow && (api_is_drh() || api_is_platform_admin())) {
if ($filterMessages) { if ($filterMessages) {
$users = MessageManager::getUsersThatHadConversationWithUser($student_id, $coachAccessStartDate, $coachAccessEndDate); $users = MessageManager::getMessageExchangeWithUser($student_id, $coachAccessStartDate, $coachAccessEndDate);
} else { } else {
$users = MessageManager::getUsersThatHadConversationWithUser($student_id); $users = MessageManager::getMessageExchangeWithUser($student_id);
} }
$users = MessageManager::getUsersThatHadConversationWithUser($student_id);
echo Display::page_subheader2(get_lang('MessageTracking')); echo Display::page_subheader2(get_lang('MessageTracking'));
$table = new HTML_Table(['class' => 'table']); $table = new HTML_Table(['class' => 'table']);

Loading…
Cancel
Save