ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilOnScreenChatGUI Class Reference

Class ilOnScreenChatGUI. More...

+ Inheritance diagram for ilOnScreenChatGUI:
+ Collaboration diagram for ilOnScreenChatGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 

Static Public Member Functions

static initializeFrontend (ilGlobalTemplateInterface $page)
 

Static Protected Member Functions

static isOnScreenChatAccessible (ilSetting $chatSettings)
 
static getEmoticons (ilChatroomServerSettings $chatSettings)
 

Static Protected Attributes

static bool $frontend_initialized = false
 

Private Member Functions

 getResponseWithText (string $body)
 
 verifyLogin ()
 
 getUserList ()
 
 getUserProfileData ()
 

Private Attributes

ILIAS DI Container $dic
 
ILIAS HTTP Services $http
 
ilCtrlInterface $ctrl
 
ilObjUser $actor
 

Detailed Description

Class ilOnScreenChatGUI.

Author
Thomas Joußen tjous.nosp@m.sen@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Since
26.07.16

Definition at line 33 of file class.ilOnScreenChatGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilOnScreenChatGUI::__construct ( )

Definition at line 42 of file class.ilOnScreenChatGUI.php.

References $DIC, ILIAS\Repository\ctrl(), and ILIAS\FileDelivery\http().

43  {
44  global $DIC;
45 
46  $this->dic = $DIC;
47  $this->http = $DIC->http();
48  $this->ctrl = $DIC->ctrl();
49  $this->actor = $DIC->user();
50  }
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilOnScreenChatGUI::executeCommand ( )

Definition at line 104 of file class.ilOnScreenChatGUI.php.

References $provider, $response, ILIAS\Repository\ctrl(), getResponseWithText(), getUserList(), getUserProfileData(), ILIAS\FileDelivery\http(), and verifyLogin().

104  : void
105  {
106  $cmd = $this->ctrl->getCmd();
107  switch ($cmd) {
108  case 'getUserProfileData':
109  $response = $this->getUserProfileData();
110  break;
111 
112  case 'verifyLogin':
113  $response = $this->verifyLogin();
114  break;
115 
116  case 'getRenderedConversationItems':
118  $this->dic,
119  new Conversation($this->dic->database(), $this->dic->user()),
120  new Subscriber($this->dic->database(), $this->dic->user())
121  );
122 
123  $conversationIds = (string) ($this->dic->http()->request()->getQueryParams()['ids'] ?? '');
124  $noAggregates = ($this->dic->http()->request()->getQueryParams()['no_aggregates'] ?? '');
125 
127  $this->dic->ui()->renderer()->renderAsync($provider->getAsyncItem(
128  $conversationIds,
129  $noAggregates !== 'true'
130  ))
131  );
132  break;
133 
134  case 'getUserlist':
135  default:
136  $response = $this->getUserList();
137  }
138 
139  if ($this->ctrl->isAsynch()) {
140  $this->http->saveResponse($response);
141  $this->http->sendResponse();
142  $this->http->close();
143  }
144  }
$provider
Definition: ltitoken.php:83
static http()
Fetches the global http state from ILIAS.
getResponseWithText(string $body)
$response
+ Here is the call graph for this function:

◆ getEmoticons()

static ilOnScreenChatGUI::getEmoticons ( ilChatroomServerSettings  $chatSettings)
staticprotected
Parameters
ilChatroomServerSettings$chatSettings
Returns
array<string, string>

Definition at line 72 of file class.ilOnScreenChatGUI.php.

References ILIAS\LTI\ToolProvider\$key, and ilChatroomServerSettings\getSmiliesEnabled().

72  : array
73  {
74  $smileys = [];
75 
76  if ($chatSettings->getSmiliesEnabled()) {
77  $smileys_array = ilChatroomSmilies::_getSmilies();
78  foreach ($smileys_array as $smiley_array) {
79  $new_keys = [];
80  $new_val = '';
81  foreach ($smiley_array as $key => $value) {
82  if ($key === 'smiley_keywords') {
83  $new_keys = explode("\n", $value);
84  }
85 
86  if ($key === 'smiley_fullpath') {
87  $new_val = $value;
88  }
89  }
90 
91  if (!$new_keys || !$new_val) {
92  continue;
93  }
94 
95  foreach ($new_keys as $new_key) {
96  $smileys[$new_key] = $new_val;
97  }
98  }
99  }
100 
101  return $smileys;
102  }
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ getResponseWithText()

