ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilOnScreenChatGUI Class Reference

Class ilOnScreenChatGUI. More...

+ Collaboration diagram for ilOnScreenChatGUI:

Public Member Functions

 __construct ()
 ilOnScreenChatGUI constructor. More...
 
 executeCommand ()
 

Static Public Member Functions

static initializeFrontend (ilGlobalTemplateInterface $page)
 Initialize frontend and delivers required javascript files and configuration to the global template. More...
 

Static Protected Member Functions

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

Static Protected Attributes

static $frontend_initialized = false
 

Private Member Functions

 getResponseWithText (string $body)
 
 verifyLogin ()
 Checks if a user is logged in. More...
 
 getUserList ()
 
 getUserProfileData ()
 

Private Attributes

 $dic
 
 $http
 
 $ctrl
 
 $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 16 of file class.ilOnScreenChatGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilOnScreenChatGUI::__construct ( )

ilOnScreenChatGUI constructor.

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

37 {
38 global $DIC;
39
40 $this->dic = $DIC;
41 $this->http = $DIC->http();
42 $this->ctrl = $DIC->ctrl();
43 $this->actor = $DIC->user();
44 }
static http()
Fetches the global http state from ILIAS.
$DIC
Definition: xapitoken.php:46

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

+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilOnScreenChatGUI::executeCommand ( )

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

105 : void
106 {
107 $cmd = $this->ctrl->getCmd();
108 switch ($cmd) {
109 case 'getUserProfileData':
110 $response = $this->getUserProfileData();
111 break;
112
113 case 'verifyLogin':
114 $response = $this->verifyLogin();
115 break;
116
117 case 'getRenderedNotificationItems':
118 $provider = new OnScreenChatNotificationProvider(
119 $this->dic,
120 new Conversation($this->dic->database(), $this->dic->user()),
121 new Subscriber($this->dic->database(), $this->dic->user())
122 );
123
124 $conversationIds = (string) ($this->dic->http()->request()->getQueryParams()['ids'] ?? '');
125 $noAggregates = ($this->dic->http()->request()->getQueryParams()['no_aggregates'] ?? '');
126
128 $this->dic->ui()->renderer()->renderAsync($provider->getAsyncItem(
129 $conversationIds,
130 $noAggregates !== 'true'
131 ))
132 );
133 break;
134
135 case 'getUserlist':
136 default:
137 $response = $this->getUserList();
138 }
139
140 if ($this->ctrl->isAsynch()) {
141 $this->http->saveResponse($response);
142 $this->http->sendResponse();
143 exit();
144 }
145 }
getResponseWithText(string $body)
verifyLogin()
Checks if a user is logged in.
exit
Definition: login.php:29
$response

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

+ Here is the call graph for this function:

◆ getEmoticons()

static ilOnScreenChatGUI::getEmoticons ( ilChatroomServerSettings  $chatSettings)
staticprotected
Parameters
ilChatroomServerSettings$chatSettings
Returns
array

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

70 : array
71 {
72 $smileys = array();
73
74 if ($chatSettings->getSmiliesEnabled()) {
75 require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
76 ;
77
78 $smileys_array = ilChatroomSmilies::_getSmilies();
79 foreach ($smileys_array as $smiley_array) {
80 $new_keys = array();
81 $new_val = '';
82 foreach ($smiley_array as $key => $value) {
83 if ($key == 'smiley_keywords') {
84 $new_keys = explode("\n", $value);
85 }
86
87 if ($key == 'smiley_fullpath') {
88 $new_val = $value;
89 }
90 }
91
92 if (!$new_keys || !$new_val) {
93 continue;
94 }
95
96 foreach ($new_keys as $new_key) {
97 $smileys[$new_key] = $new_val;
98 }
99 }
100 }
101
102 return $smileys;
103 }

References ilChatroomServerSettings\getSmiliesEnabled().

+ Here is the call graph for this function:

◆ getResponseWithText()

ilOnScreenChatGUI::getResponseWithText ( string  $body)
private
Parameters
string$body
Returns
ResponseInterface

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

50 : ResponseInterface
51 {
52 return $this->dic->http()->response()->withBody(Streams::ofString($body));
53 }

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

+ Here is the caller graph for this function:

◆ getUserList()

ilOnScreenChatGUI::getUserList ( )
private
Returns
ResponseInterface

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

164 : ResponseInterface
165 {
166 if (!$this->actor->getId() || $this->actor->isAnonymous()) {
167 return $this->getResponseWithText(json_encode([]));
168 }
169
171 $auto->setUser($this->actor);
173 if (isset($this->http->request()->getQueryParams()['fetchall'])) {
174 $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
175 }
176 $auto->setMoreLinkAvailable(true);
177 $auto->setSearchFields(['firstname', 'lastname']);
178 $auto->setResultField('login');
179 $auto->enableFieldSearchableCheck(true);
180
181 return $this->getResponseWithText($auto->getList($this->http->request()->getQueryParams()['term'] ?? ''));
182 }

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

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserProfileData()

ilOnScreenChatGUI::getUserProfileData ( )
private
Returns
ResponseInterface
Exceptions
ilWACException

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

188 : ResponseInterface
189 {
190 if (!$this->actor->getId() || $this->actor->isAnonymous()) {
191 return $this->getResponseWithText(json_encode([]));
192 }
193
194 $usrIds = (string) ($this->http->request()->getQueryParams()['usr_ids'] ?? '');
195 if (0 === strlen($usrIds)) {
196 return $this->getResponseWithText(json_encode([]));
197 }
198
199 $this->dic->language()->loadLanguageModule('user');
200 $subscriberRepo = new Subscriber($this->dic->database(), $this->dic->user());
201 $data = $subscriberRepo->getDataByUserIds(explode(',', $usrIds));
202
204
205 return $this->getResponseWithText(json_encode($data));
206 }
static enableWebAccessWithoutSession($enable_web_access_without_session)
$data
Definition: storeScorm.php:23

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

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initializeFrontend()

static ilOnScreenChatGUI::initializeFrontend ( ilGlobalTemplateInterface  $page)
static

Initialize frontend and delivers required javascript files and configuration to the global template.

Parameters
ilGlobalTemplateInterface$page
Exceptions
ilTemplateException
ilWACException

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

214 : void
215 {
216 global $DIC;
217
218 if (!self::$frontend_initialized) {
219 $clientSettings = new ilSetting('chatroom');
220
221 if (!self::isOnScreenChatAccessible($clientSettings)) {
222 self::$frontend_initialized = true;
223 return;
224 }
225
227
228 $DIC->language()->loadLanguageModule('chatroom');
229 $DIC->language()->loadLanguageModule('user');
230
231 $renderer = $DIC->ui()->renderer();
232 $factory = $DIC->ui()->factory();
233
234 $chatWindowTemplate = new ilTemplate('tpl.chat-window.html', false, false, 'Services/OnScreenChat');
235 $chatWindowTemplate->setVariable('SUBMIT_ACTION', $renderer->render(
236 $factory->button()->standard($DIC->language()->txt('chat_osc_send'), 'onscreenchat-submit')
237 ));
238 $chatWindowTemplate->setVariable('ADD_ACTION', $renderer->render(
239 $factory->symbol()->glyph()->add('addUser')
240 ));
241 $chatWindowTemplate->setVariable('CLOSE_ACTION', $renderer->render(
242 $factory->button()->close()
243 ));
244 $chatWindowTemplate->setVariable('CONVERSATION_ICON', ilUtil::img(ilUtil::getImagePath('outlined/icon_pcht.svg')));
245
246 $subscriberRepo = new Subscriber($DIC->database(), $DIC->user());
247
248 $guiConfig = array(
249 'chatWindowTemplate' => $chatWindowTemplate->get(),
250 'messageTemplate' => (new ilTemplate(
251 'tpl.chat-message.html',
252 false,
253 false,
254 'Services/OnScreenChat'
255 ))->get(),
256 'modalTemplate' => (new ilTemplate(
257 'tpl.chat-add-user.html',
258 false,
259 false,
260 'Services/OnScreenChat'
261 ))->get(),
262 'userId' => $DIC->user()->getId(),
263 'username' => $DIC->user()->getLogin(),
264 'userListURL' => $DIC->ctrl()->getLinkTargetByClass(
265 'ilonscreenchatgui',
266 'getUserList',
267 '',
268 true,
269 false
270 ),
271 'userProfileDataURL' => $DIC->ctrl()->getLinkTargetByClass(
272 'ilonscreenchatgui',
273 'getUserProfileData',
274 '',
275 true,
276 false
277 ),
278 'verifyLoginURL' => $DIC->ctrl()->getLinkTargetByClass(
279 'ilonscreenchatgui',
280 'verifyLogin',
281 '',
282 true,
283 false
284 ),
285 'renderNotificationItemsURL' => $DIC->ctrl()->getLinkTargetByClass(
286 'ilonscreenchatgui',
287 'getRenderedNotificationItems',
288 '',
289 true,
290 false
291 ),
292 'loaderImg' => ilUtil::getImagePath('loader.svg'),
293 'emoticons' => self::getEmoticons($settings),
294 'locale' => $DIC->language()->getLangKey(),
295 'initialUserData' => $subscriberRepo->getInitialUserProfileData(),
296 'enabledBrowserNotifications' => (
297 $clientSettings->get('enable_browser_notifications', false) &&
298 (bool) ilUtil::yn2tf($DIC->user()->getPref('chat_osc_browser_notifications'))
299 ),
300 'notificationIconPath' => \ilUtil::getImagePath('icon_chta.png'),
301 );
302
303 $chatConfig = array(
304 'url' => $settings->generateClientUrl() . '/' . $settings->getInstance() . '-im',
305 'subDirectory' => $settings->getSubDirectory() . '/socket.io',
306 'userId' => $DIC->user()->getId(),
307 'username' => $DIC->user()->getLogin(),
308 );
309
310 $DIC->language()->toJS([
311 'chat_osc_no_usr_found',
312 'chat_osc_emoticons',
313 'chat_osc_write_a_msg',
314 'autocomplete_more',
315 'close',
316 'chat_osc_invite_to_conversation',
317 'chat_osc_user',
318 'chat_osc_add_user',
319 'chat_osc_subs_rej_msgs',
320 'chat_osc_subs_rej_msgs_p',
321 'chat_osc_self_rej_msgs',
322 'chat_osc_search_modal_info',
323 'chat_osc_head_grp_x_persons',
324 'osc_noti_title',
325 'chat_osc_conversations',
326 'chat_osc_sure_to_leave_grp_conv',
327 'chat_osc_user_left_grp_conv',
328 'confirm',
329 'cancel',
330 'chat_osc_leave_grp_conv',
331 'chat_osc_no_conv',
332 'chat_osc_nc_conv_x_p',
333 'chat_osc_nc_conv_x_s',
334 'chat_osc_nc_no_conv',
335 'today',
336 'yesterday',
337 ], $page);
338
342
343 $page->addJavaScript('./libs/bower/bower_components/jquery-outside-events/jquery.ba-outside-events.min.js');
344 $page->addJavaScript('./libs/bower/bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
345 $page->addJavascript('./Services/UIComponent/Modal/js/Modal.js');
346 $page->addJavascript('./libs/bower/bower_components/moment/min/moment-with-locales.min.js');
347 $page->addJavascript('./Services/Notifications/js/browser_notifications.js');
348 $page->addJavascript('./Services/OnScreenChat/js/onscreenchat-notifications.js');
349 $page->addJavascript('./Services/OnScreenChat/js/moment.js');
350 $page->addJavascript('./Modules/Chatroom/chat/node_modules/socket.io-client/dist/socket.io.js');
351 $page->addJavascript('./Services/OnScreenChat/js/chat.js');
352 $page->addJavascript('./Services/OnScreenChat/js/onscreenchat.js');
353 $page->addOnLoadCode("il.Chat.setConfig(" . json_encode($chatConfig) . ");");
354 $page->addOnLoadCode("il.OnScreenChat.setConfig(" . json_encode($guiConfig) . ");");
355 $page->addOnLoadCode("il.OnScreenChat.init();");
356 $page->addOnLoadCode('il.OnScreenChatNotifications.init(' . json_encode([
357 'conversationIdleTimeThreshold' => max(
358 1,
359 (int) $clientSettings->get('conversation_idle_state_in_minutes', 1)
360 ),
361 'logLevel' => $DIC['ilLoggerFactory']->getSettings()->getLevelByComponent('osch'),
362 ]) . ');');
363
364 self::$frontend_initialized = true;
365 }
366 }
static initLinkify($a_tpl=null)
Init Linkify.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static yn2tf($a_yn)
convert "y"/"n" to true/false
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
static initjQueryUI($a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components....
addJavaScript($a_js_file, $a_add_version_parameter=true, $a_batch=2)
Add a javascript file that should be included in the header.
addOnLoadCode($a_code, $a_batch=2)
Add on load code.
$factory
Definition: metadata.php:58

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

Referenced by ilGlobalPageTemplate\prepareBasicJS().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isOnScreenChatAccessible()

static ilOnScreenChatGUI::isOnScreenChatAccessible ( ilSetting  $chatSettings)
staticprotected
Parameters
ilSetting$chatSettings
Returns
bool

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

59 : bool
60 {
61 global $DIC;
62
63 return $chatSettings->get('chat_enabled') && $chatSettings->get('enable_osc') && $DIC->user() && !$DIC->user()->isAnonymous();
64 }
get($a_keyword, $a_default_value=false)
get setting

References $DIC, and ilSetting\get().

+ Here is the call graph for this function:

◆ verifyLogin()

ilOnScreenChatGUI::verifyLogin ( )
private

Checks if a user is logged in.

If not, this function should cause an redirect, to disallow chatting while not logged into ILIAS.

Returns
ResponseInterface

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

152 : ResponseInterface
153 {
155
156 return $this->getResponseWithText(json_encode([
157 'loggedIn' => $this->actor->getId() && !$this->actor->isAnonymous()
158 ]));
159 }

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

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $actor

ilOnScreenChatGUI::$actor
private

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

◆ $ctrl

ilOnScreenChatGUI::$ctrl
private

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

◆ $dic

ilOnScreenChatGUI::$dic
private

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

◆ $frontend_initialized

ilOnScreenChatGUI::$frontend_initialized = false
staticprotected

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

◆ $http

ilOnScreenChatGUI::$http
private

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


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