ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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

 __construct (ilChatroomObjectGUI $gui)
 {} More...
 
 byDayExport ()
 
 byDay ($export=false)
 Prepares and displays history period form by day. More...
 
 bySessionExport ()
 
 bySession ($export=false)
 Prepares and displays history period form by session. More...
 
 executeDefault ($requestedMethod)
 
- Public Member Functions inherited from ilChatroomGUIHandler
 __construct (ilChatroomObjectGUI $gui)
 
 execute ($method)
 Executes given $method if existing, otherwise executes executeDefault() method. More...
 
 executeDefault ($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)
 Sends a json encoded response and exits the php process. More...
 
 hasPermission ($permission)
 Checks for access with ilRbacSystem. More...
 

Private Member Functions

 showMessages ($messages, $durationForm, $export=false, $psessions=array(), $from=null, $to=null)
 Prepares history table and displays it. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ilChatroomGUIHandler
 getRoomByObjectId ($objectId)
 
 exitIfNoRoomExists ($room)
 Checks if a ilChatroom exists. More...
 
 exitIfNoRoomPermission ($room, $subRoom, $chat_user)
 Check if user can moderate a chatroom. More...
 
 canModerate ($room, $subRoom, $user_id)
 Checks if the user has permission to moderate a ilChatroom. More...
 
 isMainRoom ($subRoomId)
 
- Protected Attributes inherited from ilChatroomGUIHandler
 $gui
 
 $ilUser
 
 $ilCtrl
 
 $ilLng
 
 $webDirectory
 
 $obj_service
 
 $upload
 
 $rbacsystem
 
 $mainTpl
 
 $ilias
 
 $navigationHistory
 
 $tree
 
 $tabs
 

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 11 of file class.ilChatroomHistoryGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilChatroomHistoryGUI::__construct ( ilChatroomObjectGUI  $gui)

{}

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

References ILIAS\GlobalScreen\Provider\__construct().

17  {
18  parent::__construct($gui);
19  require_once 'Modules/Chatroom/classes/class.ilChatroomFormFactory.php';
20  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
21  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
22  }
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ byDay()

ilChatroomHistoryGUI::byDay (   $export = false)

Prepares and displays history period form by day.

Parameters
bool$export

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

References $_SERVER, $messages, ilChatroom\byObjectId(), ilCtrl\getFormAction(), and showMessages().

Referenced by byDayExport(), and executeDefault().

35  {
36  $room = ilChatroom::byObjectId($this->gui->object->getId());
37 
38  $this->mainTpl->addJavaScript('./Services/Form/js/date_duration.js');
39 
40  $scope = $room->getRoomId();
41 
42  $chat_user = new ilChatroomUser($this->ilUser, $room);
43  $formFactory = new ilChatroomFormFactory();
44 
45  $durationForm = $formFactory->getPeriodForm();
46  $durationForm->setTitle($this->ilLng->txt('history_byday_title'));
47  $durationForm->addCommandButton('history-byDayExport', $this->ilLng->txt('export'));
48  $durationForm->addCommandButton('history-byDay', $this->ilLng->txt('show'));
49  $durationForm->setFormAction($this->ilCtrl->getFormAction($this->gui, 'history-byDay'));
50 
51  $messages = array();
52  $psessions = array();
53  $submit_request = strtolower($_SERVER['REQUEST_METHOD']) == 'post';
54  $from = null;
55  $to = null;
56 
57  if ($submit_request) {
58  if ($durationForm->checkInput()) {
59  $period = $durationForm->getItemByPostVar('timeperiod');
60 
61  $messages = $room->getHistory(
62  $from = $period->getStart(),
63  $to = $period->getEnd(),
64  $chat_user->getUserId(),
65  isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
66  );
67 
68  $psessions = $room->getPrivateRoomSessions(
69  $from,
70  $to,
71  $chat_user->getUserId(),
72  $scope
73  );
74  } else {
75  $export = false;
76  }
77 
78  $durationForm->setValuesByPost();
79  }
80 
81  $this->showMessages($messages, $durationForm, $export, $psessions, $from, $to);
82  }
This class provides processing control methods.
Class ilChatroomFormFactory.
$messages
Definition: xapiexit.php:5
getFormAction( $a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=false)
Get form action url for gui class object.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
showMessages($messages, $durationForm, $export=false, $psessions=array(), $from=null, $to=null)
Prepares history table and displays it.
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ byDayExport()

ilChatroomHistoryGUI::byDayExport ( )

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

References byDay().

25  {
26  $this->tabs->activateSubTab('byday');
27  $this->byDay(true);
28  }
byDay($export=false)
Prepares and displays history period form by day.
+ Here is the call graph for this function:

◆ bySession()

ilChatroomHistoryGUI::bySession (   $export = false)

Prepares and displays history period form by session.

Parameters
bool$export

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

References $_POST, $_SERVER, $messages, ilChatroom\byObjectId(), ilCtrl\getFormAction(), IL_CAL_UNIX, and showMessages().

Referenced by bySessionExport().

