ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 if ($durationForm->checkInput()) {
72 $period = $durationForm->getItemByPostVar('timeperiod');
73
74 $messages = $room->getHistory(
75 $from = $period->getStart(),
76 $to = $period->getEnd(),
77 $chat_user->getUserId(),
78 isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
79 );
80
81 $psessions = $room->getPrivateRoomSessions(
82 $from,
83 $to,
84 $chat_user->getUserId(),
85 $scope
86 );
87 } else {
88 $export = false;
89 }
90
91 $durationForm->setValuesByPost();
92 }
93
94 $this->showMessages($messages, $durationForm, $export, $psessions, $from, $to);
95 }
96
106 private function showMessages($messages, $durationForm, $export = false, $psessions = array(), $from, $to)
107 {
113 global $tpl, $lng, $ilCtrl;
114
115 include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
116
117 $this->redirectIfNoPermission('read');
118
119 $this->gui->switchToVisibleMode();
120
121 $tpl->addCSS('Modules/Chatroom/templates/default/style.css');
122
123 // should be able to grep templates
124 if ($export) {
125 $roomTpl = new ilTemplate('tpl.history_export.html', true, true, 'Modules/Chatroom');
126 } else {
127 $roomTpl = new ilTemplate('tpl.history.html', true, true, 'Modules/Chatroom');
128 }
129
130 $scopes = array();
131
132 if ($export) {
134 }
135
136 global $ilUser;
137 $time_format = $ilUser->getTimeFormat();
138
139 $prevDate = '';
140 $messagesShown = 0;
141 $lastDateTime = null;
142 foreach ($messages as $message) {
143 //$message['message']->content = json_decode($message['message']->content);
144
145 switch ($message['message']->type) {
146 case 'message':
147 if (($_REQUEST['scope'] && $message['message']->subRoomId == $_REQUEST['scope']) || (!$_REQUEST['scope'] && !$message['message']->subRoomId)) {
148 $date = new ilDate($message['timestamp'], IL_CAL_UNIX);
149 $dateTime = new ilDateTime($message['timestamp'], IL_CAL_UNIX);
150 $currentDate = ilDatePresentation::formatDate($dateTime);
151
152 $roomTpl->setCurrentBlock('MESSAGELINE');
153 $roomTpl->setVariable('MESSAGECONTENT', $message['message']->content); // oops... it is a message? ^^
154 $roomTpl->setVariable('MESSAGESENDER', $message['message']->from->username);
155 if (null == $lastDateTime ||
156 date('d', $lastDateTime->get(IL_CAL_UNIX)) != date('d', $dateTime->get(IL_CAL_UNIX)) ||
157 date('m', $lastDateTime->get(IL_CAL_UNIX)) != date('m', $dateTime->get(IL_CAL_UNIX)) ||
158 date('Y', $lastDateTime->get(IL_CAL_UNIX)) != date('Y', $dateTime->get(IL_CAL_UNIX))
159 ) {
160 $roomTpl->setVariable('MESSAGEDATE', ilDatePresentation::formatDate($date));
161 }
162
163 if ($prevDate != $currentDate) {
164 switch ($time_format) {
166 $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'H:i', $ilUser->getTimeZone());
167 break;
169 $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'g:ia', $ilUser->getTimeZone());
170 break;
171 }
172
173 $roomTpl->setVariable('MESSAGETIME', $date_string);
174 $prevDate = $currentDate;
175 }
176
177 $roomTpl->parseCurrentBlock();
178
179 $lastDateTime = $dateTime;
180
181 ++$messagesShown;
182 }
183 break;
184 }
185 }
186
187 foreach ($psessions as $session) {
188 $scopes[$session['proom_id']] = $session['title'];
189 }
190
191 if (isset($scopes[''])) {
192 unset($scopes['']);
193 }
194
195 if (!$messagesShown) {
196 //$roomTpl->touchBlock('NO_MESSAGES');
197 $roomTpl->setVariable('LBL_NO_MESSAGES', $lng->txt('no_messages'));
198 }
199
200 asort($scopes, SORT_STRING);
201
202 $scopes = array($lng->txt('main')) + $scopes;
203
204 if (count($scopes) > 1) {
205 $select = new ilSelectInputGUI($lng->txt('scope'), 'scope');
206 $select->setOptions($scopes);
207
208 if (isset($_REQUEST['scope'])) {
209 $select->setValue($_REQUEST['scope']);
210 }
211
212 $durationForm->addItem($select);
213 }
214
215 $room = ilChatroom::byObjectId($this->gui->object->getId());
216 //if ($room->getSetting('private_rooms_enabled')) {
217
218 $prevUseRelDates = ilDatePresentation::useRelativeDates();
220
221 if ($from instanceof ilDateTime && $to instanceof ilDateTime) {
222 $unixFrom = $from->getUnixTime();
223 $unixTo = $to->getUnixTime();
224
225 if ($unixFrom == $unixTo) {
226 $date = new ilDate($unixFrom, IL_CAL_UNIX);
227 $date_sub = ilDatePresentation::formatDate($date);
228 } else {
229 $date1 = new ilDate($unixFrom, IL_CAL_UNIX);
230 $date2 = new ilDate($unixTo, IL_CAL_UNIX);
231 $date_sub = ilDatePresentation::formatPeriod($date1, $date2);
232 }
234
235 $isPrivateRoom = (boolean) ((int) $_REQUEST['scope']);
236 if ($isPrivateRoom) {
237 $roomTpl->setVariable('ROOM_TITLE', sprintf($lng->txt('history_title_private_room'), $scopes[(int) $_REQUEST['scope']]) . ' (' . $date_sub . ')');
238 } else {
239 $roomTpl->setVariable('ROOM_TITLE', sprintf($lng->txt('history_title_general'), $this->gui->object->getTitle()) . ' (' . $date_sub . ')');
240 }
241 }
242
243 if ($export) {
244 header("Content-Type: text/html");
245 header("Content-Disposition: attachment; filename=\"" . urlencode($scopes[(int) $_REQUEST['scope']] . '.html') . "\"");
246 echo $roomTpl->get();
247 exit;
248 }
249
250 $roomTpl->setVariable('PERIOD_FORM', $durationForm->getHTML());
251
252 $tpl->setVariable('ADM_CONTENT', $roomTpl->get());
253 }
254
255 public function bySessionExport()
256 {
260 global $ilTabs;
261
262 $ilTabs->activateSubTab('bysession');
263 $this->bySession(true);
264 }
265
270 public function bySession($export = false)
271 {
277 global $lng, $ilCtrl, $ilUser;
278
279 $room = ilChatroom::byObjectId($this->gui->object->getId());
280
281 $scope = $room->getRoomId();
282
283 $chat_user = new ilChatroomUser($ilUser, $room);
284
285 $formFactory = new ilChatroomFormFactory();
286 $durationForm = $formFactory->getSessionForm($room->getSessions($chat_user));
287 $durationForm->setTitle($lng->txt('history_bysession_title'));
288 $durationForm->addCommandButton('history-bySessionExport', $lng->txt('export'));
289 $durationForm->addCommandButton('history-bySession', $lng->txt('show'));
290 $durationForm->setFormAction(
291 $ilCtrl->getFormAction($this->gui),
292 'history-bySession'
293 );
294
295 if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
296 $durationForm->checkInput();
297 $postVals = explode(',', $_POST['session']);
298 $durationForm->setValuesByArray(array('session' => $_POST['session']));
299
300 $messages = $room->getHistory(
301 $from = new ilDateTime($postVals[0], IL_CAL_UNIX),
302 $to = new ilDateTime($postVals[1], IL_CAL_UNIX),
303 $chat_user->getUserId(),
304 isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
305 );
306 } else {
307 $last_session = $room->getLastSession($chat_user);
308
309 if ($last_session) {
310 $from = new ilDateTime($last_session['connected'], IL_CAL_UNIX);
311 $to = new ilDateTime($last_session['disconnected'], IL_CAL_UNIX);
312 } else {
313 $from = null;
314 $to = null;
315 }
316
317 $messages = $room->getHistory(
318 $from,
319 $to,
320 $chat_user->getUserId(),
321 isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
322 );
323 }
324
325 if ($from && $to) {
326 $psessions = $room->getPrivateRoomSessions(
327 $from,
328 $to,
329 $chat_user->getUserId(),
330 $scope
331 );
332 } else {
333 $from = new ilDateTime();
334 $to = new ilDateTime();
335 $psessions = array();
336 }
337
338 $psessions = $room->getPrivateRoomSessions(
339 $from,
340 $to,
341 $chat_user->getUserId(),
342 $scope
343 );
344
345 $this->showMessages($messages, $durationForm, $export, $psessions, $from, $to);
346 }
347
351 public function executeDefault($method)
352 {
353 $this->byDay();
354 }
355}
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$tpl
Definition: ilias.php:10
$_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.
__construct(ilChatroomObjectGUI $gui)
{}
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=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.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
catch(Exception $e) $message
$messages
Definition: en-x-test.php:7
global $lng
Definition: privfeed.php:17
$session
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$from