diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index 21c380d3c8..584e370c7c 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -3049,6 +3049,57 @@ class MessageManager 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 $otherUserId diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index 6c2b92acf1..73fef8f1a3 100755 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -2405,11 +2405,11 @@ if (!empty($sessionId)) { $allow = api_get_configuration_value('allow_user_message_tracking'); if ($allow && (api_is_drh() || api_is_platform_admin())) { if ($filterMessages) { - $users = MessageManager::getUsersThatHadConversationWithUser($student_id, $coachAccessStartDate, $coachAccessEndDate); + $users = MessageManager::getMessageExchangeWithUser($student_id, $coachAccessStartDate, $coachAccessEndDate); } else { - $users = MessageManager::getUsersThatHadConversationWithUser($student_id); + $users = MessageManager::getMessageExchangeWithUser($student_id); } - $users = MessageManager::getUsersThatHadConversationWithUser($student_id); + echo Display::page_subheader2(get_lang('MessageTracking')); $table = new HTML_Table(['class' => 'table']);