ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 Protected Attributes

static bool $frontend_initialized = false
 

Private Member Functions

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

Private Attributes

readonly ILIAS DI Container $dic
 
readonly ILIAS HTTP Services $http
 
readonly ilCtrlInterface $ctrl
 
readonly 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 68 of file class.ilOnScreenChatGUI.php.

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

68  : void
69  {
70  $cmd = $this->ctrl->getCmd();
71  switch ($cmd) {
72  case 'getUserProfileData':
73  $response = $this->getUserProfileData();
74  break;
75 
76  case 'verifyLogin':
77  $response = $this->verifyLogin();
78  break;
79 
80  case 'getRenderedConversationItems':
82  $this->dic,
83  new Conversation($this->dic->database(), $this->dic->user()),
84  new Subscriber($this->dic->database(), $this->dic->user())
85  );
86 
87  $conversationIds = (string) ($this->dic->http()->request()->getQueryParams()['ids'] ?? '');
88  $noAggregates = ($this->dic->http()->request()->getQueryParams()['no_aggregates'] ?? '');
89 
91  $this->dic->ui()->renderer()->renderAsync($provider->getAsyncItem(
92  $conversationIds,
93  $noAggregates !== 'true'
94  ))
95  );
96  break;
97 
98  case 'getUserlist':
99  default:
100  $response = $this->getUserList();
101  }
102 
103  if ($this->ctrl->isAsynch()) {
104  $this->http->saveResponse($response);
105  $this->http->sendResponse();
106  $this->http->close();
107  }
108  }
$response
Definition: xapitoken.php:93
$provider
Definition: ltitoken.php:83
static http()
Fetches the global http state from ILIAS.
getResponseWithText(string $body)
+ 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 119 of file class.ilOnScreenChatGUI.php.

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

Referenced by executeCommand().

119  : ResponseInterface
120  {
121  if (!$this->actor->getId() || $this->actor->isAnonymous()) {
122  return $this->getResponseWithText(json_encode([], JSON_THROW_ON_ERROR));
123  }
124 
126  $auto->setUser($this->actor);
128  if (isset($this->http->request()->getQueryParams()['fetchall'])) {
129  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
130  }
131  $auto->setMoreLinkAvailable(true);
132  $auto->setSearchFields(['firstname', 'lastname']);
133  $auto->setResultField('login');
134  $auto->enableFieldSearchableCheck(true);
135 
136  return $this->getResponseWithText($auto->getList($this->http->request()->getQueryParams()['term'] ?? ''));
137  }
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 139 of file class.ilOnScreenChatGUI.php.

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

Referenced by executeCommand().

139  : ResponseInterface
140  {
141  if (!$this->actor->getId() || $this->actor->isAnonymous()) {
142  return $this->getResponseWithText(json_encode([], JSON_THROW_ON_ERROR));
143  }
144 
145  $usrIds = (string) ($this->http->request()->getQueryParams()['usr_ids'] ?? '');
146  if ($usrIds === '') {
147  return $this->getResponseWithText(json_encode([], JSON_THROW_ON_ERROR));
148  }
149 
150  $this->dic->language()->loadLanguageModule('user');
151  $subscriberRepo = new Subscriber($this->dic->database(), $this->dic->user());
152  $data = $subscriberRepo->getDataByUserIds(explode(',', $usrIds));
153 
155 
156  return $this->getResponseWithText(json_encode($data, JSON_THROW_ON_ERROR));
157  }
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 159 of file class.ilOnScreenChatGUI.php.

References $DIC, 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().

