ILIAS  release_8 Revision v8.23
ilChatroomHistoryGUI Class Reference

Class ilChatroom Keeps methods to prepare and display the history task. More...

+ Inheritance diagram for ilChatroomHistoryGUI:
+ Collaboration diagram for ilChatroomHistoryGUI:

Public Member Functions

 byDayExport ()
 
 byDay (bool $export=false)
 
 bySessionExport ()
 
 bySession (bool $export=false)
 
 executeDefault (string $requestedMethod)
 
- 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)
 

Private Member Functions

 renderDateTimeInformation ( $room_tpl, ?ilDateTime &$prev_date_time, ilDateTime $message_date_time, ilDate $message_date, ?string &$prev_date_time_presentation, string $message_date_time_presentation, string $time_format)
 
 showMessages (array $messages, ilPropertyFormGUI $durationForm, bool $export=false, array $psessions=[], ?ilDateTime $from=null, ?ilDateTime $to=null)
 

Additional Inherited Members

- 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)
 
- 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 ilChatroom Keeps methods to prepare and display the history task.

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

Definition at line 28 of file class.ilChatroomHistoryGUI.php.

Member Function Documentation

◆ byDay()

ilChatroomHistoryGUI::byDay ( bool  $export = false)

Definition at line 83 of file class.ilChatroomHistoryGUI.php.

References $messages, $scope, ilChatroom\byObjectId(), ilChatroomGUIHandler\exitIfNoRoomExists(), ilChatroomGUIHandler\getRequestValue(), ILIAS\FileDelivery\http(), ILIAS\Repository\refinery(), and showMessages().

Referenced by byDayExport(), and executeDefault().

