ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilChatroomHistoryTask.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
16{
17
18 private $gui;
19
28 {
29 require_once 'Modules/Chatroom/classes/class.ilChatroomFormFactory.php';
30 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
31 require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
32
33 $this->gui = $gui;
34 }
35
44 private function showMessages($messages, $durationForm, $export = false, $psessions = array(), $from, $to)
45 {
46 //global $tpl, $ilUser, $ilCtrl, $lng;
47 global $tpl, $lng, $ilCtrl;
48
49 include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
50
51 if(!ilChatroom::checkUserPermissions('read', $this->gui->ref_id))
52 {
53 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
54 $ilCtrl->redirectByClass("ilrepositorygui", "");
55 }
56
57 $this->gui->switchToVisibleMode();
58
59 $tpl->addCSS('Modules/Chatroom/templates/default/style.css');
60
61 // should be able to grep templates
62 if($export)
63 {
64 $roomTpl = new ilTemplate('tpl.history_export.html', true, true, 'Modules/Chatroom');
65 }
66 else
67 {
68 $roomTpl = new ilTemplate('tpl.history.html', true, true, 'Modules/Chatroom');
69 }
70
71 $scopes = array();
72
73 if($export)
74 {
76 }
77
78 global $ilUser;
79 $time_format = $ilUser->getTimeFormat();
80
81 $prevDate = '';
82 $messagesShown = 0;
83 $lastDateTime = null;
84 foreach($messages as $message)
85 {
86 $message['message']->message = json_decode($message['message']->message);
87
88 switch($message['message']->type)
89 {
90 case 'message':
91 if(($_REQUEST['scope'] && $message['message']->sub == $_REQUEST['scope']) || (!$_REQUEST['scope'] && !$message['message']->sub))
92 {
93 $date = new ilDate($message['timestamp'], IL_CAL_UNIX);
94 $dateTime = new ilDateTime($message['timestamp'], IL_CAL_UNIX);
95 $currentDate = ilDatePresentation::formatDate($dateTime);
96
97 $roomTpl->setCurrentBlock('MESSAGELINE');
98 $roomTpl->setVariable('MESSAGECONTENT', $message['message']->message->content); // oops... it is a message? ^^
99 $roomTpl->setVariable('MESSAGESENDER', $message['message']->user->username);
100 if(null == $lastDateTime ||
101 date('d', $lastDateTime->get(IL_CAL_UNIX)) != date('d', $dateTime->get(IL_CAL_UNIX)) ||
102 date('m', $lastDateTime->get(IL_CAL_UNIX)) != date('m', $dateTime->get(IL_CAL_UNIX)) ||
103 date('Y', $lastDateTime->get(IL_CAL_UNIX)) != date('Y', $dateTime->get(IL_CAL_UNIX)))
104 {
105 $roomTpl->setVariable('MESSAGEDATE', ilDatePresentation::formatDate($date));
106 }
107
108 if($prevDate != $currentDate)
109 {
110 switch($time_format)
111 {
113 $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'H:i', $ilUser->getTimeZone());
114 break;
116 $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'g:ia', $ilUser->getTimeZone());
117 break;
118 }
119
120 $roomTpl->setVariable('MESSAGETIME', $date_string);
121 $prevDate = $currentDate;
122 }
123
124 $roomTpl->parseCurrentBlock();
125
126 $lastDateTime = $dateTime;
127
128 ++$messagesShown;
129 }
130 break;
131 }
132 }
133
134 foreach($psessions as $session)
135 {
136 $scopes[$session['proom_id']] = $session['title'];
137 }
138
139 if(isset($scopes['']))
140 {
141 unset($scopes['']);
142 }
143
144 if(!$messagesShown)
145 {
146 //$roomTpl->touchBlock('NO_MESSAGES');
147 $roomTpl->setVariable('LBL_NO_MESSAGES', $lng->txt('no_messages'));
148 }
149
150 asort($scopes, SORT_STRING);
151
152 $scopes = array($lng->txt('main')) + $scopes;
153
154 if(count($scopes) > 1)
155 {
156 $select = new ilSelectInputGUI($lng->txt('scope'), 'scope');
157 $select->setOptions($scopes);
158
159 if(isset($_REQUEST['scope']))
160 {
161 $select->setValue($_REQUEST['scope']);
162 }
163
164 $durationForm->addItem($select);
165 }
166
167 $room = ilChatroom::byObjectId($this->gui->object->getId());
168 //if ($room->getSetting('private_rooms_enabled')) {
169
170 $prevUseRelDates = ilDatePresentation::useRelativeDates();
172
173 $unixFrom = $from->getUnixTime();
174 $unixTo = $to->getUnixTime();
175
176 if($unixFrom == $unixTo)
177 {
178 $date = new ilDate($unixFrom, IL_CAL_UNIX);
179 $date_sub = ilDatePresentation::formatDate($date);
180 }
181 else
182 {
183 $date1 = new ilDate($unixFrom, IL_CAL_UNIX);
184 $date2 = new ilDate($unixTo, IL_CAL_UNIX);
185 $date_sub = ilDatePresentation::formatPeriod($date1, $date2);
186 }
188
189 $isPrivateRoom = (boolean)((int)$_REQUEST['scope']);
190 if($isPrivateRoom)
191 {
192 $roomTpl->setVariable('ROOM_TITLE', sprintf($lng->txt('history_title_private_room'), $scopes[(int)$_REQUEST['scope']]) . ' (' . $date_sub . ')');
193 }
194 else
195 {
196 $roomTpl->setVariable('ROOM_TITLE', sprintf($lng->txt('history_title_general'), $this->gui->object->getTitle()) . ' (' . $date_sub . ')');
197 }
198
199 //}
200
201 if($export)
202 {
203 header("Content-Type: text/html");
204 header("Content-Disposition: attachment; filename=\"" . urlencode($scopes[(int)$_REQUEST['scope']] . '.html') . "\"");
205 echo $roomTpl->get();
206 exit;
207 }
208
209 $roomTpl->setVariable('PERIOD_FORM', $durationForm->getHTML());
210
211 $tpl->setVariable('ADM_CONTENT', $roomTpl->get());
212 }
213
214 public function byDayExport() {
215 $this->byDay(true);
216 }
217
218 public function bySessionExport() {
219 $this->bySession(true);
220 }
228 public function byDay($export = false)
229 {
230 global $lng, $ilCtrl, $ilUser, $tpl;
231
232 $room = ilChatroom::byObjectId( $this->gui->object->getId() );
233
234 $tpl->addJavaScript('./Services/Form/js/date_duration.js');
235
236 $scope = $room->getRoomId();
237
238 $chat_user = new ilChatroomUser( $ilUser, $room );
239 $formFactory = new ilChatroomFormFactory();
240
241 $durationForm = $formFactory->getPeriodForm();
242 $durationForm->setTitle( $lng->txt('history_byday_title') );
243 $durationForm->addCommandButton( 'history-byDayExport', $lng->txt( 'export' ) );
244 $durationForm->addCommandButton( 'history-byDay', $lng->txt( 'show' ) );
245 $durationForm->setFormAction( $ilCtrl->getFormAction( $this->gui ), 'history-byDay' );
246
247 if( strtolower( $_SERVER['REQUEST_METHOD'] ) == 'post' )
248 {
249 $durationForm->checkInput();
250 $period = $durationForm->getItemByPostVar( 'timeperiod' );
251 $messages = $room->getHistory(
252 $from = $period->getStart(),
253 $to = $period->getEnd(),
254 /*$room->getSetting( 'restrict_history' ) ?*/ $chat_user->getUserId() /*: null*/,
255 isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
256 );
257 }
258 else
259 {
260 $from = new ilDateTime( time() - 60 * 60, IL_CAL_UNIX );
261 $to = new ilDateTime( time(), IL_CAL_UNIX );
262
263 $period = $durationForm->getItemByPostVar( 'timeperiod' );
264 $period->setStart( $from );
265 $period->setEnd( $to );
266
267 $messages = $room->getHistory(
268 $from,
269 $to,
270 $chat_user->getUserId(),
271 isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
272 );
273 }
274
275 $psessions = $room->getPrivateRoomSessions(
276 $from,
277 $to,
278 $chat_user->getUserId(),
279 $scope
280 );
281
282 $this->showMessages( $messages, $durationForm, $export, $psessions, $from, $to );
283 }
284
292 public function bySession($export = false)
293 {
294 global $lng, $ilCtrl, $ilUser;
295
296 $room = ilChatroom::byObjectId( $this->gui->object->getId() );
297
298 $scope = $room->getRoomId();
299
300 $chat_user = new ilChatroomUser( $ilUser, $room );
301
302 $formFactory = new ilChatroomFormFactory();
303 $durationForm = $formFactory->getSessionForm( $room->getSessions( $chat_user ) );
304 $durationForm->setTitle( $lng->txt('history_bysession_title') );
305 $durationForm->addCommandButton( 'history-bySessionExport', $lng->txt( 'export' ) );
306 $durationForm->addCommandButton( 'history-bySession', $lng->txt( 'show' ) );
307 $durationForm->setFormAction(
308 $ilCtrl->getFormAction( $this->gui ), 'history-bySession'
309 );
310
311 if( strtolower( $_SERVER['REQUEST_METHOD'] ) == 'post' )
312 {
313 $durationForm->checkInput();
314 $postVals = explode( ',', $_POST['session'] );
315 $durationForm->setValuesByArray( array('session' => $_POST['session']) );
316
317 $messages = $room->getHistory(
318 $from = new ilDateTime( $postVals[0], IL_CAL_UNIX ),
319 $to = new ilDateTime( $postVals[1], IL_CAL_UNIX ),
320 $chat_user->getUserId(),
321 isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
322 );
323 }
324 else
325 {
326 $last_session = $room->getLastSession( $chat_user );
327
328 if( $last_session )
329 {
330 $from = new ilDateTime( $last_session['connected'], IL_CAL_UNIX );
331 $to = new ilDateTime( $last_session['disconnected'], IL_CAL_UNIX );
332 }
333 else
334 {
335 $from = null;
336 $to = null;
337 }
338
339 $messages = $room->getHistory(
340 $from,
341 $to,
342 $chat_user->getUserId(),
343 isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
344 );
345 }
346
347 if ($from && $to) {
348 $psessions = $room->getPrivateRoomSessions(
349 $from,
350 $to,
351 $chat_user->getUserId(),
352 $scope
353 );
354 }
355 else {
356 $from = new ilDateTime();
357 $to = new ilDateTime();
358 $psessions = array();
359 }
360
361 $psessions = $room->getPrivateRoomSessions(
362 $from,
363 $to,
364 $chat_user->getUserId(),
365 $scope
366 );
367
368 $this->showMessages( $messages, $durationForm, $export, $psessions, $from, $to );
369 }
370
376 public function executeDefault($method)
377 {
378 $this->byDay();
379 }
380
381}
382
383?>
global $tpl
Definition: ilias.php:8
const IL_CAL_UNIX
const IL_CAL_FKT_DATE
Class ilChatroomFormFactory.
byDay($export=false)
Prepares and displays history period form by day.
showMessages($messages, $durationForm, $export=false, $psessions=array(), $from, $to)
Prepares history table and displays it.
__construct(ilChatroomObjectGUI $gui)
Constructor.
bySession($export=false)
Prepares and displays history period form by session.
executeDefault($method)
Calls $this->byDay method.
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
$_POST['username']
Definition: cron.php:12
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
$messages
Definition: en-x-test.php:7
global $lng
Definition: privfeed.php:40
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
global $ilUser
Definition: imgupload.php:15