ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
OnScreenChatProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ilDateTime;
33 use ilSetting;
34 use ilUtil;
35 use JsonException;
37 use ilDashboardGUI;
40 
46 {
49 
50  public function __construct(
52  ?Conversation $conversationRepo = null,
53  ?Subscriber $subscriberRepo = null
54  ) {
55  parent::__construct($dic);
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  ilPersonalProfileGUI::class,
90  ilUserPrivacySettingsGUI::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($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())
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 }
Class Factory.
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
getAsyncItem(string $conversationIds, bool $withAggregates)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
language()
Get interface to the i18n service.
Definition: Container.php:86
__construct(Container $dic, ilPlugin $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ?Conversation $conversationRepo=null, ?Subscriber $subscriberRepo=null)
static yn2tf(string $a_yn)