159  : void
160  {
161  global $DIC;
162 
163  if (!self::$frontend_initialized) {
164  $clientSettings = new ilSetting('chatroom');
165 
166  if (!self::isOnScreenChatAccessible($clientSettings)) {
167  self::$frontend_initialized = true;
168  return;
169  }
170 
172 
173  $DIC->language()->loadLanguageModule('chatroom');
174  $DIC->language()->loadLanguageModule('user');
175 
176  $renderer = $DIC->ui()->renderer();
177  $factory = $DIC->ui()->factory();
178 
179  $chatWindowTemplate = new ilTemplate('tpl.chat-window.html', false, false, 'Services/OnScreenChat');
180  $chatWindowTemplate->setVariable('SUBMIT_ACTION', $renderer->render(
181  $factory->button()->standard($DIC->language()->txt('chat_osc_send'), 'onscreenchat-submit')
182  ));
183  $chatWindowTemplate->setVariable('ADD_ACTION', $renderer->render(
184  $factory->symbol()->glyph()->add('addUser')
185  ));
186  $chatWindowTemplate->setVariable('MINIMIZE_ACTION', $renderer->render(
187  $factory->button()->minimize()
188  ));
189  $chatWindowTemplate->setVariable('CONVERSATION_ICON', ilUtil::img(ilUtil::getImagePath('standard/icon_pcht.svg')));
190 
191  $subscriberRepo = new Subscriber($DIC->database(), $DIC->user());
192 
193  $guiConfig = [
194  'chatWindowTemplate' => $chatWindowTemplate->get(),
195  'messageTemplate' => (new ilTemplate(
196  'tpl.chat-message.html',
197  false,
198  false,
199  'Services/OnScreenChat'
200  ))->get(),
201  'modalTemplate' => (new ilTemplate(
202  'tpl.chat-add-user.html',
203  false,
204  false,
205  'Services/OnScreenChat'
206  ))->get(),
207  'userId' => $DIC->user()->getId(),
208  'username' => $DIC->user()->getLogin(),
209  'userListURL' => $DIC->ctrl()->getLinkTargetByClass(
210  'ilonscreenchatgui',
211  'getUserList',
212  '',
213  true,
214  false
215  ),
216  'userProfileDataURL' => $DIC->ctrl()->getLinkTargetByClass(
217  'ilonscreenchatgui',
218  'getUserProfileData',
219  '',
220  true,
221  false
222  ),
223  'verifyLoginURL' => $DIC->ctrl()->getLinkTargetByClass(
224  'ilonscreenchatgui',
225  'verifyLogin',
226  '',
227  true,
228  false
229  ),
230  'renderConversationItemsURL' => $DIC->ctrl()->getLinkTargetByClass(
231  'ilonscreenchatgui',
232  'getRenderedConversationItems',
233  '',
234  true,
235  false
236  ),
237  'loaderImg' => ilUtil::getImagePath('media/loader.svg'),
238  'locale' => $DIC->language()->getLangKey(),
239  'initialUserData' => $subscriberRepo->getInitialUserProfileData(),
240  'enabledBrowserNotifications' => (
241  $clientSettings->get('enable_browser_notifications', '0') &&
242  ilUtil::yn2tf((string) $DIC->user()->getPref('chat_osc_browser_notifications'))
243  ),
244  'broadcast_typing' => (
245  ilUtil::yn2tf((string) $DIC->user()->getPref('chat_broadcast_typing'))
246  ),
247  'notificationIconPath' => ilUtil::getImagePath('standard/icon_chta.png'),
248  ];
249 
250  $chatConfig = [
251  'url' => $settings->generateClientUrl() . '/' . $settings->getInstance() . '-im',
252  'subDirectory' => $settings->getSubDirectory() . '/socket.io',
253  'userId' => $DIC->user()->getId(),
254  'username' => $DIC->user()->getLogin(),
255  ];
256 
257  $DIC->language()->toJS([
258  'chat_osc_no_usr_found',
259  'chat_osc_write_a_msg',
260  'autocomplete_more',
261  'chat_osc_minimize',
262  'chat_osc_invite_to_conversation',
263  'chat_osc_user',
264  'chat_osc_add_user',
265  'chat_osc_subs_rej_msgs',
266  'chat_osc_subs_rej_msgs_p',
267  'chat_osc_self_rej_msgs',
268  'chat_osc_search_modal_info',
269  'chat_osc_head_grp_x_persons',
270  'osc_noti_title',
271  'chat_osc_conversations',
272  'chat_osc_sure_to_leave_grp_conv',
273  'chat_osc_user_left_grp_conv',
274  'confirm',
275  'cancel',
276  'chat_osc_leave_grp_conv',
277  'chat_osc_no_conv',
278  'chat_osc_nc_conv_x_p',
279  'chat_osc_nc_conv_x_s',
280  'chat_osc_nc_no_conv',
281  'chat_user_x_is_typing',
282  'chat_users_are_typing',
283  'today',
284  'yesterday',
285  ], $page);
286 
290 
291  $page->addJavaScript('./node_modules/jquery-outside-events/jquery.ba-outside-events.js');
292  $page->addJavaScript('./node_modules/@andxor/jquery-ui-touch-punch-fix/jquery.ui.touch-punch.js');
293  $page->addJavascript('./Services/UIComponent/Modal/js/Modal.js');
294  $page->addJavascript('./node_modules/moment/min/moment-with-locales.min.js');
295  $page->addJavascript('./Services/Notifications/js/browser_notifications.js');
296  $page->addJavascript('./Services/OnScreenChat/js/onscreenchat-notifications.js');
297  $page->addJavascript('./Services/OnScreenChat/js/moment.js');
298  $page->addJavascript('./Modules/Chatroom/chat/node_modules/socket.io-client/dist/socket.io.js');
299  $page->addJavascript('./Services/OnScreenChat/js/chat.js');
300  $page->addJavascript('./Services/OnScreenChat/js/onscreenchat.js');
301  $page->addOnLoadCode("il.Chat.setConfig(" . json_encode($chatConfig, JSON_THROW_ON_ERROR) . ");");
302  $page->addOnLoadCode("il.OnScreenChat.setConfig(" . json_encode($guiConfig, JSON_THROW_ON_ERROR) . ");");
303  $page->addOnLoadCode("il.OnScreenChat.init();");
304  $page->addOnLoadCode('il.OnScreenChatNotifications.init(' . json_encode([
305  'conversationIdleTimeThreshold' => max(
306  1,
307  (int) $clientSettings->get('conversation_idle_state_in_minutes', '1')
308  ),
309  'logLevel' => $DIC['ilLoggerFactory']->getSettings()->getLevelByComponent('osch'),
310  ], JSON_THROW_ON_ERROR) . ');');
311 
312  self::$frontend_initialized = true;
313  }
314  }
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)
+ 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 110 of file class.ilOnScreenChatGUI.php.

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

Referenced by executeCommand().

110  : ResponseInterface
111  {
113 
114  return $this->getResponseWithText(json_encode([
115  'loggedIn' => $this->actor->getId() && !$this->actor->isAnonymous()
116  ], JSON_THROW_ON_ERROR));
117  }
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

readonly ilObjUser ilOnScreenChatGUI::$actor
private

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

◆ $ctrl

readonly ilCtrlInterface ilOnScreenChatGUI::$ctrl
private

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

◆ $dic

readonly 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

readonly 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: