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

Class ilChatroomViewGUI. More...

+ Inheritance diagram for ilChatroomViewGUI:
+ Collaboration diagram for ilChatroomViewGUI:

Public Member Functions

 joinWithCustomName ()
 
 toggleAutoMessageDisplayState ()
 
 executeDefault (string $requestedMethod)
 Chatroom and Chatuser get prepared before $this->showRoom method is called. More...
 
 invitePD ()
 
 logout ()
 
 lostConnection ()
 
- Public Member Functions inherited from ilChatroomGUIHandler
 execute (string $method)
 
 executeDefault (string $requestedMethod)
 
 redirectIfNoPermission ($permission)
 Checks for requested permissions and redirects if the permission check failed. More...
 
 isSuccessful ($response)
 Checks for success param in an json decoded response. More...
 
 sendResponse ($response, bool $isJson=false)
 Sends a json encoded response and exits the php process. More...
 
 hasPermission (string $permission)
 

Protected Member Functions

 renderSendMessageBox (ilTemplate $roomTpl)
 
 renderLanguageVariables (ilTemplate $roomTpl)
 
 renderRightUsersBlock (ilTemplate $roomTpl)
 
- Protected Member Functions inherited from ilChatroomGUIHandler
 getRequestValue (string $key, Transformation $trafo, $default=null)
 
 hasRequestValue (string $key)
 
 getRoomByObjectId (int $objectId)
 
 exitIfNoRoomExists (?ilChatroom $room)
 Checks if a ilChatroom exists. More...
 
 exitIfNoRoomModeratePermission (ilChatroom $room, int $subRoom, ilChatroomUser $chatUser)
 Check if user can moderate a chatroom. More...
 
 canModerate (ilChatroom $room, int $subRoom, int $usrId)
 
 isMainRoom (int $subRoomId)
 

Private Member Functions

 setupTemplate ()
 Adds CSS and JavaScript files that should be included in the header. More...
 
 showRoom (ilChatroom $room, ilChatroomUser $chat_user)
 Prepares and displays chatroom and connects user to it. More...
 
 cancelJoin (string $message)
 Calls ilUtil::sendFailure method using given $message as parameter. More...
 
 showNameSelection (ilChatroomUser $chat_user)
 

Additional Inherited Members

- Protected Attributes inherited from ilChatroomGUIHandler
ilChatroomObjectGUI $gui
 
ilObjUser $ilUser
 
ilCtrlInterface $ilCtrl
 
ilLanguage $ilLng
 
Filesystem $webDirectory
 
ilObjectService $obj_service
 
FileUpload $upload
 
ilRbacSystem $rbacsystem
 
ilGlobalTemplateInterface $mainTpl
 
ILIAS $ilias
 
ilNavigationHistory $navigationHistory
 
ilTree $tree
 
ilTabsGUI $tabs
 
UIFactory $uiFactory
 
UIRenderer $uiRenderer
 
GlobalHttpState $http
 
Refinery $refinery
 

Detailed Description

Class ilChatroomViewGUI.

Author
Jan Posselt jposs.nosp@m.elt@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$

Definition at line 30 of file class.ilChatroomViewGUI.php.

Member Function Documentation

◆ cancelJoin()

ilChatroomViewGUI::cancelJoin ( string  $message)
private

Calls ilUtil::sendFailure method using given $message as parameter.

Parameters
string$message

Definition at line 355 of file class.ilChatroomViewGUI.php.

Referenced by executeDefault(), and showRoom().

355  : void
356  {
357  $this->mainTpl->setOnScreenMessage('failure', $message);
358  }
$message
Definition: xapiexit.php:32
+ Here is the caller graph for this function:

◆ executeDefault()

ilChatroomViewGUI::executeDefault ( string  $requestedMethod)

Chatroom and Chatuser get prepared before $this->showRoom method is called.

If custom usernames are allowed, $this->showNameSelection method is called if user isn't already registered in the Chatroom.

Definition at line 453 of file class.ilChatroomViewGUI.php.

References ilChatroom\byObjectId(), cancelJoin(), ilChatroomGUIHandler\redirectIfNoPermission(), setupTemplate(), showNameSelection(), and showRoom().

