ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
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 }
23
24 public function byDayExport()
25 {
29 global $ilTabs;
30
31 $ilTabs->activateSubTab('byday');
32 $this->byDay(true);
33 }
34
39 public function byDay($export = false)
40 {
47 global $lng, $ilCtrl, $ilUser, $tpl;
48
49 $room = ilChatroom::byObjectId($this->gui->object->getId());
50
51 $tpl->addJavaScript('./Services/Form/js/date_duration.js');
52
53 $scope = $room->getRoomId();
54
55 $chat_user = new ilChatroomUser($ilUser, $room);
56 $formFactory = new ilChatroomFormFactory();
57
58 $durationForm = $formFactory->getPeriodForm();
59 $durationForm->setTitle($lng->txt('history_byday_title'));
60 $durationForm->addCommandButton('history-byDayExport', $lng->txt('export'));
61 $durationForm->addCommandButton('history-byDay', $lng->txt('show'));
62 $durationForm->setFormAction($ilCtrl->getFormAction($this->gui), 'history-byDay');
63
64 $messages = array();
65 $psessions = array();
66 $submit_request = strtolower($_SERVER['REQUEST_METHOD']) == 'post';
67 $from = null;
68 $to = null;
69
70 if($submit_request)
71 {
72 if($durationForm->checkInput())
73 {
74 $period = $durationForm->getItemByPostVar('timeperiod');
75
76 $messages = $room->getHistory(
77 $from = $period->getStart(),
78 $to = $period->getEnd(),
79 $chat_user->getUserId(),
80 isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
81 );
82
83 $psessions = $room->getPrivateRoomSessions(
84 $from,
85 $to,
86 $chat_user->getUserId(),
87 $scope
88 );
89 }
90 else
91 {
92 $export = false;
93 }
94
95 $durationForm->setValuesByPost();
96 }
97
98 $this->showMessages($messages, $durationForm, $export, $psessions, $from, $to);
99 }
100
110 private function showMessages($messages, $durationForm, $export = false, $psessions = array(), $from, $to)
111 {
117 global $tpl, $lng, $ilCtrl;
118
119 include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
120
121 if(!ilChatroom::checkUserPermissions('read', $this->gui->ref_id))
122 {
123 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
124 $ilCtrl->redirectByClass("ilrepositorygui", "");
125 }
126
127 $this->gui->switchToVisibleMode();
128
129 $tpl->addCSS('Modules/Chatroom/templates/default/style.css');
130
131 // should be able to grep templates
132 if($export)
133 {
134 $roomTpl = new ilTemplate('tpl.history_export.html', true, true, 'Modules/Chatroom');
135 }
136 else
137 {
138 $roomTpl = new ilTemplate('tpl.history.html', true, true, 'Modules/Chatroom');
139 }
140
141 $scopes = array();
142
143 if($export)
144 {
146 }
147
148 global $ilUser;
149 $time_format = $ilUser->getTimeFormat();
150
151 $prevDate = '';
152 $messagesShown = 0;
153 $lastDateTime = null;
154 foreach($messages as $message)
155 {
156 //$message['message']->content = json_decode($message['message']->content);
157
158 switch($message['message']->type)
159 {
160 case 'message':
161 if(($_REQUEST['scope'] && $message['message']->subRoomId == $_REQUEST['scope']) || (!$_REQUEST['scope'] && !$message['message']->subRoomId))
162 {
163 $date = new ilDate($message['timestamp'], IL_CAL_UNIX);
164 $dateTime = new ilDateTime($message['timestamp'], IL_CAL_UNIX);
165 $currentDate = ilDatePresentation::formatDate($dateTime);
166
167 $roomTpl->setCurrentBlock('MESSAGELINE');
168 $roomTpl->setVariable('MESSAGECONTENT', $message['message']->content); // oops... it is a message? ^^
169 $roomTpl->setVariable('MESSAGESENDER', $message['message']->from->username);
170 if(null == $lastDateTime ||
171 date('d', $lastDateTime->get(IL_CAL_UNIX)) != date('d', $dateTime->get(IL_CAL_UNIX)) ||
172 date('m', $lastDateTime->get(IL_CAL_UNIX)) != date('m', $dateTime->get(IL_CAL_UNIX)) ||
173 date('Y', $lastDateTime->get(IL_CAL_UNIX)) != date('Y', $dateTime->get(IL_CAL_UNIX))
174 )
175 {
176 $roomTpl->setVariable('MESSAGEDATE', ilDatePresentation::formatDate($date));
177 }
178
179 if($prevDate != $currentDate)
180 {
181 switch($time_format)
182 {
184 $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'H:i', $ilUser->getTimeZone());
185 break;
187 $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'g:ia', $ilUser->getTimeZone());
188 break;
189 }
190
191 $roomTpl->setVariable('MESSAGETIME', $date_string);
192 $prevDate = $currentDate;
193 }
194
195 $roomTpl->parseCurrentBlock();
196
197 $lastDateTime = $dateTime;
198
199 ++$messagesShown;
200 }
201 break;
202 }
203 }
204
205 foreach($psessions as $session)
206 {
207 $scopes[$session['proom_id']] = $session['title'];
208 }
209
210 if(isset($scopes['']))
211 {
212 unset($scopes['']);
213 }
214
215 if(!$messagesShown)
216 {
217 //$roomTpl->touchBlock('NO_MESSAGES');
218 $roomTpl->setVariable('LBL_NO_MESSAGES', $lng->txt('no_messages'));
219 }
220
221 asort($scopes, SORT_STRING);
222
223 $scopes = array($lng->txt('main')) + $scopes;
224
225 if(count($scopes) > 1)
226 {
227 $select = new ilSelectInputGUI($lng->txt('scope'), 'scope');
228 $select->setOptions($scopes);
229
230 if(isset($_REQUEST['scope']))
231 {
232 $select->setValue($_REQUEST['scope']);
233 }
234
235 $durationForm->addItem($select);
236 }
237
238 $room = ilChatroom::byObjectId($this->gui->object->getId());
239 //if ($room->getSetting('private_rooms_enabled')) {
240
241 $prevUseRelDates = ilDatePresentation::useRelativeDates();
243
244 if($from instanceof ilDateTime && $to instanceof ilDateTime)
245 {
246 $unixFrom = $from->getUnixTime();
247 $unixTo = $to->getUnixTime();
248
249 if($unixFrom == $unixTo)
250 {
251 $date = new ilDate($unixFrom, IL_CAL_UNIX);
252 $date_sub = ilDatePresentation::formatDate($date);
253 }
254 else
255 {
256 $date1 = new ilDate($unixFrom, IL_CAL_UNIX);
257 $date2 = new ilDate($unixTo, IL_CAL_UNIX);
258 $date_sub = ilDatePresentation::formatPeriod($date1, $date2);
259 }
261
262 $isPrivateRoom = (boolean)((int)$_REQUEST['scope']);
263 if($isPrivateRoom)
264 {
265 $roomTpl->setVariable('ROOM_TITLE', sprintf($lng->txt('history_title_private_room'), $scopes[(int)$_REQUEST['scope']]) . ' (' . $date_sub . ')');
266 }
267 else
268 {
269 $roomTpl->setVariable('ROOM_TITLE', sprintf($lng->txt('history_title_general'), $this->gui->object->getTitle()) . ' (' . $date_sub . ')');
270 }
271 }
272
273 if($export)
274 {
275 header("Content-Type: text/html");
276 header("Content-Disposition: attachment; filename=\"" . urlencode($scopes[(int)$_REQUEST['scope']] . '.html') . "\"");
277 echo $roomTpl->get();
278 exit;
279 }
280
281 $roomTpl->setVariable('PERIOD_FORM', $durationForm->getHTML());
282
283 $tpl->setVariable('ADM_CONTENT', $roomTpl->get());
284 }
285
286 public function bySessionExport()
287 {
291 global $ilTabs;
292
293 $ilTabs->activateSubTab('bysession');
294 $this->bySession(true);
295 }
296
301 public function bySession($export = false)
302 {
308 global $lng, $ilCtrl, $ilUser;
309
310 $room = ilChatroom::byObjectId($this->gui->object->getId());
311
312 $scope = $room->getRoomId();
313
314 $chat_user = new ilChatroomUser($ilUser, $room);
315
316 $formFactory = new ilChatroomFormFactory();
317 $durationForm = $formFactory->getSessionForm($room->getSessions($chat_user));
318 $durationForm->setTitle($lng->txt('history_bysession_title'));
319 $durationForm->addCommandButton('history-bySessionExport', $lng->txt('export'));
320 $durationForm->addCommandButton('history-bySession', $lng->txt('show'));
321 $durationForm->setFormAction(
322 $ilCtrl->getFormAction($this->gui), 'history-bySession'
323 );
324
325 if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
326 {
327 $durationForm->checkInput();
328 $postVals = explode(',', $_POST['session']);
329 $durationForm->setValuesByArray(array('session' => $_POST['session']));
330
331 $messages = $room->getHistory(
332 $from = new ilDateTime($postVals[0], IL_CAL_UNIX),
333 $to = new ilDateTime($postVals[1], IL_CAL_UNIX),
334 $chat_user->getUserId(),
335 isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
336 );
337 }
338 else
339 {
340 $last_session = $room->getLastSession($chat_user);
341
342 if($last_session)
343 {
344 $from = new ilDateTime($last_session['connected'], IL_CAL_UNIX);
345 $to = new ilDateTime($last_session['disconnected'], IL_CAL_UNIX);
346 }
347 else
348 {
349 $from = null;
350 $to = null;
351 }
352
353 $messages = $room->getHistory(
354 $from,
355 $to,
356 $chat_user->getUserId(),
357 isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
358 );
359 }
360
361 if($from && $to)
362 {
363 $psessions = $room->getPrivateRoomSessions(
364 $from,
365 $to,
366 $chat_user->getUserId(),
367 $scope
368 );
369 }
370 else
371 {
372 $from = new ilDateTime();
373 $to = new ilDateTime();
374 $psessions = array();
375 }
376
377 $psessions = $room->getPrivateRoomSessions(
378 $from,
379 $to,
380 $chat_user->getUserId(),
381 $scope
382 );
383
384 $this->showMessages($messages, $durationForm, $export, $psessions, $from, $to);
385 }
386
390 public function executeDefault($method)
391 {
392 $this->byDay();
393 }
394}
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
global $tpl
Definition: ilias.php:8
$_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.
Class ilChatroom Keeps methods to prepare and display the history task.
__construct(ilChatroomObjectGUI $gui)
{}
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date)
Format a date @access public.
static useRelativeDates()
check if relative dates are used
@classDescription Date and time handling
Class for single dates.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
$messages
Definition: en-x-test.php:7
global $lng
Definition: privfeed.php:17
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']