ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilChatroomHistoryTask Class Reference

Class ilChatroom. More...

+ Inheritance diagram for ilChatroomHistoryTask:
+ Collaboration diagram for ilChatroomHistoryTask:

Public Member Functions

 __construct (ilDBayObjectGUI $gui)
 Constructor.
 byDayExport ()
 bySessionExport ()
 byDay ($export=false)
 Prepares and displays history period form by day.
 bySession ($export=false)
 Prepares and displays history period form by session.
 executeDefault ($method)
 Calls $this->byDay method.
- Public Member Functions inherited from ilDBayTaskHandler
 execute ($method)
 Executes given $method if existing, otherwise executes executeDefault() method.

Private Member Functions

 showMessages ($messages, $durationForm, $export=false, $psessions=array(), $from, $to)
 Prepares history table and displays it.

Private Attributes

 $gui

Detailed Description

Class ilChatroom.

Keeps methods to prepare and display the history task.

Author
Jan Posselt jposs.nosp@m.elt@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$

Definition at line 15 of file class.ilChatroomHistoryTask.php.

Constructor & Destructor Documentation

ilChatroomHistoryTask::__construct ( ilDBayObjectGUI  $gui)

Constructor.

Requires needed classes and sets $this->gui using given $gui.

Parameters
ilDBayObjectGUI$gui

Reimplemented from ilDBayTaskHandler.

Definition at line 27 of file class.ilChatroomHistoryTask.php.

References $gui.

{
require_once 'Modules/Chatroom/classes/class.ilChatroomFormFactory.php';
require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
$this->gui = $gui;
}

Member Function Documentation

ilChatroomHistoryTask::byDay (   $export = false)

Prepares and displays history period form by day.

ilLanguage $lng ilCtrl2 $ilCtrl ilObjUser $ilUser

Definition at line 199 of file class.ilChatroomHistoryTask.php.

References $_REQUEST, $ilCtrl, $lng, $messages, $tpl, ilChatroom\byObjectId(), IL_CAL_UNIX, and showMessages().

Referenced by byDayExport(), and executeDefault().