453  : void
454  {
455  $this->redirectIfNoPermission('read');
456 
457  $this->gui->switchToVisibleMode();
458  $this->setupTemplate();
459 
460  $chatSettings = new ilSetting('chatroom');
461  if (!$chatSettings->get('chat_enabled', '0')) {
462  $this->ilCtrl->redirect($this->gui, 'settings-general');
463  }
464 
465  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
466 
467  if (!$room->getSetting('allow_anonymous') && $this->ilUser->isAnonymous()) {
468  $this->cancelJoin($this->ilLng->txt('chat_anonymous_not_allowed'));
469  return;
470  }
471 
472  $chat_user = new ilChatroomUser($this->ilUser, $room);
473 
474  if ($room->getSetting('allow_custom_usernames')) {
475  if ($room->isSubscribed($chat_user->getUserId())) {
476  $chat_user->setUsername($chat_user->getUsername());
477  $this->showRoom($room, $chat_user);
478  } else {
479  $this->showNameSelection($chat_user);
480  }
481  } else {
482  $chat_user->setUsername($this->ilUser->getLogin());
483  $this->showRoom($room, $chat_user);
484  }
485  }
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
cancelJoin(string $message)
Calls ilUtil::sendFailure method using given $message as parameter.
setupTemplate()
Adds CSS and JavaScript files that should be included in the header.
showRoom(ilChatroom $room, ilChatroomUser $chat_user)
Prepares and displays chatroom and connects user to it.
Class ilChatroomUser.
static byObjectId(int $object_id)
showNameSelection(ilChatroomUser $chat_user)
+ Here is the call graph for this function:

◆ invitePD()

ilChatroomViewGUI::invitePD ( )

Definition at line 487 of file class.ilChatroomViewGUI.php.

References ilChatroom\byObjectId(), ilChatroomGUIHandler\getRequestValue(), ILIAS\Repository\refinery(), and ilSession\set().

487  : void
488  {
489  $chatSettings = new ilSetting('chatroom');
490  if (!$chatSettings->get('chat_enabled', '0')) {
491  $this->ilCtrl->redirect($this->gui, 'settings-general');
492  }
493 
494  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
495  $chat_user = new ilChatroomUser($this->ilUser, $room);
496 
497  $user_id = $this->getRequestValue('usr_id', $this->refinery->kindlyTo()->int());
498 
499  $connector = $this->gui->getConnector();
500  $title = $room->getUniquePrivateRoomTitle($chat_user->buildLogin());
501  $subRoomId = $room->addPrivateRoom($title, $chat_user, ['public' => false]);
502 
503  $room->inviteUserToPrivateRoom($user_id, $subRoomId);
504  $connector->sendCreatePrivateRoom($room->getRoomId(), $subRoomId, $chat_user->getUserId(), $title);
505  $connector->sendInviteToPrivateRoom($room->getRoomId(), $subRoomId, $chat_user->getUserId(), $user_id);
506 
507  $room->sendInvitationNotification($this->gui, $chat_user, $user_id, $subRoomId);
508 
509  ilSession::set('show_invitation_message', $user_id);
510 
511  $this->ilCtrl->setParameter($this->gui, 'sub', $subRoomId);
512  $this->ilCtrl->redirect($this->gui, 'view');
513  }
getRequestValue(string $key, Transformation $trafo, $default=null)
Class ilChatroomUser.
static byObjectId(int $object_id)
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

◆ joinWithCustomName()

ilChatroomViewGUI::joinWithCustomName ( )

Definition at line 32 of file class.ilChatroomViewGUI.php.

References ilChatroom\byObjectId(), ilChatroomGUIHandler\getRequestValue(), ilChatroomGUIHandler\hasRequestValue(), ilChatroomGUIHandler\redirectIfNoPermission(), ILIAS\Repository\refinery(), setupTemplate(), showNameSelection(), and showRoom().

