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

Class ilChatroomUploadFileTask. More...

+ Inheritance diagram for ilChatroomUploadFileTask:
+ Collaboration diagram for ilChatroomUploadFileTask:

Public Member Functions

 __construct (ilDBayObjectGUI $gui)
 Constructor.
 executeDefault ($requestedMethod)
 Default execute method.
 uploadFile ()
 Saves file, fetched from $_FILES to specified upload path.
 deliverFile ()
 checkUploadPath ($path)
 Checks if given upload path exists, is readable or can be created.
 getUploadPath ()
 Returns upload path.
- Public Member Functions inherited from ilDBayTaskHandler
 execute ($method)
 Executes given $method if existing, otherwise executes executeDefault() method.

Protected Member Functions

 displayLinkToUploadedFile ($room, $chat_user)

Private Member Functions

 buildMessage ($messageString, $params, ilChatroomUser $chat_user)

Private Attributes

 $gui

Detailed Description

Class ilChatroomUploadFileTask.

Provides methods to upload a file.

Author
Andreas Kordosz akord.nosp@m.osz@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$

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

Constructor & Destructor Documentation

ilChatroomUploadFileTask::__construct ( ilDBayObjectGUI  $gui)

Constructor.

Parameters
ilDBayObjectGUI$gui

Reimplemented from ilDBayTaskHandler.

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

References $gui.

{
$this->gui = $gui;
}

Member Function Documentation

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

Definition at line 134 of file class.ilChatroomUploadFileTask.php.

References $data.

Referenced by displayLinkToUploadedFile().

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

+ Here is the caller graph for this function:

ilChatroomUploadFileTask::checkUploadPath (   $path)

Checks if given upload path exists, is readable or can be created.

Parameters
string$path

Definition at line 153 of file class.ilChatroomUploadFileTask.php.

References $path, and ilUtil\makeDirParents().

Referenced by uploadFile().

{
$err = false;
switch( true )
{
case !file_exists( $path ):
if( ! ilUtil::makeDirParents( $path ) )
{
$err = true;
$msg = 'Error: Upload path could not be created!';
}
break;
case !is_dir( $path ):
$err = true;
$msg = 'Error: Upload path is not a directory!';
break;
case !is_readable( $path ):
$err = true;
$msg = 'Error: Upload path is not readable!';
break;
default:
}
if( $err )
{
throw new Exception( $msg );
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilChatroomUploadFileTask::deliverFile ( )

Definition at line 127 of file class.ilChatroomUploadFileTask.php.

{
// send file
echo "hello world";
}
ilChatroomUploadFileTask::displayLinkToUploadedFile (   $room,
  $chat_user 
)
protected
Todo:
erwartet message als json

Definition at line 90 of file class.ilChatroomUploadFileTask.php.

References $ilCtrl, $query, buildMessage(), exit, and ilUtil\stripSlashes().

Referenced by uploadFile().

{
global $ilCtrl;
$scope = $room->getRoomId();
$params = array();
$params['public'] = 1;
$message = json_encode( $this->buildMessage(
json_encode(array(
'format' => array(),
'content' => ilUtil::stripSlashes(
'Eine neue Datei mit dem Link ' .
$ilCtrl->getLinkTarget($this->gui, 'uploadFile-deliverFile') .
' wurde hochgeladen'
)
)) , $params, $chat_user
) );
$params = array_merge( $params, array('message' => $message) );
$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( $message, $recipient, $publicMessage );
}
*/
echo $response;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilChatroomUploadFileTask::executeDefault (   $requestedMethod)

Default execute method.

Parameters
string$requestedMethod

Reimplemented from ilDBayTaskHandler.

Definition at line 35 of file class.ilChatroomUploadFileTask.php.

{
}
ilChatroomUploadFileTask::getUploadPath ( )

Returns upload path.

Returns
string

Definition at line 191 of file class.ilChatroomUploadFileTask.php.

References $path, and ilUtil\getDataDir().

Referenced by uploadFile().

{
$path = ilUtil::getDataDir() . "/chatroom/" . $this->gui->object->getId() . "/uploads/";
return $path;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilChatroomUploadFileTask::uploadFile ( )

Saves file, fetched from $_FILES to specified upload path.

ilObjUser $ilUser

Todo:
: filename must be unique.

Definition at line 45 of file class.ilChatroomUploadFileTask.php.

References $file, $filename, ilChatroom\byObjectId(), checkUploadPath(), ilChatroom\checkUserPermissions(), displayLinkToUploadedFile(), getUploadPath(), ilUtil\moveUploadedFile(), and ilUtil\redirect().

{
if ( !ilChatroom::checkUserPermissions( 'read', $this->gui->ref_id ) )
{
ilUtil::redirect("repository.php");
}
$upload_path = $this->getUploadPath();
$this->checkUploadPath($upload_path);
$file = $_FILES['file_to_upload']['tmp_name'];
$filename = $_FILES['file_to_upload']['name'];
$type = $_FILES['file_to_upload']['type'];
$target = $upload_path . $filename;
{
global $ilUser;
require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
$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');
}
$room->saveFileUploadToDb($user_id, $filename, $type);
$this->displayLinkToUploadedFile($room, $chat_user);
}
}

+ Here is the call graph for this function:

Field Documentation

ilChatroomUploadFileTask::$gui
private

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

Referenced by __construct().


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