83  : void
84  {
85  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
86  $this->exitIfNoRoomExists($room);
87 
88  $scope = $room->getRoomId();
89 
90  $chat_user = new ilChatroomUser($this->ilUser, $room);
91  $formFactory = new ilChatroomFormFactory();
92 
93  $durationForm = $formFactory->getPeriodForm();
94  $durationForm->setTitle($this->ilLng->txt('history_byday_title'));
95  $durationForm->addCommandButton('history-byDayExport', $this->ilLng->txt('export'));
96  $durationForm->addCommandButton('history-byDay', $this->ilLng->txt('show'));
97  $durationForm->setFormAction($this->ilCtrl->getFormAction($this->gui, 'history-byDay'));
98 
99  $messages = [];
100  $psessions = [];
101  $submit_request = strtolower($this->http->request()->getServerParams()['REQUEST_METHOD']) === 'post';
102  $from = null;
103  $to = null;
104 
105  if ($submit_request) {
106  if ($durationForm->checkInput()) {
107  $period = $durationForm->getItemByPostVar('timeperiod');
108 
109  $messages = $room->getHistory(
110  $from = $period->getStart(),
111  $to = $period->getEnd(),
112  $chat_user->getUserId(),
113  $this->getRequestValue('scope', $this->refinery->kindlyTo()->int(), 0)
114  );
115 
116  $psessions = $room->getPrivateRoomSessions(
117  $from,
118  $to,
119  $chat_user->getUserId(),
120  $scope
121  );
122  } else {
123  $export = false;
124  }
125 
126  $durationForm->setValuesByPost();
127  }
128 
129  $this->showMessages($messages, $durationForm, $export, $psessions, $from, $to);
130  }
$scope
Definition: ltiregstart.php:53
getRequestValue(string $key, Transformation $trafo, $default=null)
exitIfNoRoomExists(?ilChatroom $room)
Checks if a ilChatroom exists.
Class ilChatroomFormFactory.
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: xapiexit.php:22
static http()
Fetches the global http state from ILIAS.
showMessages(array $messages, ilPropertyFormGUI $durationForm, bool $export=false, array $psessions=[], ?ilDateTime $from=null, ?ilDateTime $to=null)
Class ilChatroomUser.
static byObjectId(int $object_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ byDayExport()

ilChatroomHistoryGUI::byDayExport ( )

Definition at line 77 of file class.ilChatroomHistoryGUI.php.

References byDay(), and ILIAS\Repository\tabs().

77  : void
78  {
79  $this->tabs->activateSubTab('byday');
80  $this->byDay(true);
81  }
+ Here is the call graph for this function:

◆ bySession()

ilChatroomHistoryGUI::bySession ( bool  $export = false)

Definition at line 284 of file class.ilChatroomHistoryGUI.php.

References $messages, $scope, $session, ilChatroom\byObjectId(), ilChatroomGUIHandler\exitIfNoRoomExists(), ilChatroomGUIHandler\getRequestValue(), ILIAS\FileDelivery\http(), IL_CAL_UNIX, ILIAS\Repository\refinery(), and showMessages().

Referenced by bySessionExport().

284  : void
285  {
286  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
287  $this->exitIfNoRoomExists($room);
288 
289  $scope = $room->getRoomId();
290 
291  $chat_user = new ilChatroomUser($this->ilUser, $room);
292 
293  $formFactory = new ilChatroomFormFactory();
294  $durationForm = $formFactory->getSessionForm($room->getSessions($chat_user));
295  $durationForm->setTitle($this->ilLng->txt('history_bysession_title'));
296  $durationForm->addCommandButton('history-bySessionExport', $this->ilLng->txt('export'));
297  $durationForm->addCommandButton('history-bySession', $this->ilLng->txt('show'));
298  $durationForm->setFormAction(
299  $this->ilCtrl->getFormAction($this->gui, 'history-bySession')
300  );
301 
302  if (strtolower($this->http->request()->getServerParams()['REQUEST_METHOD']) === 'post') {
303  $session = $this->getRequestValue('session', $this->refinery->kindlyTo()->string());
304  $durationForm->checkInput();
305  $postVals = explode(',', $session);
306  $durationForm->setValuesByArray([
307  'session' => $session
308  ]);
309 
310  $messages = $room->getHistory(
311  $from = new ilDateTime($postVals[0], IL_CAL_UNIX),
312  $to = new ilDateTime($postVals[1], IL_CAL_UNIX),
313  $chat_user->getUserId(),
314  $this->getRequestValue('scope', $this->refinery->kindlyTo()->int(), 0)
315  );
316  } else {
317  $last_session = $room->getLastSession($chat_user);
318 
319  if ($last_session) {
320  $from = new ilDateTime($last_session['connected'], IL_CAL_UNIX);
321  $to = new ilDateTime($last_session['disconnected'], IL_CAL_UNIX);
322  } else {
323  $from = null;
324  $to = null;
325  }
326 
327  $messages = $room->getHistory(
328  $from,
329  $to,
330  $chat_user->getUserId(),
331  $this->getRequestValue('scope', $this->refinery->kindlyTo()->int(), 0)
332  );
333  }
334 
335  $from = new ilDateTime();
336  $to = new ilDateTime();
337  $psessions = [];
338  if ($from && $to) {
339  $psessions = $room->getPrivateRoomSessions(
340  $from,
341  $to,
342  $chat_user->getUserId(),
343  $scope
344  );
345  }
346 
347  $this->showMessages($messages, $durationForm, $export, $psessions, $from, $to);
348  }
$scope
Definition: ltiregstart.php:53
getRequestValue(string $key, Transformation $trafo, $default=null)
$session
exitIfNoRoomExists(?ilChatroom $room)
Checks if a ilChatroom exists.
const IL_CAL_UNIX
Class ilChatroomFormFactory.
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: xapiexit.php:22
static http()
Fetches the global http state from ILIAS.
showMessages(array $messages, ilPropertyFormGUI $durationForm, bool $export=false, array $psessions=[], ?ilDateTime $from=null, ?ilDateTime $to=null)
Class ilChatroomUser.
static byObjectId(int $object_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bySessionExport()

ilChatroomHistoryGUI::bySessionExport ( )

Definition at line 278 of file class.ilChatroomHistoryGUI.php.

References bySession(), and ILIAS\Repository\tabs().

278  : void
279  {
280  $this->tabs->activateSubTab('bysession');
281  $this->bySession(true);
282  }
+ Here is the call graph for this function:

◆ executeDefault()

ilChatroomHistoryGUI::executeDefault ( string  $requestedMethod)

Definition at line 350 of file class.ilChatroomHistoryGUI.php.

References byDay().

350  : void
351  {
352  $this->byDay();
353  }
+ Here is the call graph for this function:

◆ renderDateTimeInformation()

ilChatroomHistoryGUI::renderDateTimeInformation (   $room_tpl,
?ilDateTime $prev_date_time,
ilDateTime  $message_date_time,
ilDate  $message_date,
?string &  $prev_date_time_presentation,
string  $message_date_time_presentation,
string  $time_format 
)
private
Parameters
ilTemplate | ilGlobalTemplate$room_tpl

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

References ILIAS\LTI\ToolProvider\$key, ilDatePresentation\formatDate(), ilDateTime\get(), IL_CAL_FKT_DATE, IL_CAL_UNIX, ilCalendarSettings\TIME_FORMAT_12, and ilCalendarSettings\TIME_FORMAT_24.

Referenced by showMessages().

41  : void {
42  $render_parts = [];
43 
44  if (null === $prev_date_time ||
45  date('d', $prev_date_time->get(IL_CAL_UNIX)) !== date('d', $message_date_time->get(IL_CAL_UNIX)) ||
46  date('m', $prev_date_time->get(IL_CAL_UNIX)) !== date('m', $message_date_time->get(IL_CAL_UNIX)) ||
47  date('Y', $prev_date_time->get(IL_CAL_UNIX)) !== date('Y', $message_date_time->get(IL_CAL_UNIX))
48  ) {
49  $render_parts['MESSAGEDATE'] = ilDatePresentation::formatDate($message_date);
50  $prev_date_time = $message_date_time;
51  }
52 
53  if ($prev_date_time_presentation !== $message_date_time_presentation) {
54  switch ($time_format) {
56  $date_string = $message_date_time->get(IL_CAL_FKT_DATE, 'H:i', $this->ilUser->getTimeZone());
57  break;
59  default:
60  $date_string = $message_date_time->get(IL_CAL_FKT_DATE, 'g:ia', $this->ilUser->getTimeZone());
61  break;
62  }
63 
64  $render_parts['MESSAGETIME'] = $date_string;
65  $prev_date_time_presentation = $message_date_time_presentation;
66  }
67 
68  if ($render_parts !== []) {
69  $room_tpl->setCurrentBlock('datetime_line');
70  foreach ($render_parts as $key => $value) {
71  $room_tpl->setVariable($key, $value);
72  }
73  $room_tpl->parseCurrentBlock();
74  }
75  }
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
const IL_CAL_FKT_DATE
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showMessages()

ilChatroomHistoryGUI::showMessages ( array  $messages,
ilPropertyFormGUI  $durationForm,
bool  $export = false,
array  $psessions = [],
?ilDateTime  $from = null,
?ilDateTime  $to = null 
)
private

Definition at line 132 of file class.ilChatroomHistoryGUI.php.

References $message, $scopes, $session, ilPropertyFormGUI\addItem(), ilUtil\deliverData(), ilDatePresentation\formatDate(), ilDatePresentation\formatPeriod(), ilFileUtils\getASCIIFilename(), ilPropertyFormGUI\getHTML(), ilChatroomGUIHandler\getRequestValue(), ilChatroomGUIHandler\hasRequestValue(), IL_CAL_UNIX, ilChatroomGUIHandler\redirectIfNoPermission(), ILIAS\Repository\refinery(), renderDateTimeInformation(), ilDatePresentation\setUseRelativeDates(), and ilDatePresentation\useRelativeDates().

Referenced by byDay(), and bySession().

139  : void {
140  $this->redirectIfNoPermission('read');
141 
142  $this->gui->switchToVisibleMode();
143 
144  $this->mainTpl->addCss('Modules/Chatroom/templates/default/style.css');
145 
146  // should be able to grep templates
147  if ($export) {
148  $roomTpl = new ilGlobalTemplate('tpl.history_export.html', true, true, 'Modules/Chatroom');
149  } else {
150  $roomTpl = new ilTemplate('tpl.history.html', true, true, 'Modules/Chatroom');
151  }
152 
153  $scopes = [];
154  $isScopeRequest = $this->hasRequestValue('scope');
155  $requestScope = $this->getRequestValue('scope', $this->refinery->kindlyTo()->int(), 0);
156 
157  if ($export) {
159  }
160 
161  $time_format = $this->ilUser->getTimeFormat();
162 
163  $messagesShown = 0;
164  $prev_date_time_presentation = null;
165  $prev_date_time = null;
166  foreach ($messages as $message) {
167  switch ($message['message']->type) {
168  case 'message':
169  if (
170  !$message['message']->subRoomId ||
171  (
172  $isScopeRequest &&
173  (int) $message['message']->subRoomId === $requestScope
174  )
175  ) {
176  $date = new ilDate($message['timestamp'], IL_CAL_UNIX);
177  $dateTime = new ilDateTime($message['timestamp'], IL_CAL_UNIX);
178  $currentDate = ilDatePresentation::formatDate($dateTime);
179 
181  $roomTpl,
182  $prev_date_time,
183  $dateTime,
184  $date,
185  $prev_date_time_presentation,
186  $currentDate,
187  $time_format
188  );
189 
190  $roomTpl->setCurrentBlock('message_line');
191  $roomTpl->setVariable('MESSAGECONTENT', $message['message']->content); // oops... it is a message? ^^
192  $roomTpl->setVariable('MESSAGESENDER', $message['message']->from->username);
193  $roomTpl->parseCurrentBlock();
194 
195  $roomTpl->setCurrentBlock('row');
196  $roomTpl->parseCurrentBlock();
197 
198  ++$messagesShown;
199  }
200  break;
201  }
202  }
203 
204  foreach ($psessions as $session) {
205  $scopes[$session['proom_id']] = $session['title'];
206  }
207 
208  if (isset($scopes[''])) {
209  unset($scopes['']);
210  }
211 
212  if (!$messagesShown) {
213  $roomTpl->setVariable('LBL_NO_MESSAGES', $this->ilLng->txt('no_messages'));
214  }
215 
216  asort($scopes, SORT_STRING);
217 
218  $scopes = [$this->ilLng->txt('main')] + $scopes;
219 
220  if (count($scopes) > 1) {
221  $select = new ilSelectInputGUI($this->ilLng->txt('scope'), 'scope');
222  $select->setOptions($scopes);
223 
224  if ($isScopeRequest) {
225  $select->setValue($requestScope);
226  }
227 
228  $durationForm->addItem($select);
229  }
230 
231  $prevUseRelDates = ilDatePresentation::useRelativeDates();
233 
234  if ($from instanceof ilDateTime && $to instanceof ilDateTime) {
235  $unixFrom = $from->getUnixTime();
236  $unixTo = $to->getUnixTime();
237 
238  if ($unixFrom === $unixTo) {
239  $date = new ilDate($unixFrom, IL_CAL_UNIX);
240  $date_sub = ilDatePresentation::formatDate($date);
241  } else {
242  $date1 = new ilDate($unixFrom, IL_CAL_UNIX);
243  $date2 = new ilDate($unixTo, IL_CAL_UNIX);
244  $date_sub = ilDatePresentation::formatPeriod($date1, $date2);
245  }
246  ilDatePresentation::setUseRelativeDates($prevUseRelDates);
247 
248  $isPrivateRoom = $isScopeRequest;
249  if ($isPrivateRoom) {
250  $roomTpl->setVariable(
251  'ROOM_TITLE',
252  sprintf(
253  $this->ilLng->txt('history_title_private_room'),
254  $scopes[$requestScope]
255  ) . ' (' . $date_sub . ')'
256  );
257  } else {
258  $roomTpl->setVariable(
259  'ROOM_TITLE',
260  sprintf($this->ilLng->txt('history_title_general'), $this->gui->getObject()->getTitle()) . ' (' . $date_sub . ')'
261  );
262  }
263  }
264 
265  if ($export) {
267  $roomTpl->get(),
268  ilFileUtils::getASCIIFilename($scopes[$requestScope] . '.html'),
269  'text/html'
270  );
271  }
272 
273  $roomTpl->setVariable('PERIOD_FORM', $durationForm->getHTML());
274 
275  $this->mainTpl->setVariable('ADM_CONTENT', $roomTpl->get());
276  }
special template class to simplify handling of ITX/PEAR
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
$scopes
Definition: ltitoken.php:99
getRequestValue(string $key, Transformation $trafo, $default=null)
$session
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
const IL_CAL_UNIX
renderDateTimeInformation( $room_tpl, ?ilDateTime &$prev_date_time, ilDateTime $message_date_time, ilDate $message_date, ?string &$prev_date_time_presentation, string $message_date_time_presentation, string $time_format)
static getASCIIFilename(string $a_filename)
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: xapiexit.php:22
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false)
Format a period of two dates Shows: 14.
$message
Definition: xapiexit.php:32
static setUseRelativeDates(bool $a_status)
set use relative dates
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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