ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\OnScreenChat\Repository\Conversation Class Reference
+ Collaboration diagram for ILIAS\OnScreenChat\Repository\Conversation:

Public Member Functions

 __construct (private readonly ilDBInterface $db, protected ilObjUser $user)
 
 findByIds (array $conversationIds)
 

Detailed Description

Definition at line 32 of file Conversation.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\OnScreenChat\Repository\Conversation::__construct ( private readonly ilDBInterface  $db,
protected ilObjUser  $user 
)

Definition at line 34 of file Conversation.php.

35 {
36 }

Member Function Documentation

◆ findByIds()

ILIAS\OnScreenChat\Repository\Conversation::findByIds ( array  $conversationIds)
Parameters
string[]$conversationIds
Returns
ConversationDto[]

Definition at line 42 of file Conversation.php.

42 : array
43 {
44 $conversations = [];
45
46 $res = $this->db->query(
47 'SELECT * FROM osc_conversation WHERE ' . $this->db->in(
48 'id',
49 $conversationIds,
50 false,
51 'text'
52 )
53 );
54
55 while ($row = $this->db->fetchAssoc($res)) {
56 $participants = json_decode((string) $row['participants'], true, 512, JSON_THROW_ON_ERROR);
57 $participantIds = array_filter(array_map(static function ($user): int {
58 if (is_array($user) && isset($user['id'])) {
59 return (int) $user['id'];
60 }
61
62 return 0;
63 }, $participants));
64
65 if (!in_array($this->user->getId(), $participantIds, true)) {
66 continue;
67 }
68
69 $conversation = new ConversationDto($row['id']);
70 $conversation->setIsGroup((bool) $row['is_group']);
71 $conversation->setSubscriberUsrIds($participantIds);
72
73 $inParticipants = $this->db->in(
74 'osc_messages.user_id',
75 $participantIds,
76 false,
77 'text'
78 );
79
80 $this->db->setLimit(1, 0);
81 $query = "
82 SELECT osc_messages.*
83 FROM osc_messages
84 WHERE osc_messages.conversation_id = %s
85 AND $inParticipants
86 ORDER BY osc_messages.timestamp DESC
87 ";
88 $msgRes = $this->db->queryF($query, ['text'], [$conversation->getId()]);
89 while ($msgRow = $this->db->fetchAssoc($msgRes)) {
90 $message = new MessageDto($msgRow['id'], $conversation);
91 $message->setMessage($msgRow['message']);
92 $message->setAuthorUsrId((int) $msgRow['user_id']);
93 $message->setCreatedTimestamp((int) $msgRow['timestamp']);
94 $conversation->setLastMessage($message);
95 break;
96 }
97
98 $conversations[] = $conversation;
99 }
100
101 return $conversations;
102 }
$res
Definition: ltiservices.php:69
$message
Definition: xapiexit.php:31

References $message, $res, and ILIAS\Repository\user().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: