ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilChatroomHistoryGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
17 {
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 }
23
24 public function byDayExport()
25 {
26 $this->tabs->activateSubTab('byday');
27 $this->byDay(true);
28 }
29
34 public function byDay($export = false)
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 }
83
93 private function showMessages($messages, $durationForm, $export = false, $psessions = array(), $from = null, $to = null)
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 }
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 }
234
235 public function bySessionExport()
236 {
237 $this->tabs->activateSubTab('bysession');
238 $this->bySession(true);
239 }
240
245 public function bySession($export = false)
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 }
314
318 public function executeDefault($requestedMethod)
319 {
320 $this->byDay();
321 }
322}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_FKT_DATE
Class ilChatroomFormFactory.
Class ilChatroomGUIHandler.
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
Class ilChatroom Keeps methods to prepare and display the history task.
executeDefault($requestedMethod)
@inheritDoc
__construct(ilChatroomObjectGUI $gui)
{}
showMessages($messages, $durationForm, $export=false, $psessions=array(), $from=null, $to=null)
Prepares history table and displays it.
bySession($export=false)
Prepares and displays history period form by session.
byDay($export=false)
Prepares and displays history period form by day.
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
This class provides processing control methods.
getFormAction( $a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=false)
Get form action url for gui class object.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
Class for single dates.
special template class to simplify handling of ITX/PEAR
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
exit
Definition: login.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$session
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
$messages
Definition: xapiexit.php:5
$message
Definition: xapiexit.php:14