ilOnScreenChatGUI::getResponseWithText ( string  $body)
private

Definition at line 52 of file class.ilOnScreenChatGUI.php.

Referenced by executeCommand(), getUserList(), getUserProfileData(), and verifyLogin().

52  : ResponseInterface
53  {
54  return $this->dic->http()->response()->withBody(Streams::ofString($body));
55  }
+ Here is the caller graph for this function:

◆ getUserList()

ilOnScreenChatGUI::getUserList ( )
private

Definition at line 155 of file class.ilOnScreenChatGUI.php.

References getResponseWithText(), ILIAS\FileDelivery\http(), ilUserAutoComplete\MAX_ENTRIES, and ilUserAutoComplete\PRIVACY_MODE_RESPECT_USER_SETTING.

Referenced by executeCommand().

155  : ResponseInterface
156  {
157  if (!$this->actor->getId() || $this->actor->isAnonymous()) {
158  return $this->getResponseWithText(json_encode([], JSON_THROW_ON_ERROR));
159  }
160 
162  $auto->setUser($this->actor);
164  if (isset($this->http->request()->getQueryParams()['fetchall'])) {
165  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
166  }
167  $auto->setMoreLinkAvailable(true);
168  $auto->setSearchFields(['firstname', 'lastname']);
169  $auto->setResultField('login');
170  $auto->enableFieldSearchableCheck(true);
171 
172  return $this->getResponseWithText($auto->getList($this->http->request()->getQueryParams()['term'] ?? ''));
173  }
Class ilOnScreenChatUserUserAutoComplete.
static http()
Fetches the global http state from ILIAS.
getResponseWithText(string $body)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserProfileData()

ilOnScreenChatGUI::getUserProfileData ( )
private

Definition at line 175 of file class.ilOnScreenChatGUI.php.

References $data, ilSession\enableWebAccessWithoutSession(), getResponseWithText(), and ILIAS\FileDelivery\http().

Referenced by executeCommand().

175  : ResponseInterface
176  {
177  if (!$this->actor->getId() || $this->actor->isAnonymous()) {
178  return $this->getResponseWithText(json_encode([], JSON_THROW_ON_ERROR));
179  }
180 
181  $usrIds = (string) ($this->http->request()->getQueryParams()['usr_ids'] ?? '');
182  if ($usrIds === '') {
183  return $this->getResponseWithText(json_encode([], JSON_THROW_ON_ERROR));
184  }
185 
186  $this->dic->language()->loadLanguageModule('user');
187  $subscriberRepo = new Subscriber($this->dic->database(), $this->dic->user());
188  $data = $subscriberRepo->getDataByUserIds(explode(',', $usrIds));
189 
191 
192  return $this->getResponseWithText(json_encode($data, JSON_THROW_ON_ERROR));
193  }
static enableWebAccessWithoutSession(bool $enable_web_access_without_session)
static http()
Fetches the global http state from ILIAS.
getResponseWithText(string $body)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initializeFrontend()

static ilOnScreenChatGUI::initializeFrontend ( ilGlobalTemplateInterface  $page)
static

Definition at line 195 of file class.ilOnScreenChatGUI.php.

References $DIC, $factory, ILIAS\LTI\ToolProvider\$settings, ilGlobalTemplateInterface\addJavaScript(), ilGlobalTemplateInterface\addOnLoadCode(), ilUtil\getImagePath(), ILIAS\LTI\ToolProvider\getSettings(), ilUtil\img(), iljQueryUtil\initjQuery(), iljQueryUtil\initjQueryUI(), ilLinkifyUtil\initLinkify(), ilChatroomServerSettings\loadDefault(), and ilUtil\yn2tf().

Referenced by ilGlobalPageTemplate\prepareBasicJS().

