ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
OnScreenChatProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ilDateTime;
33use ilSetting;
34use ilUtil;
35use JsonException;
37use ILIAS\User\Privacy\SettingsGUI as PrivacySettingsGUI;
40
46{
48 private readonly Subscriber $subscriberRepo;
49
50 public function __construct(
54 ) {
56 $dic->language()->loadLanguageModule('chatroom');
57 $this->conversationRepo = $conversationRepo ?? new Conversation($this->dic->database(), $this->dic->user());
58 $this->subscriberRepo = $subscriberRepo ?? new Subscriber($this->dic->database(), $this->dic->user());
59 }
60
64 public function getStaticTopItems(): array
65 {
66 return [];
67 }
68
69 private function getSlateMessageBox(): MessageBox
70 {
71 $acceptsMessages = ilUtil::yn2tf((string) $this->dic->user()->getPref('chat_osc_accept_msg'));
72 if ($acceptsMessages) {
73 return $this->dic->ui()->factory()
74 ->messageBox()
75 ->info($this->dic->language()->txt('chat_osc_accept_no_conv_info_slate'));
76 }
77
78 return $this->dic->ui()->factory()
79 ->messageBox()
80 ->info($this->dic->language()->txt('chat_osc_accept_msg_info_slate'))
81 ->withLinks([
82 $this->dic->ui()->factory()
83 ->link()
84 ->standard(
85 $this->dic->language()->txt('chat_osc_accept_msg_info_slate_link_txt'),
86 $this->dic->ctrl()->getLinkTargetByClass(
87 [
88 ilDashboardGUI::class,
89 PersonalProfileGUI::class,
90 PrivacySettingsGUI::class
91 ],
92 'showPrivacySettings'
93 )
94 )
95 ]);
96 }
97
101 public function getStaticSubItems(): array
102 {
103 $icon = $this->dic->ui()->factory()->symbol()->icon()->standard(
105 $this->dic->language()->txt('public_room')
106 );
107
108 return [
109 $this->mainmenu->complex($this->if->identifier('mm_chat'))
110 ->withAvailableCallable(function (): bool {
111 $isUser = 0 !== $this->dic->user()->getId() && !$this->dic->user()->isAnonymous();
112 $chatSettings = new ilSetting('chatroom');
113 $isEnabled = $chatSettings->get('chat_enabled') && $chatSettings->get('enable_osc');
114
115 return $isUser && $isEnabled;
116 })
117 ->withTitle($this->dic->language()->txt('mm_private_chats'))
118 ->withSymbol($icon)
119 ->withContentWrapper(function (): \ILIAS\UI\Component\Component {
120 $components = [
121 $this->getSlateMessageBox(),
122 $this->dic->ui()->factory()->item()->shy('')->withAdditionalOnLoadCode(
123 static function ($id): string {
124 return "il.OnScreenChat.menuCollector = $id.parentNode;$id.remove();";
125 }
126 )
127 ];
128
129 return $this->dic->ui()->factory()->legacy()->content($this->dic->ui()->renderer()->render($components));
130 })
131 ->withParent(StandardTopItemsProvider::getInstance()->getCommunicationIdentification())
132 ->withPosition(40)
133 ,
134 ];
135 }
136
142 public function getAsyncItem(string $conversationIds, bool $withAggregates): array
143 {
144 $conversationIds = array_filter(explode(',', $conversationIds));
145
146 if (!$withAggregates || !$this->dic->user()->getId() || $this->dic->user()->isAnonymous()) {
147 return [$this->getSlateMessageBox()];
148 }
149
150 $conversations = $this->conversationRepo->findByIds($conversationIds);
151
152 $allUsrIds = [];
153 foreach ($conversations as $conversation) {
154 foreach ($conversation->getSubscriberUsrIds() as $id) {
155 if ($id !== $this->dic->user()->getId()) {
156 $allUsrIds[$id] = true;
157 }
158 }
159 }
160 $allUsrIds = array_keys($allUsrIds);
161 $user_data = $this->subscriberRepo->getDataByUserIds($allUsrIds);
162
163 $items = [];
164 foreach ($conversations as $conversation) {
165 if ($conversation->isGroup()) {
166 $icon = $this->dic->ui()->factory()->symbol()->icon()->standard(Standard::GCON, 'group-conversation');
167 } else {
168 $icon = $this->dic->ui()->factory()->symbol()->icon()->standard(Standard::CON, 'conversation');
169 }
170
171 $users = [];
172 foreach ($conversation->getSubscriberUsrIds() as $id) {
173 if ($id !== $this->dic->user()->getId()) {
174 $users[] = $user_data[$id]['public_name'];
175 }
176 }
177
178 $cid = $conversation->getId();
179
180 $items[] = $this->dic->ui()->factory()->item()->shy(implode(', ', $users))
181 ->withDescription($conversation->getLastMessage()->getMessage())
182 ->withProperties(
183 [$this->dic->language()->txt('time') . ':' =>
185 new ilDateTime(
186 (int) ($conversation->getLastMessage()->getCreatedTimestamp() / 1000),
188 )
189 )
190 ]
191 )
192 ->withLeadIcon($icon)
193 ->withClose($this->dic->ui()->factory()->button()->close())
194 ->withAdditionalOnLoadCode(
195 function ($id) use ($cid) {
196 return "il.OnScreenChat.menuCollector.querySelector('#$id').dataset.id = '$cid';";
197 }
198 );
199 }
200
201 if ($items === []) {
202 $items[] = $this->getSlateMessageBox();
203 }
204
205 return $items;
206 }
207}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$components
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
language()
Get interface to the i18n service.
Definition: Container.php:95
__construct(Container $dic, ?Conversation $conversationRepo=null, ?Subscriber $subscriberRepo=null)
getAsyncItem(string $conversationIds, bool $withAggregates)
Definition: UI.php:24
const IL_CAL_UNIX
@ilCtrl_Calls ilDashboardGUI: ILIAS\User\Profile\PersonalProfileGUI @ilCtrl_Calls ilDashboardGUI: ilO...
Class for date presentation.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
ILIAS Setting Class.
get(string $a_keyword, ?string $a_default_value=null)
get setting
Util class various functions, usage as namespace.
static yn2tf(string $a_yn)
This describes the specific behavior of an ILIAS standard icon.
Definition: Standard.php:27
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
withParent(IdentificationInterface $identification)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))