32  : void
33  {
34  $this->redirectIfNoPermission('read');
35 
36  $this->gui->switchToVisibleMode();
37  $this->setupTemplate();
38  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
39  $chat_user = new ilChatroomUser($this->ilUser, $room);
40  $failure = true;
41  $username = '';
42 
43  if ($this->hasRequestValue('custom_username_radio')) {
44  if (
45  $this->hasRequestValue('custom_username_text') &&
46  $this->getRequestValue('custom_username_radio', $this->refinery->kindlyTo()->string()) === 'custom_username'
47  ) {
48  $username = $this->getRequestValue('custom_username_text', $this->refinery->kindlyTo()->string());
49  $failure = false;
50  } elseif (
51  method_exists(
52  $chat_user,
53  'build' . $this->getRequestValue('custom_username_radio', $this->refinery->kindlyTo()->string())
54  )
55  ) {
56  $username = $chat_user->{
57  'build' . $this->getRequestValue('custom_username_radio', $this->refinery->kindlyTo()->string())
58  }();
59  $failure = false;
60  }
61  }
62 
63  if (!$failure && trim($username) !== '') {
64  if (!$room->isSubscribed($chat_user->getUserId())) {
65  $chat_user->setUsername($chat_user->buildUniqueUsername($username));
66  }
67 
68  $this->showRoom($room, $chat_user);
69  } else {
70  $this->mainTpl->setOnScreenMessage('failure', $this->ilLng->txt('no_username_given'));
71  $this->showNameSelection($chat_user);
72  }
73  }
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
getRequestValue(string $key, Transformation $trafo, $default=null)
setupTemplate()
Adds CSS and JavaScript files that should be included in the header.
showRoom(ilChatroom $room, ilChatroomUser $chat_user)
Prepares and displays chatroom and connects user to it.
Class ilChatroomUser.
static byObjectId(int $object_id)
showNameSelection(ilChatroomUser $chat_user)
+ Here is the call graph for this function:

◆ logout()

ilChatroomViewGUI::logout ( )

Definition at line 515 of file class.ilChatroomViewGUI.php.

515  : void
516  {
517  $pid = $this->tree->getParentId($this->gui->getRefId());
518  $this->ilCtrl->setParameterByClass(ilRepositoryGUI::class, 'ref_id', $pid);
519  $this->ilCtrl->redirectByClass(ilRepositoryGUI::class);
520  }

◆ lostConnection()

ilChatroomViewGUI::lostConnection ( )

Definition at line 522 of file class.ilChatroomViewGUI.php.

References $DIC, $response, ANONYMOUS_USER_ID, ilChatroom\byObjectId(), ilUserUtil\getNamePresentation(), ilChatroomGUIHandler\getRequestValue(), ilChatroomUser\getUserInformation(), ilChatroomGUIHandler\hasRequestValue(), ILIAS\FileDelivery\http(), ILIAS\UI\examples\Symbol\Glyph\Login\login(), ILIAS\Repository\refinery(), ilChatroomGUIHandler\sendResponse(), ilWACSignedPath\setTokenMaxLifetimeInSeconds(), and ilStr\subStr().

