ILIAS  release_8 Revision v8.23
ILIAS\OnScreenChat\Repository\Conversation Class Reference
+ Collaboration diagram for ILIAS\OnScreenChat\Repository\Conversation:

Public Member Functions

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

Protected Attributes

ilObjUser $user
 

Private Attributes

ilDBInterface $db
 

Detailed Description

Definition at line 32 of file Conversation.php.

Constructor & Destructor Documentation

◆ __construct()

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

Member Function Documentation

◆ findByIds()

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

Definition at line 47 of file Conversation.php.

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

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

Field Documentation

◆ $db

ilDBInterface ILIAS\OnScreenChat\Repository\Conversation::$db
private

◆ $user

ilObjUser ILIAS\OnScreenChat\Repository\Conversation::$user
protected

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