{
global $lng, $ilCtrl, $ilUser, $tpl;
$room = ilChatroom::byObjectId( $this->gui->object->getId() );
$tpl->addJavaScript('./Services/Form/js/date_duration.js');
$scope = $room->getRoomId();
$chat_user = new ilChatroomUser( $ilUser, $room );
$formFactory = new ilChatroomFormFactory();
$durationForm = $formFactory->getPeriodForm();
$durationForm->setTitle( $lng->txt('history_byday_title') );
$durationForm->addCommandButton( 'history-byDayExport', $lng->txt( 'export' ) );
$durationForm->addCommandButton( 'history-byDay', $lng->txt( 'show' ) );
$durationForm->setFormAction( $ilCtrl->getFormAction( $this->gui ), 'history-byDay' );
if( strtolower( $_SERVER['REQUEST_METHOD'] ) == 'post' )
{
$durationForm->checkInput();
$period = $durationForm->getItemByPostVar( 'timeperiod' );
$messages = $room->getHistory(
$from = $period->getStart(),
$to = $period->getEnd(),
/*$room->getSetting( 'restrict_history' ) ?*/ $chat_user->getUserId() /*: null*/,
isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
);
}
else
{
$from = new ilDateTime( time() - 60 * 60, IL_CAL_UNIX );
$to = new ilDateTime( time(), IL_CAL_UNIX );
$period = $durationForm->getItemByPostVar( 'timeperiod' );
$period->setStart( $from );
$period->setEnd( $to );
$messages = $room->getHistory(
$from,
$to,
$chat_user->getUserId(),
isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
);
}
$psessions = $room->getPrivateRoomSessions(
$from,
$to,
$chat_user->getUserId(),
$scope
);
$this->showMessages( $messages, $durationForm, $export, $psessions, $from, $to );
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilChatroomHistoryTask::byDayExport ( )

Definition at line 185 of file class.ilChatroomHistoryTask.php.

References byDay().

{
$this->byDay(true);
}

+ Here is the call graph for this function:

ilChatroomHistoryTask::bySession (   $export = false)

Prepares and displays history period form by session.

ilLanguage $lng ilCtrl2 $ilCtrl ilObjUser $ilUser

Definition at line 263 of file class.ilChatroomHistoryTask.php.

References $_POST, $_REQUEST, $ilCtrl, $lng, $messages, ilChatroom\byObjectId(), IL_CAL_UNIX, and showMessages().

Referenced by bySessionExport().

{
global $lng, $ilCtrl, $ilUser;
$room = ilChatroom::byObjectId( $this->gui->object->getId() );
$scope = $room->getRoomId();
$chat_user = new ilChatroomUser( $ilUser, $room );
$formFactory = new ilChatroomFormFactory();
$durationForm = $formFactory->getSessionForm( $room->getSessions( $chat_user ) );
$durationForm->setTitle( $lng->txt('history_bysession_title') );
$durationForm->addCommandButton( 'history-bySessionExport', $lng->txt( 'export' ) );
$durationForm->addCommandButton( 'history-bySession', $lng->txt( 'show' ) );
$durationForm->setFormAction(
$ilCtrl->getFormAction( $this->gui ), 'history-bySession'
);
if( strtolower( $_SERVER['REQUEST_METHOD'] ) == 'post' )
{
$durationForm->checkInput();
$postVals = explode( ',', $_POST['session'] );
$durationForm->setValuesByArray( array('session' => $_POST['session']) );
$messages = $room->getHistory(
$from = new ilDateTime( $postVals[0], IL_CAL_UNIX ),
$to = new ilDateTime( $postVals[1], IL_CAL_UNIX ),
$chat_user->getUserId(),
isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
);
}
else
{
$last_session = $room->getLastSession( $chat_user );
if( $last_session )
{
$from = new ilDateTime( $last_session['connected'], IL_CAL_UNIX );
$to = new ilDateTime( $last_session['disconnected'], IL_CAL_UNIX );
}
else
{
$from = null;
$to = null;
}
$messages = $room->getHistory(
$from,
$to,
$chat_user->getUserId(),
isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0
);
}
if ($from && $to) {
$psessions = $room->getPrivateRoomSessions(
$from,
$to,
$chat_user->getUserId(),
$scope
);
}
else {
$from = new ilDateTime();
$to = new ilDateTime();
$psessions = array();
}
$psessions = $room->getPrivateRoomSessions(
$from,
$to,
$chat_user->getUserId(),
$scope
);
$this->showMessages( $messages, $durationForm, $export, $psessions, $from, $to );
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilChatroomHistoryTask::bySessionExport ( )

Definition at line 189 of file class.ilChatroomHistoryTask.php.

References bySession().

{
$this->bySession(true);
}

+ Here is the call graph for this function:

ilChatroomHistoryTask::executeDefault (   $method)

Calls $this->byDay method.

Parameters
string$method

Reimplemented from ilDBayTaskHandler.

Definition at line 347 of file class.ilChatroomHistoryTask.php.

References byDay().

{
$this->byDay();
}

+ Here is the call graph for this function:

ilChatroomHistoryTask::showMessages (   $messages,
  $durationForm,
  $export = false,
  $psessions = array(),
  $from,
  $to 
)
private

Prepares history table and displays it.

ilTemplate $tpl ilLanguage $lng

Parameters
array$messages
ilPropertyFormGUI$durationForm

Definition at line 44 of file class.ilChatroomHistoryTask.php.

References $_REQUEST, $lng, $messages, $tpl, ilChatroom\byObjectId(), ilChatroom\checkUserPermissions(), exit, ilDatePresentation\formatDate(), ilDatePresentation\formatPeriod(), IL_CAL_FKT_DATE, IL_CAL_UNIX, ilUtil\redirect(), ilSelectInputGUI\setOptions(), ilDatePresentation\setUseRelativeDates(), ilCalendarSettings\TIME_FORMAT_12, ilCalendarSettings\TIME_FORMAT_24, and ilDatePresentation\useRelativeDates().

Referenced by byDay(), and bySession().

{
//global $tpl, $ilUser, $ilCtrl, $lng;
global $tpl, $lng;
include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
if ( !ilChatroom::checkUserPermissions('read' , $this->gui->ref_id ) )
{
ilUtil::redirect("repository.php");
}
$this->gui->switchToVisibleMode();
$tpl->addCSS( 'Modules/Chatroom/templates/default/style.css' );
$roomTpl = new ilTemplate( 'tpl.history'.($export ? '_export' : '').'.html', true, true, 'Modules/Chatroom' );
$scopes = array();
if ($export) {
}
global $ilUser;
$time_format = $ilUser->getTimeFormat();
$prevDate = '';
$messagesShown = 0;
foreach( $messages as $message )
{
$message['message']->message = json_decode( $message['message']->message );
switch($message['message']->type)
{
case 'message':
if (($_REQUEST['scope'] && $message['message']->sub == $_REQUEST['scope']) || (!$_REQUEST['scope'] && !$message['message']->sub)) {
$dateTime = new ilDateTime($message['timestamp'], IL_CAL_UNIX);
$currentDate = ilDatePresentation::formatDate($dateTime);
$roomTpl->setCurrentBlock( 'MESSAGELINE' );
$roomTpl->setVariable( 'MESSAGECONTENT', $message['message']->message->content ); // oops... it is a message? ^^
$roomTpl->setVariable( 'MESSAGESENDER', $message['message']->user->username );
if ($prevDate != $currentDate) {
switch($time_format)
{
$date_string = $dateTime->get(IL_CAL_FKT_DATE,'H:i',$ilUser->getTimeZone());
break;
$date_string = $dateTime->get(IL_CAL_FKT_DATE,'g:ia',$ilUser->getTimeZone());
break;
}
$roomTpl->setVariable( 'MESSAGEDATE', $date_string);
$prevDate = $currentDate;
}
/*
else {
$roomTpl->touchBlock( 'NO_MESSAGE_DATE');
}
*
*/
$roomTpl->parseCurrentBlock();
}
++$messagesShown;
break;
}
}
foreach($psessions as $session) {
$scopes[$session['proom_id']] = $session['title'];
}
if (isset($scopes[''])) {
unset($scopes['']);
}
if (!$messagesShown) {
//$roomTpl->touchBlock('NO_MESSAGES');
$roomTpl->setVariable('LBL_NO_MESSAGES', $lng->txt('no_messages'));
}
asort($scopes, SORT_STRING);
$scopes = array($lng->txt('main')) + $scopes;
if (count($scopes) > 1) {
$select = new ilSelectInputGUI($lng->txt('scope'), 'scope');
$select->setOptions($scopes);
if (isset($_REQUEST['scope'])) {
$select->setValue($_REQUEST['scope']);
}
$durationForm->addItem($select);
}
$room = ilChatroom::byObjectId( $this->gui->object->getId() );
//if ($room->getSetting('private_rooms_enabled')) {
$unixFrom = $from->getUnixTime();
$unixTo = $to->getUnixTime();
if ($unixFrom == $unixTo) {
$date = new ilDate($unixFrom, IL_CAL_UNIX);
$date_sub = ilDatePresentation::formatDate($date);
}
else {
$date1 = new ilDate($unixFrom, IL_CAL_UNIX);
$date2 = new ilDate($unixTo, IL_CAL_UNIX);
$date_sub = ilDatePresentation::formatPeriod($date1, $date2);
}
$isPrivateRoom = (boolean)((int)$_REQUEST['scope']);
if ($isPrivateRoom) {
$roomTpl->setVariable( 'ROOM_TITLE', sprintf($lng->txt('history_title_private_room'), $scopes[(int)$_REQUEST['scope']]) . ' (' . $date_sub . ')');
}
else {
$roomTpl->setVariable( 'ROOM_TITLE', sprintf($lng->txt('history_title_general'), $this->gui->object->getTitle()) . ' (' . $date_sub . ')');
}
//}
if ($export) {
header("Content-Type: text/html");
header("Content-Disposition: attachment; filename=\"". urlencode( $scopes[(int)$_REQUEST['scope']] . '.html' ) ."\"");
echo $roomTpl->get();
}
$roomTpl->setVariable( 'PERIOD_FORM', $durationForm->getHTML() );
$tpl->setVariable( 'ADM_CONTENT', $roomTpl->get() );
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilChatroomHistoryTask::$gui
private

Definition at line 18 of file class.ilChatroomHistoryTask.php.

Referenced by __construct().


The documentation for this class was generated from the following file: