ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
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, $to)
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 ilTemplate('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);
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 $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'g:ia', $this->ilUser->getTimeZone());
149 break;
150 }
151
152 $roomTpl->setVariable('MESSAGETIME', $date_string);
153 $prevDate = $currentDate;
154 }
155
156 $roomTpl->parseCurrentBlock();
157
158 $lastDateTime = $dateTime;
159
160 ++$messagesShown;
161 }
162 break;
163 }
164 }
165
166 foreach ($psessions as $session) {
167 $scopes[$session['proom_id']] = $session['title'];
168 }
169
170 if (isset($scopes[''])) {
171 unset($scopes['']);
172 }
173
174 if (!$messagesShown) {
175 //$roomTpl->touchBlock('NO_MESSAGES');
176 $roomTpl->setVariable('LBL_NO_MESSAGES', $this->ilLng->txt('no_messages'));
177 }
178
179 asort($scopes, SORT_STRING);
180
181 $scopes = array($this->ilLng->txt('main')) + $scopes;
182
183 if (count($scopes) > 1) {
184 $select = new ilSelectInputGUI($this->ilLng->txt('scope'), 'scope');
185 $select->setOptions($scopes);
186
187 if (isset($_REQUEST['scope'])) {
188 $select->setValue($_REQUEST['scope']);
189 }
190
191 $durationForm->addItem($select);
192 }
193
194 $room = ilChatroom::byObjectId($this->gui->object->getId());
195 //if ($room->getSetting('private_rooms_enabled')) {
196
197 $prevUseRelDates = ilDatePresentation::useRelativeDates();
199
200 if ($from instanceof ilDateTime && $to instanceof ilDateTime) {
201 $unixFrom = $from->getUnixTime();
202 $unixTo = $to->getUnixTime();
203
204 if ($unixFrom == $unixTo) {
205 $date = new ilDate($unixFrom, IL_CAL_UNIX);
206 $date_sub = ilDatePresentation::formatDate($date);
207 } else {
208 $date1 = new ilDate($unixFrom, IL_CAL_UNIX);
209 $date2 = new ilDate($unixTo, IL_CAL_UNIX);
210 $date_sub = ilDatePresentation::formatPeriod($date1, $date2);
211 }
213
214 $isPrivateRoom = (boolean) ((int) $_REQUEST['scope']);
215 if ($isPrivateRoom) {
216 $roomTpl->setVariable('ROOM_TITLE', sprintf($this->ilLng->txt('history_title_private_room'), $scopes[(int) $_REQUEST['scope']]) . ' (' . $date_sub . ')');
217 } else {
218 $roomTpl->setVariable('ROOM_TITLE', sprintf($this->ilLng->txt('history_title_general'), $this->gui->object->getTitle()) . ' (' . $date_sub . ')');
219 }
220 }
221
222 if ($export) {
223 header("Content-Type: text/html");
224 header("Content-Disposition: attachment; filename=\"" . urlencode($scopes[(int) $_REQUEST['scope']] . '.html') . "\"");
225 echo $roomTpl->get();
226 exit;
227 }
228
229 $roomTpl->setVariable('PERIOD_FORM', $durationForm->getHTML());
230
231 $this->mainTpl->setVariable('ADM_CONTENT', $roomTpl->get());
232 }
233
234 public function bySessionExport()
235 {
236 $this->tabs->activateSubTab('bysession');
237 $this->bySession(true);
238 }
239
244 public function bySession($export = false)
245 {
246 $room = ilChatroom::byObjectId($this->gui->object->getId());
247
248 $scope = $room->getRoomId();
249
250 $chat_user = new ilChatroomUser($this->ilUser, $room);
251
252 $formFactory = new ilChatroomFormFactory();
253 $durationForm = $formFactory->getSessionForm($room->getSessions($chat_user));
254 $durationForm->setTitle($this->ilLng->txt('history_bysession_title'));
255 $durationForm->addCommandButton('history-bySessionExport', $this->ilLng->txt('export'));
256 $durationForm->addCommandButton('history-bySession', $this->ilLng->txt('show'));
257 $durationForm->setFormAction(
258 $this->ilCtrl->getFormAction($this->gui),
259 '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($method)
319 {
320 $this->byDay();
321 }
322}
exit
Definition: backend.php:16
$_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.
showMessages($messages, $durationForm, $export=false, $psessions=array(), $from, $to)
Prepares history table and displays it.
__construct(ilChatroomObjectGUI $gui)
{}
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=true)
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.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
$messages
Definition: en.php:5
catch(Exception $e) $message
$session
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$from