522  : void
523  {
524  if ($this->http->wrapper()->query()->has('msg')) {
525  switch ($this->http->wrapper()->query()->retrieve('msg', $this->refinery->kindlyTo()->string())) {
526  case 'kicked':
527  $this->mainTpl->setOnScreenMessage('failure', $this->ilLng->txt('kicked'), true);
528  break;
529 
530  case 'banned':
531  $this->mainTpl->setOnScreenMessage('failure', $this->ilLng->txt('banned'), true);
532  break;
533 
534  default:
535  $this->mainTpl->setOnScreenMessage('failure', $this->ilLng->txt('lost_connection'), true);
536  break;
537  }
538  } else {
539  $this->mainTpl->setOnScreenMessage('failure', $this->ilLng->txt('lost_connection'), true);
540  }
541 
542  $this->ilCtrl->redirectByClass(ilInfoScreenGUI::class, 'info');
543  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ renderLanguageVariables()

ilChatroomViewGUI::renderLanguageVariables ( ilTemplate  $roomTpl)
protected

Definition at line 369 of file class.ilChatroomViewGUI.php.

References HTML_Template_IT\setVariable().

Referenced by showRoom().

369  : void
370  {
371  $js_translations = [
372  'LBL_MAINROOM' => 'chat_mainroom',
373  'LBL_LEAVE_PRIVATE_ROOM' => 'leave_private_room',
374  'LBL_LEFT_PRIVATE_ROOM' => 'left_private_room',
375  'LBL_JOIN' => 'chat_join',
376  'LBL_DELETE_PRIVATE_ROOM' => 'delete_private_room',
377  'LBL_DELETE_PRIVATE_ROOM_QUESTION' => 'delete_private_room_question',
378  'LBL_INVITE_TO_PRIVATE_ROOM' => 'invite_to_private_room',
379  'LBL_KICK' => 'chat_kick',
380  'LBL_BAN' => 'chat_ban',
381  'LBL_KICK_QUESTION' => 'kick_question',
382  'LBL_BAN_QUESTION' => 'ban_question',
383  'LBL_ADDRESS' => 'chat_address',
384  'LBL_WHISPER' => 'chat_whisper',
385  'LBL_CONNECT' => 'chat_connection_established',
386  'LBL_DISCONNECT' => 'chat_connection_disconnected',
387  'LBL_TO_MAINROOM' => 'chat_to_mainroom',
388  'LBL_CREATE_PRIVATE_ROOM_JS' => 'chat_create_private_room_button',
389  'LBL_WELCOME_TO_CHAT' => 'welcome_to_chat',
390  'LBL_USER_INVITED' => 'user_invited',
391  'LBL_USER_KICKED' => 'user_kicked',
392  'LBL_USER_INVITED_SELF' => 'user_invited_self',
393  'LBL_PRIVATE_ROOM_CLOSED' => 'private_room_closed',
394  'LBL_PRIVATE_ROOM_ENTERED' => 'private_room_entered',
395  'LBL_PRIVATE_ROOM_LEFT' => 'private_room_left',
396  'LBL_PRIVATE_ROOM_ENTERED_USER' => 'private_room_entered_user',
397  'LBL_KICKED_FROM_PRIVATE_ROOM' => 'kicked_from_private_room',
398  'LBL_OK' => 'ok',
399  'LBL_INVITE' => 'chat_invite',
400  'LBL_CANCEL' => 'cancel',
401  'LBL_WHISPER_TO' => 'whisper_to',
402  'LBL_SPEAK_TO' => 'speak_to',
403  'LBL_HISTORY_CLEARED' => 'history_cleared',
404  'LBL_CLEAR_ROOM_HISTORY' => 'clear_room_history',
405  'LBL_CLEAR_ROOM_HISTORY_QUESTION' => 'clear_room_history_question',
406  'LBL_END_WHISPER' => 'end_whisper',
407  'LBL_TIMEFORMAT' => 'lang_timeformat_no_sec',
408  'LBL_DATEFORMAT' => 'lang_dateformat'
409  ];
410  foreach ($js_translations as $placeholder => $lng_variable) {
411  $roomTpl->setVariable($placeholder, json_encode($this->ilLng->txt($lng_variable), JSON_THROW_ON_ERROR));
412  }
413  $this->ilLng->toJSMap([
414  'chat_user_x_is_typing' => $this->ilLng->txt('chat_user_x_is_typing'),
415  'chat_users_are_typing' => $this->ilLng->txt('chat_users_are_typing'),
416  ]);
417 
418  $roomTpl->setVariable('LBL_CREATE_PRIVATE_ROOM', $this->ilLng->txt('chat_create_private_room_button'));
419  $roomTpl->setVariable('LBL_CREATE_PRIVATE_ROOM_TEXT', $this->ilLng->txt('create_private_room_text'));
420  $roomTpl->setVariable('LBL_LAYOUT', $this->ilLng->txt('layout'));
421  $roomTpl->setVariable('LBL_SHOW_SETTINGS', $this->ilLng->txt('show_settings'));
422  $roomTpl->setVariable('LBL_USER_IN_ROOM', $this->ilLng->txt('user_in_room'));
423  $roomTpl->setVariable('LBL_USER_IN_ILIAS', $this->ilLng->txt('user_in_ilias'));
424  }
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderRightUsersBlock()

ilChatroomViewGUI::renderRightUsersBlock ( ilTemplate  $roomTpl)
protected

Definition at line 426 of file class.ilChatroomViewGUI.php.

References HTML_Template_IT\setVariable().

Referenced by showRoom().

426  : void
427  {
428  $roomTpl->setVariable('LBL_NO_FURTHER_USERS', $this->ilLng->txt('no_further_users'));
429  }
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderSendMessageBox()

ilChatroomViewGUI::renderSendMessageBox ( ilTemplate  $roomTpl)
protected

Definition at line 360 of file class.ilChatroomViewGUI.php.

References HTML_Template_IT\setVariable().

Referenced by showRoom().

360  : void
361  {
362  $roomTpl->setVariable('LBL_MESSAGE', $this->ilLng->txt('chat_message'));
363  $roomTpl->setVariable('LBL_TOALL', $this->ilLng->txt('chat_message_to_all'));
364  $roomTpl->setVariable('LBL_OPTIONS', $this->ilLng->txt('chat_message_options'));
365  $roomTpl->setVariable('LBL_DISPLAY', $this->ilLng->txt('chat_message_display'));
366  $roomTpl->setVariable('LBL_SEND', $this->ilLng->txt('send'));
367  }
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setupTemplate()

ilChatroomViewGUI::setupTemplate ( )
private

Adds CSS and JavaScript files that should be included in the header.

Definition at line 78 of file class.ilChatroomViewGUI.php.

Referenced by executeDefault(), and joinWithCustomName().

78  : void
79  {
80  $this->mainTpl->addJavaScript('Modules/Chatroom/js/chat.js');
81  $this->mainTpl->addJavaScript('Modules/Chatroom/js/iliaschat.jquery.js');
82  $this->mainTpl->addJavaScript('node_modules/jquery-outside-events/jquery.ba-outside-events.js');
83  $this->mainTpl->addJavaScript('./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js');
84 
85  $this->mainTpl->addCss('Modules/Chatroom/templates/default/style.css');
86 
87  $this->mainTpl->setPermanentLink($this->gui->getObject()->getType(), $this->gui->getObject()->getRefId());
88  }
+ Here is the caller graph for this function:

◆ showNameSelection()

ilChatroomViewGUI::showNameSelection ( ilChatroomUser  $chat_user)
private

Definition at line 431 of file class.ilChatroomViewGUI.php.

References ilChatroomUser\getChatNameSuggestions().

Referenced by executeDefault(), and joinWithCustomName().

431  : void
432  {
433  $name_options = $chat_user->getChatNameSuggestions();
434  $formFactory = new ilChatroomFormFactory();
435  $selectionForm = $formFactory->getUserChatNameSelectionForm($name_options);
436 
437  $this->ilCtrl->saveParameter($this->gui, 'sub');
438 
439  $selectionForm->addCommandButton('view-joinWithCustomName', $this->ilLng->txt('enter'));
440  $selectionForm->setFormAction(
441  $this->ilCtrl->getFormAction($this->gui, 'view-joinWithCustomName')
442  );
443 
444  $this->mainTpl->setVariable('ADM_CONTENT', $selectionForm->getHTML());
445  }
Class ilChatroomFormFactory.
getChatNameSuggestions()
Returns an array of chat-name suggestions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showRoom()

ilChatroomViewGUI::showRoom ( ilChatroom  $room,
ilChatroomUser  $chat_user 
)
private

Prepares and displays chatroom and connects user to it.

Parameters
ilChatroom$room
ilChatroomUser$chat_user

Definition at line 95 of file class.ilChatroomViewGUI.php.

References $id, ILIAS\LTI\ToolProvider\$key, $params, $ref_id, $response, $scope, ILIAS\LTI\ToolProvider\$settings, cancelJoin(), ilChatroom\checkUserPermissions(), ilChatroom\connectUser(), ilChatroomUser\enabledBroadcastTyping(), ilChatroom\getActivePrivateRooms(), ilChatroom\getConnectedUsers(), ilUtil\getImagePath(), ilPanelGUI\getInstance(), ilChatroom\getLastMessages(), ilChatroomGUIHandler\getRequestValue(), ilChatroom\getRoomId(), ilChatroom\getSetting(), ilChatroomUser\getUserId(), ilChatroomUser\getUsername(), ilChatroomGUIHandler\hasRequestValue(), ilPanelGUI\HEADING_STYLE_BLOCK, ilModalGUI\initJS(), ilChatroom\isAllowedToEnterPrivateRoom(), ilChatroom\isSubscribed(), ilChatroomGUIHandler\isSuccessful(), ilChatroom\isUserBanned(), ilPanelGUI\PANEL_STYLE_SECONDARY, ilChatroomGUIHandler\redirectIfNoPermission(), ILIAS\Repository\refinery(), renderLanguageVariables(), renderRightUsersBlock(), renderSendMessageBox(), ilChatroom\subscribeUserToPrivateRoom(), and ILIAS\UI\Implementation\Component\withOnLoadCode().

Referenced by executeDefault(), and joinWithCustomName().

95  : void
96  {
97  $this->redirectIfNoPermission('read');
98 
99  $user_id = $chat_user->getUserId();
100 
101  $ref_id = $this->getRequestValue('ref_id', $this->refinery->kindlyTo()->int());
102  $this->navigationHistory->addItem(
103  $ref_id,
104  $this->ilCtrl->getLinkTargetByClass(ilRepositoryGUI::class, 'view'),
105  'chtr'
106  );
107 
108  if ($room->isUserBanned($user_id)) {
109  $this->cancelJoin($this->ilLng->txt('banned'));
110  return;
111  }
112 
113  $scope = $room->getRoomId();
114  $connector = $this->gui->getConnector();
115  $response = $connector->connect($scope, $user_id);
116 
117  if (!$response) {
118  $this->mainTpl->setOnScreenMessage('failure', $this->ilLng->txt('unable_to_connect'), true);
119  $this->ilCtrl->redirectByClass(ilInfoScreenGUI::class, 'info');
120  }
121 
122  if (!$room->isSubscribed($chat_user->getUserId())) {
123  $room->connectUser($chat_user);
124  }
125 
126  $subScope = 0;
127  $response = $connector->sendEnterPrivateRoom($scope, $subScope, $user_id);
128  if (!$response) {
129  $this->mainTpl->setOnScreenMessage('failure', $this->ilLng->txt('unable_to_connect'), true);
130  $this->ilCtrl->redirectByClass('ilinfoscreengui', 'info');
131  }
132 
133  $settings = $connector->getSettings();
134  $known_private_room = $room->getActivePrivateRooms($this->ilUser->getId());
135 
136  $initial = new stdClass();
137  $initial->users = $room->getConnectedUsers();
138  $initial->private_rooms = array_values($known_private_room);
139  $initial->redirect_url = $this->ilCtrl->getLinkTarget($this->gui, 'view-lostConnection', '', false);
140  $initial->profile_image_url = $this->ilCtrl->getLinkTarget($this->gui, 'view-getUserProfileImages', '', true);
141  $initial->no_profile_image_url = ilUtil::getImagePath('no_photo_xxsmall.jpg');
142  $initial->private_rooms_enabled = (bool) $room->getSetting('private_rooms_enabled');
143  $initial->subdirectory = $settings->getSubDirectory();
144 
145  $initial->userinfo = [
146  'moderator' => ilChatroom::checkUserPermissions('moderate', $ref_id, false),
147  'id' => $chat_user->getUserId(),
148  'login' => $chat_user->getUsername(),
149  'broadcast_typing' => $chat_user->enabledBroadcastTyping(),
150  ];
151 
152  $smileys = [];
153 
154  if ($settings->getSmiliesEnabled()) {
155  $smileys_array = ilChatroomSmilies::_getSmilies();
156  foreach ($smileys_array as $smiley_array) {
157  $new_keys = [];
158  $new_val = '';
159  foreach ($smiley_array as $key => $value) {
160  if ($key === 'smiley_keywords') {
161  $new_keys = explode("\n", $value);
162  }
163 
164  if ($key === 'smiley_fullpath') {
165  $new_val = $value;
166  }
167  }
168 
169  if (!$new_keys || !$new_val) {
170  continue;
171  }
172 
173  foreach ($new_keys as $new_key) {
174  $smileys[$new_key] = $new_val;
175  }
176  }
177 
178  $initial->smileys = $smileys;
179  } else {
180  $initial->smileys = '{}';
181  }
182 
183  $initial->messages = [];
184 
185  $sub = null;
186  if ($this->hasRequestValue('sub')) {
187  $sub = $this->getRequestValue('sub', $this->refinery->kindlyTo()->int());
188  }
189 
190  if ($sub !== null) {
191  if ($known_private_room[$sub]) {
192  if (!$room->isAllowedToEnterPrivateRoom($chat_user->getUserId(), $sub)) {
193  $initial->messages[] = [
194  'type' => 'error',
195  'message' => $this->ilLng->txt('not_allowed_to_enter'),
196  ];
197  } else {
198  $scope = $room->getRoomId();
199  $params = [];
200  $params['user'] = $chat_user->getUserId();
201  $params['sub'] = $sub;
202 
203  $params['message'] = json_encode([
204  'type' => 'private_room_entered',
205  'user' => $user_id
206  ], JSON_THROW_ON_ERROR);
207 
208  $connector = $this->gui->getConnector();
209  $response = $connector->sendEnterPrivateRoom($scope, $sub, $chat_user->getUserId());
210 
211  if ($this->isSuccessful($response)) {
212  $room->subscribeUserToPrivateRoom($params['sub'], $params['user']);
213  }
214 
215  $initial->enter_room = $sub;
216  }
217  } else {
218  $initial->messages[] = [
219  'type' => 'error',
220  'message' => $this->ilLng->txt('user_invited'),
221  ];
222  }
223  }
224 
225  if ((int) $room->getSetting('display_past_msgs')) {
226  $initial->messages = array_merge(
227  $initial->messages,
228  array_reverse($room->getLastMessages($room->getSetting('display_past_msgs'), $chat_user))
229  );
230  }
231 
232  $roomTpl = new ilTemplate('tpl.chatroom.html', true, true, 'Modules/Chatroom');
233  $roomTpl->setVariable('BASEURL', $settings->generateClientUrl());
234  $roomTpl->setVariable('INSTANCE', $settings->getInstance());
235  $roomTpl->setVariable('SCOPE', $scope);
236  $roomTpl->setVariable('POSTURL', $this->ilCtrl->getLinkTarget($this->gui, 'postMessage', '', true));
237 
238  $roomTpl->setVariable('ACTIONS', $this->ilLng->txt('actions'));
239  $roomTpl->setVariable('LBL_CREATE_PRIVATE_ROOM', $this->ilLng->txt('create_private_room_label'));
240  $roomTpl->setVariable('LBL_USER', $this->ilLng->txt('user'));
241  $roomTpl->setVariable('LBL_USER_TEXT', $this->ilLng->txt('invite_username'));
242  $showAutoMessages = true;
243  if ($this->ilUser->getPref('chat_hide_automsg_' . $room->getRoomId())) {
244  $showAutoMessages = false;
245  }
246 
247  $roomTpl->setVariable(
248  'TOGGLE_SCROLLING_COMPONENT',
249  $this->uiRenderer->render(
250  $this->uiFactory->button()->toggle(
251  $this->ilLng->txt('auto_scroll'),
252  '#',
253  '#',
254  true
255  )
256  ->withAriaLabel($this->ilLng->txt('auto_scroll'))
257  ->withOnLoadCode(static function (string $id): string {
258  return '
259  $("#' . $id . '")
260  .on("click", function(e) {
261  let t = $(this), msg = $("#chat_messages");
262  if (t.hasClass("on")) {
263  msg.trigger("msg-scrolling:toggle", [true]);
264  } else {
265  msg.trigger("msg-scrolling:toggle", [false]);
266  }
267  });
268  ';
269  })
270  )
271  );
272 
273  $toggleUrl = $this->ilCtrl->getFormAction($this->gui, 'view-toggleAutoMessageDisplayState', '', true, false);
274  $roomTpl->setVariable(
275  'TOGGLE_AUTO_MESSAGE_COMPONENT',
276  $this->uiRenderer->render(
277  $this->uiFactory->button()->toggle(
278  $this->ilLng->txt('chat_show_auto_messages'),
279  '#',
280  '#',
281  $showAutoMessages
282  )
283  ->withAriaLabel($this->ilLng->txt('chat_show_auto_messages'))
284  ->withOnLoadCode(static function (string $id) use ($toggleUrl): string {
285  return '
286  $("#' . $id . '")
287  .on("click", function(e) {
288  let t = $(this), msg = $("#chat_messages");
289  if (t.hasClass("on")) {
290  msg.trigger("auto-message:toggle", [true, "' . $toggleUrl . '"]);
291  } else {
292  msg.trigger("auto-message:toggle", [false, "' . $toggleUrl . '"]);
293  }
294  });
295  ';
296  })
297  )
298  );
299 
300  $initial->state = new stdClass();
301  $initial->state->scrolling = true;
302  $initial->state->show_auto_msg = $showAutoMessages;
303 
304  $roomTpl->setVariable('INITIAL_DATA', json_encode($initial, JSON_THROW_ON_ERROR));
305  $roomTpl->setVariable('INITIAL_USERS', json_encode($room->getConnectedUsers(), JSON_THROW_ON_ERROR));
306 
307  $this->renderSendMessageBox($roomTpl);
308  $this->renderLanguageVariables($roomTpl);
309 
311 
312  $roomRightTpl = new ilTemplate('tpl.chatroom_right.html', true, true, 'Modules/Chatroom');
313  $this->renderRightUsersBlock($roomRightTpl);
314 
315  $right_content_panel = ilPanelGUI::getInstance();
316  $right_content_panel->setHeading($this->ilLng->txt('users'));
317  $right_content_panel->setPanelStyle(ilPanelGUI::PANEL_STYLE_SECONDARY);
318  $right_content_panel->setHeadingStyle(ilPanelGUI::HEADING_STYLE_BLOCK);
319  $right_content_panel->setBody($roomRightTpl->get());
320 
321  $this->mainTpl->setContent($roomTpl->get());
322  $this->mainTpl->setRightContent($right_content_panel->getHTML());
323  }
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
getSetting(string $name)
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
getUserId()
Returns Ilias User ID.
$scope
Definition: ltiregstart.php:53
renderLanguageVariables(ilTemplate $roomTpl)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static initJS(ilGlobalTemplateInterface $a_main_tpl=null)
getRequestValue(string $key, Transformation $trafo, $default=null)
getLastMessages(int $number, ilChatroomUser $chatuser)
renderSendMessageBox(ilTemplate $roomTpl)
getConnectedUsers(bool $only_data=true)
cancelJoin(string $message)
Calls ilUtil::sendFailure method using given $message as parameter.
$ref_id
Definition: ltiauth.php:67
isSubscribed(int $chat_userid)
string $key
Consumer key/client ID value.
Definition: System.php:193
isUserBanned(int $user_id)
isSuccessful($response)
Checks for success param in an json decoded response.
connectUser(ilChatroomUser $user)
isAllowedToEnterPrivateRoom(int $chat_userid, int $proom_id)
static getInstance()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const PANEL_STYLE_SECONDARY
getUsername()
Returns username from Object or SESSION.
const HEADING_STYLE_BLOCK
subscribeUserToPrivateRoom(int $room_id, int $user_id)
$response
renderRightUsersBlock(ilTemplate $roomTpl)
getActivePrivateRooms(int $userid)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toggleAutoMessageDisplayState()

ilChatroomViewGUI::toggleAutoMessageDisplayState ( )

Definition at line 325 of file class.ilChatroomViewGUI.php.

References ilObjUser\_writePref(), ilChatroom\byObjectId(), ILIAS\FileDelivery\http(), ilChatroomGUIHandler\redirectIfNoPermission(), and ILIAS\Repository\refinery().

325  : void
326  {
327  $this->redirectIfNoPermission('read');
328 
329  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
330 
331  $state = 0;
332  if ($this->http->wrapper()->post()->has('state')) {
333  $state = $this->http->wrapper()->post()->retrieve('state', $this->refinery->kindlyTo()->int());
334  }
335 
337  $this->ilUser->getId(),
338  'chat_hide_automsg_' . $room->getRoomId(),
339  (string) ((int) (!(bool) $state))
340  );
341 
342  $this->http->saveResponse(
343  $this->http->response()
344  ->withHeader(ResponseHeader::CONTENT_TYPE, 'application/json')
345  ->withBody(Streams::ofString(json_encode(['success' => true], JSON_THROW_ON_ERROR)))
346  );
347  $this->http->sendResponse();
348  $this->http->close();
349  }
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
static http()
Fetches the global http state from ILIAS.
static byObjectId(int $object_id)
static _writePref(int $a_usr_id, string $a_keyword, string $a_value)
+ Here is the call graph for this function:

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