19 declare(strict_types=1);
47 public function findByIds(array $conversationIds): array
51 $res = $this->db->query(
52 'SELECT * FROM osc_conversation WHERE ' . $this->db->in(
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'];
70 if (!in_array($this->
user->getId(), $participantIds,
true)) {
75 $conversation->setIsGroup((
bool) $row[
'is_group']);
76 $conversation->setSubscriberUsrIds($participantIds);
78 $inParticipants = $this->db->in(
79 'osc_messages.user_id',
85 $this->db->setLimit(1, 0);
89 WHERE osc_messages.conversation_id = %s 91 ORDER BY osc_messages.timestamp DESC 93 $msgRes = $this->db->queryF(
$query, [
'text'], [$conversation->getId()]);
94 while ($msgRow = $this->db->fetchAssoc($msgRes)) {
96 $message->setMessage($msgRow[
'message']);
97 $message->setAuthorUsrId((
int) $msgRow[
'user_id']);
98 $message->setCreatedTimestamp((
int) $msgRow[
'timestamp']);
99 $conversation->setLastMessage(
$message);
103 $conversations[] = $conversation;
106 return $conversations;
findByIds(array $conversationIds)
__construct(ilDBInterface $db, ilObjUser $user)