195  : void
196  {
197  global $DIC;
198 
199  if (!self::$frontend_initialized) {
200  $clientSettings = new ilSetting('chatroom');
201 
202  if (!self::isOnScreenChatAccessible($clientSettings)) {
203  self::$frontend_initialized = true;
204  return;
205  }
206 
208 
209  $DIC->language()->loadLanguageModule('chatroom');
210  $DIC->language()->loadLanguageModule('user');
211 
212  $renderer = $DIC->ui()->renderer();
213  $factory = $DIC->ui()->factory();
214 
215  $chatWindowTemplate = new ilTemplate('tpl.chat-window.html', false, false, 'Services/OnScreenChat');
216  $chatWindowTemplate->setVariable('SUBMIT_ACTION', $renderer->render(
217  $factory->button()->standard($DIC->language()->txt('chat_osc_send'), 'onscreenchat-submit')
218  ));
219  $chatWindowTemplate->setVariable('ADD_ACTION', $renderer->render(
220  $factory->symbol()->glyph()->add('addUser')
221  ));
222  $chatWindowTemplate->setVariable('MINIMIZE_ACTION', $renderer->render(
223  $factory->button()->minimize()
224  ));
225  $chatWindowTemplate->setVariable('CONVERSATION_ICON', ilUtil::img(ilUtil::getImagePath('icon_pcht.svg')));
226 
227  $subscriberRepo = new Subscriber($DIC->database(), $DIC->user());
228 
229  $guiConfig = [
230  'chatWindowTemplate' => $chatWindowTemplate->get(),
231  'messageTemplate' => (new ilTemplate(
232  'tpl.chat-message.html',
233  false,
234  false,
235  'Services/OnScreenChat'
236  ))->get(),
237  'modalTemplate' => (new ilTemplate(
238  'tpl.chat-add-user.html',
239  false,
240  false,
241  'Services/OnScreenChat'
242  ))->get(),
243  'userId' => $DIC->user()->getId(),
244  'username' => $DIC->user()->getLogin(),
245  'userListURL' => $DIC->ctrl()->getLinkTargetByClass(
246  'ilonscreenchatgui',
247  'getUserList',
248  '',
249  true,
250  false
251  ),
252  'userProfileDataURL' => $DIC->ctrl()->getLinkTargetByClass(
253  'ilonscreenchatgui',
254  'getUserProfileData',
255  '',
256  true,
257  false
258  ),
259  'verifyLoginURL' => $DIC->ctrl()->getLinkTargetByClass(
260  'ilonscreenchatgui',
261  'verifyLogin',
262  '',
263  true,
264  false
265  ),
266  'renderConversationItemsURL' => $DIC->ctrl()->getLinkTargetByClass(
267  'ilonscreenchatgui',
268  'getRenderedConversationItems',
269  '',
270  true,
271  false
272  ),
273  'loaderImg' => ilUtil::getImagePath('loader.svg'),
274  'emoticons' => self::getEmoticons($settings),
275  'locale' => $DIC->language()->getLangKey(),
276  'initialUserData' => $subscriberRepo->getInitialUserProfileData(),
277  'enabledBrowserNotifications' => (
278  $clientSettings->get('enable_browser_notifications', '0') &&
279  ilUtil::yn2tf((string) $DIC->user()->getPref('chat_osc_browser_notifications'))
280  ),
281  'broadcast_typing' => (
282  ilUtil::yn2tf((string) $DIC->user()->getPref('chat_broadcast_typing'))
283  ),
284  'notificationIconPath' => ilUtil::getImagePath('icon_chta.png'),
285  ];
286 
287  $chatConfig = [
288  'url' => $settings->generateClientUrl() . '/' . $settings->getInstance() . '-im',
289  'subDirectory' => $settings->getSubDirectory() . '/socket.io',
290  'userId' => $DIC->user()->getId(),
291  'username' => $DIC->user()->getLogin(),
292  ];
293 
294  $DIC->language()->toJS([
295  'chat_osc_no_usr_found',
296  'chat_osc_emoticons',
297  'chat_osc_write_a_msg',
298  'autocomplete_more',
299  'chat_osc_minimize',
300  'chat_osc_invite_to_conversation',
301  'chat_osc_user',
302  'chat_osc_add_user',
303  'chat_osc_subs_rej_msgs',
304  'chat_osc_subs_rej_msgs_p',
305  'chat_osc_self_rej_msgs',
306  'chat_osc_search_modal_info',
307  'chat_osc_head_grp_x_persons',
308  'osc_noti_title',
309  'chat_osc_conversations',
310  'chat_osc_sure_to_leave_grp_conv',
311  'chat_osc_user_left_grp_conv',
312  'confirm',
313  'cancel',
314  'chat_osc_leave_grp_conv',
315  'chat_osc_no_conv',
316  'chat_osc_nc_conv_x_p',
317  'chat_osc_nc_conv_x_s',
318  'chat_osc_nc_no_conv',
319  'chat_user_x_is_typing',
320  'chat_users_are_typing',
321  'today',
322  'yesterday',
323  ], $page);
324 
328 
329  $page->addJavaScript('./node_modules/jquery-outside-events/jquery.ba-outside-events.js');
330  $page->addJavaScript('./node_modules/@andxor/jquery-ui-touch-punch-fix/jquery.ui.touch-punch.js');
331  $page->addJavascript('./Services/UIComponent/Modal/js/Modal.js');
332  $page->addJavascript('./node_modules/moment/min/moment-with-locales.min.js');
333  $page->addJavascript('./Services/Notifications/js/browser_notifications.js');
334  $page->addJavascript('./Services/OnScreenChat/js/onscreenchat-notifications.js');
335  $page->addJavascript('./Services/OnScreenChat/js/moment.js');
336  $page->addJavascript('./Modules/Chatroom/chat/node_modules/socket.io-client/dist/socket.io.js');
337  $page->addJavascript('./Services/OnScreenChat/js/chat.js');
338  $page->addJavascript('./Services/OnScreenChat/js/onscreenchat.js');
339  $page->addOnLoadCode("il.Chat.setConfig(" . json_encode($chatConfig, JSON_THROW_ON_ERROR) . ");");
340  $page->addOnLoadCode("il.OnScreenChat.setConfig(" . json_encode($guiConfig, JSON_THROW_ON_ERROR) . ");");
341  $page->addOnLoadCode("il.OnScreenChat.init();");
342  $page->addOnLoadCode('il.OnScreenChatNotifications.init(' . json_encode([
343  'conversationIdleTimeThreshold' => max(
344  1,
345  (int) $clientSettings->get('conversation_idle_state_in_minutes', '1')
346  ),
347  'logLevel' => $DIC['ilLoggerFactory']->getSettings()->getLevelByComponent('osch'),
348  ], JSON_THROW_ON_ERROR) . ');');
349 
350  self::$frontend_initialized = true;
351  }
352  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
static initLinkify(?ilGlobalTemplateInterface $a_tpl=null)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
global $DIC
Definition: feed.php:28
getSettings()
Get an array of all setting values.
Definition: System.php:287
static initjQueryUI(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components.txt for included components)
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
addOnLoadCode(string $a_code, int $a_batch=2)
Add on load code.
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
static yn2tf(string $a_yn)
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isOnScreenChatAccessible()

static ilOnScreenChatGUI::isOnScreenChatAccessible ( ilSetting  $chatSettings)
staticprotected

Definition at line 57 of file class.ilOnScreenChatGUI.php.

References $DIC, and ilSetting\get().

57  : bool
58  {
59  global $DIC;
60 
61  return (
62  $chatSettings->get('chat_enabled', '0') &&
63  $chatSettings->get('enable_osc', '0') &&
64  $DIC->user() && !$DIC->user()->isAnonymous()
65  );
66  }
get(string $a_keyword, ?string $a_default_value=null)
get setting
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ verifyLogin()

ilOnScreenChatGUI::verifyLogin ( )
private

Definition at line 146 of file class.ilOnScreenChatGUI.php.

References ilSession\enableWebAccessWithoutSession(), and getResponseWithText().

Referenced by executeCommand().

146  : ResponseInterface
147  {
149 
150  return $this->getResponseWithText(json_encode([
151  'loggedIn' => $this->actor->getId() && !$this->actor->isAnonymous()
152  ], JSON_THROW_ON_ERROR));
153  }
static enableWebAccessWithoutSession(bool $enable_web_access_without_session)
getResponseWithText(string $body)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $actor

ilObjUser ilOnScreenChatGUI::$actor
private

Definition at line 40 of file class.ilOnScreenChatGUI.php.

◆ $ctrl

ilCtrlInterface ilOnScreenChatGUI::$ctrl
private

Definition at line 39 of file class.ilOnScreenChatGUI.php.

◆ $dic

ILIAS DI Container ilOnScreenChatGUI::$dic
private

Definition at line 37 of file class.ilOnScreenChatGUI.php.

◆ $frontend_initialized

bool ilOnScreenChatGUI::$frontend_initialized = false
staticprotected

Definition at line 35 of file class.ilOnScreenChatGUI.php.

◆ $http

ILIAS HTTP Services ilOnScreenChatGUI::$http
private

Definition at line 38 of file class.ilOnScreenChatGUI.php.


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