ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ILIAS\OnScreenChat\Repository\Conversation Class Reference
+ Collaboration diagram for ILIAS\OnScreenChat\Repository\Conversation:

Public Member Functions

 __construct (\ilDBInterface $db, \ilObjUser $user)
 Conversation constructor. More...
 
 findByIds (array $conversationIds)
 

Protected Attributes

 $user
 

Private Attributes

 $db
 

Detailed Description

Definition at line 13 of file Conversation.php.

Constructor & Destructor Documentation

◆ __construct()

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

Conversation constructor.

Parameters
\ilDBInterface$db
\ilObjUser$user

Definition at line 25 of file Conversation.php.

References ILIAS\OnScreenChat\Repository\Conversation\$db, ILIAS\OnScreenChat\Repository\Conversation\$user, and user().

+ Here is the call graph for this function:

Member Function Documentation

◆ findByIds()

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

Definition at line 35 of file Conversation.php.

References $message, $query, $res, and user().

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

Field Documentation

◆ $db

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

◆ $user

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

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