ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilChatroomPostMessageTask Class Reference

Class ilChatroomPostMessageTask. More...

+ Inheritance diagram for ilChatroomPostMessageTask:
+ Collaboration diagram for ilChatroomPostMessageTask:

Public Member Functions

 __construct (ilChatroomObjectGUI $gui)
 Constructor.
 executeDefault ($method)
 Prepares and posts message fetched from $_REQUEST['message'] to recipients fetched from $_REQUEST['recipient'] and adds an entry to history if successful.

Private Member Functions

 buildMessage ($messageString, $params, ilChatroomUser $chat_user)
 Instantiates stdClass, sets $data->user, $data->message, $data->public and $data->recipients using given $chat_user, $messageString and $params and returns $data.

Private Attributes

 $gui

Detailed Description

Constructor & Destructor Documentation

ilChatroomPostMessageTask::__construct ( ilChatroomObjectGUI  $gui)

Constructor.

Sets $this->gui using given $gui

Parameters
ilChatroomObjectGUI$gui

Reimplemented from ilChatroomTaskHandler.

Definition at line 25 of file class.ilChatroomPostMessageTask.php.

References $gui.

{
$this->gui = $gui;
}

Member Function Documentation

ilChatroomPostMessageTask::buildMessage (   $messageString,
  $params,
ilChatroomUser  $chat_user 
)
private

Instantiates stdClass, sets $data->user, $data->message, $data->public and $data->recipients using given $chat_user, $messageString and $params and returns $data.

Parameters
string$messageString
array$params
ilChatroomUser$chat_user
Returns
stdClass

Definition at line 126 of file class.ilChatroomPostMessageTask.php.

Referenced by executeDefault().

{
$data = new stdClass();
$data->user = $this->gui->object->getPersonalInformation( $chat_user );
$data->message = $messageString;
$data->timestamp = time() * 1000;//date( 'c' );
$data->type = 'message';
isset($params['sub']) ? ($data->sub = $params['sub']) : false;
$data->public = (int)$params['public'];
$data->recipients = $params['recipients']; // ? explode(",", $params['recipients']) : array();
$data->recipient_names = $params['recipient_names'];
return $data;
}

+ Here is the caller graph for this function:

ilChatroomPostMessageTask::executeDefault (   $method)

Prepares and posts message fetched from $_REQUEST['message'] to recipients fetched from $_REQUEST['recipient'] and adds an entry to history if successful.

ilObjUser $ilUser

Parameters
string$method

Reimplemented from ilChatroomTaskHandler.

Definition at line 38 of file class.ilChatroomPostMessageTask.php.

References $_REQUEST, $ilCtrl, $ilUser, $query, buildMessage(), ilChatroom\byObjectId(), ilChatroom\checkUserPermissions(), exit, and ilUtil\stripSlashes().

{
global $ilUser, $ilCtrl;
require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
if ( !ilChatroom::checkUserPermissions( 'read', $this->gui->ref_id ) )
{
$ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
$ilCtrl->redirectByClass("ilrepositorygui", "");
}
$room = ilChatroom::byObjectId( $this->gui->object->getId() );
$chat_user = new ilChatroomUser($ilUser, $room);
$user_id = $chat_user->getUserId();
if( !$room )
{
throw new Exception('unkown room');
}
else if( !$room->isSubscribed( $chat_user->getUserId() ) )
{
throw new Exception('not subscribed');
}
else if ( isset($_REQUEST['sub']) && !$room->userIsInPrivateRoom( $_REQUEST['sub'], $chat_user->getUserId() ))
{
$response = json_encode( array(
'success' => false,
'reason' => 'not subscribed to private room'
) );
echo json_encode( $response );
}
$scope = $room->getRoomId();
$params = array();
if( ($recipient = $_REQUEST['recipient'] ) )
{
$params['recipients'] = join( ',', array_unique( array($user_id, $recipient) ) );
$params['recipient_names'] = implode( ',', array($chat_user->getUsername(), $_REQUEST['recipient_name']) );
$params['public'] = isset( $_REQUEST['public'] ) ? (int)$_REQUEST['public'] : 0;
}
else
{
$params['public'] = 1;
}
if ($_REQUEST['sub'])
$params['sub'] = (int)$_REQUEST['sub'];
$messageObject = $this->buildMessage(
$params,
$chat_user
);
$message = json_encode( $messageObject );
$params = array_merge( $params, array('message' => $message) );
//print_r($params);exit;
$query = http_build_query( $params );
$connector = $this->gui->getConnector();
$response = $connector->post( $scope, $query );
$responseObject = json_decode( $response );
if( $responseObject->success == true /*&& $room->getSetting( 'enable_history' )*/ )
{
$room->addHistoryEntry( $messageObject, $recipient, $publicMessage );
}
echo $response;
}

+ Here is the call graph for this function:

Field Documentation

ilChatroomPostMessageTask::$gui
private

Definition at line 16 of file class.ilChatroomPostMessageTask.php.

Referenced by __construct().


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