246  {
247  $room = ilChatroom::byObjectId($this->gui->object->getId());
248 
249  $scope = $room->getRoomId();
250 
251  $chat_user = new ilChatroomUser($this->ilUser, $room);
252 
253  $formFactory = new ilChatroomFormFactory();
254  $durationForm = $formFactory->getSessionForm($room->getSessions($chat_user));
255  $durationForm->setTitle($this->ilLng->txt('history_bysession_title'));
256  $durationForm->addCommandButton('history-bySessionExport', $this->ilLng->txt('export'));
257  $durationForm->addCommandButton('history-bySession', $this->ilLng->txt('show'));
258  $durationForm->setFormAction(
259  $this->ilCtrl->getFormAction($this->gui, 'history-bySession')
260  );
261 
262  if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
263  $durationForm->checkInput();
264  $postVals = explode(',', $_POST['session']);
265  $durationForm->setValuesByArray(array('session' => $_POST['session']));
266 
267  $messages = $room->getHistory(
268  $from = new ilDateTime($postVals[0], IL_CAL_UNIX),
269  $to = new ilDateTime($postVals[1], IL_CAL_UNIX),
270  $chat_user->getUserId(),
271  isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
272  );
273  } else {
274  $last_session = $room->getLastSession($chat_user);
275 
276  if ($last_session) {
277  $from = new ilDateTime($last_session['connected'], IL_CAL_UNIX);
278  $to = new ilDateTime($last_session['disconnected'], IL_CAL_UNIX);
279  } else {
280  $from = null;
281  $to = null;
282  }
283 
284  $messages = $room->getHistory(
285  $from,
286  $to,
287  $chat_user->getUserId(),
288  isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
289  );
290  }
291 
292  if ($from && $to) {
293  $psessions = $room->getPrivateRoomSessions(
294  $from,
295  $to,
296  $chat_user->getUserId(),
297  $scope
298  );
299  } else {
300  $from = new ilDateTime();
301  $to = new ilDateTime();
302  $psessions = array();
303  }
304 
305  $psessions = $room->getPrivateRoomSessions(
306  $from,
307  $to,
308  $chat_user->getUserId(),
309  $scope
310  );
311 
312  $this->showMessages($messages, $durationForm, $export, $psessions, $from, $to);
313  }
This class provides processing control methods.
const IL_CAL_UNIX
Class ilChatroomFormFactory.
$messages
Definition: xapiexit.php:5
getFormAction( $a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=false)
Get form action url for gui class object.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
showMessages($messages, $durationForm, $export=false, $psessions=array(), $from=null, $to=null)
Prepares history table and displays it.
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
$_POST["username"]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bySessionExport()

ilChatroomHistoryGUI::bySessionExport ( )

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

References bySession().

236  {
237  $this->tabs->activateSubTab('bysession');
238  $this->bySession(true);
239  }
bySession($export=false)
Prepares and displays history period form by session.
+ Here is the call graph for this function:

◆ executeDefault()

ilChatroomHistoryGUI::executeDefault (   $requestedMethod)

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

References byDay().

319  {
320  $this->byDay();
321  }
byDay($export=false)
Prepares and displays history period form by day.
+ Here is the call graph for this function:

◆ showMessages()

ilChatroomHistoryGUI::showMessages (   $messages,
  $durationForm,
  $export = false,
  $psessions = array(),
  $from = null,
  $to = null 
)
private

Prepares history table and displays it.

Parameters
$messages
$durationForm
bool$export
array$psessions
$from
$to

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

References $message, $messages, $session, ilChatroom\byObjectId(), exit, ilDatePresentation\formatDate(), ilDatePresentation\formatPeriod(), IL_CAL_FKT_DATE, IL_CAL_UNIX, ilChatroomGUIHandler\redirectIfNoPermission(), ilDatePresentation\setUseRelativeDates(), ilCalendarSettings\TIME_FORMAT_12, ilCalendarSettings\TIME_FORMAT_24, and ilDatePresentation\useRelativeDates().

Referenced by byDay(), and bySession().

94  {
95  include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
96 
97  $this->redirectIfNoPermission('read');
98 
99  $this->gui->switchToVisibleMode();
100 
101  $this->mainTpl->addCSS('Modules/Chatroom/templates/default/style.css');
102 
103  // should be able to grep templates
104  if ($export) {
105  $roomTpl = new ilGlobalTemplate('tpl.history_export.html', true, true, 'Modules/Chatroom');
106  } else {
107  $roomTpl = new ilTemplate('tpl.history.html', true, true, 'Modules/Chatroom');
108  }
109 
110  $scopes = array();
111 
112  if ($export) {
114  }
115 
116  $time_format = $this->ilUser->getTimeFormat();
117 
118  $prevDate = '';
119  $messagesShown = 0;
120  $lastDateTime = null;
121  foreach ($messages as $message) {
122  //$message['message']->content = json_decode($message['message']->content);
123 
124  switch ($message['message']->type) {
125  case 'message':
126  if (($_REQUEST['scope'] && $message['message']->subRoomId == $_REQUEST['scope']) || (!$_REQUEST['scope'] && !$message['message']->subRoomId)) {
127  $date = new ilDate($message['timestamp'], IL_CAL_UNIX);
128  $dateTime = new ilDateTime($message['timestamp'], IL_CAL_UNIX);
129  $currentDate = ilDatePresentation::formatDate($dateTime);
130 
131  $roomTpl->setCurrentBlock('MESSAGELINE');
132  $roomTpl->setVariable('MESSAGECONTENT', $message['message']->content); // oops... it is a message? ^^
133  $roomTpl->setVariable('MESSAGESENDER', $message['message']->from->username);
134  if (null == $lastDateTime ||
135  date('d', $lastDateTime->get(IL_CAL_UNIX)) != date('d', $dateTime->get(IL_CAL_UNIX)) ||
136  date('m', $lastDateTime->get(IL_CAL_UNIX)) != date('m', $dateTime->get(IL_CAL_UNIX)) ||
137  date('Y', $lastDateTime->get(IL_CAL_UNIX)) != date('Y', $dateTime->get(IL_CAL_UNIX))
138  ) {
139  $roomTpl->setVariable('MESSAGEDATE', ilDatePresentation::formatDate($date));
140  }
141 
142  if ($prevDate != $currentDate) {
143  switch ($time_format) {
145  $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'H:i', $this->ilUser->getTimeZone());
146  break;
148  default:
149  $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'g:ia', $this->ilUser->getTimeZone());
150  break;
151  }
152 
153  $roomTpl->setVariable('MESSAGETIME', $date_string);
154  $prevDate = $currentDate;
155  }
156 
157  $roomTpl->parseCurrentBlock();
158 
159  $lastDateTime = $dateTime;
160 
161  ++$messagesShown;
162  }
163  break;
164  }
165  }
166 
167  foreach ($psessions as $session) {
168  $scopes[$session['proom_id']] = $session['title'];
169  }
170 
171  if (isset($scopes[''])) {
172  unset($scopes['']);
173  }
174 
175  if (!$messagesShown) {
176  //$roomTpl->touchBlock('NO_MESSAGES');
177  $roomTpl->setVariable('LBL_NO_MESSAGES', $this->ilLng->txt('no_messages'));
178  }
179 
180  asort($scopes, SORT_STRING);
181 
182  $scopes = array($this->ilLng->txt('main')) + $scopes;
183 
184  if (count($scopes) > 1) {
185  $select = new ilSelectInputGUI($this->ilLng->txt('scope'), 'scope');
186  $select->setOptions($scopes);
187 
188  if (isset($_REQUEST['scope'])) {
189  $select->setValue($_REQUEST['scope']);
190  }
191 
192  $durationForm->addItem($select);
193  }
194 
195  $room = ilChatroom::byObjectId($this->gui->object->getId());
196  //if ($room->getSetting('private_rooms_enabled')) {
197 
198  $prevUseRelDates = ilDatePresentation::useRelativeDates();
200 
201  if ($from instanceof ilDateTime && $to instanceof ilDateTime) {
202  $unixFrom = $from->getUnixTime();
203  $unixTo = $to->getUnixTime();
204 
205  if ($unixFrom == $unixTo) {
206  $date = new ilDate($unixFrom, IL_CAL_UNIX);
207  $date_sub = ilDatePresentation::formatDate($date);
208  } else {
209  $date1 = new ilDate($unixFrom, IL_CAL_UNIX);
210  $date2 = new ilDate($unixTo, IL_CAL_UNIX);
211  $date_sub = ilDatePresentation::formatPeriod($date1, $date2);
212  }
213  ilDatePresentation::setUseRelativeDates($prevUseRelDates);
214 
215  $isPrivateRoom = (boolean) ((int) $_REQUEST['scope']);
216  if ($isPrivateRoom) {
217  $roomTpl->setVariable('ROOM_TITLE', sprintf($this->ilLng->txt('history_title_private_room'), $scopes[(int) $_REQUEST['scope']]) . ' (' . $date_sub . ')');
218  } else {
219  $roomTpl->setVariable('ROOM_TITLE', sprintf($this->ilLng->txt('history_title_general'), $this->gui->object->getTitle()) . ' (' . $date_sub . ')');
220  }
221  }
222 
223  if ($export) {
224  header("Content-Type: text/html");
225  header("Content-Disposition: attachment; filename=\"" . urlencode($scopes[(int) $_REQUEST['scope']] . '.html') . "\"");
226  echo $roomTpl->get();
227  exit;
228  }
229 
230  $roomTpl->setVariable('PERIOD_FORM', $durationForm->getHTML());
231 
232  $this->mainTpl->setVariable('ADM_CONTENT', $roomTpl->get());
233  }
exit
Definition: login.php:29
special template class to simplify handling of ITX/PEAR
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
$session
static setUseRelativeDates($a_status)
set use relative dates
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static useRelativeDates()
check if relative dates are used
$messages
Definition: xapiexit.php:5
Class for single dates.
const IL_CAL_FKT_DATE
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
$message
Definition: xapiexit.php:14
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
+ 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: