ILIAS  release_4-4 Revision
ilChatroomUploadFileTask Class Reference

Class ilChatroomUploadFileTask. More...

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

Public Member Functions

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

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

◆ __construct()

ilChatroomUploadFileTask::__construct ( ilChatroomObjectGUI  $gui)

Constructor.

Parameters
ilChatroomObjectGUI$gui

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

References $gui.

26  {
27  $this->gui = $gui;
28  }

Member Function Documentation

◆ buildMessage()

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

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

References $data.

Referenced by displayLinkToUploadedFile().

138  {
139  $data = new stdClass();
140 
141  $data->user = $this->gui->object->getPersonalInformation( $chat_user );
142  $data->message = $messageString;
143  $data->timestamp = date( 'c' );
144  $data->type = 'message';
145  $data->public = (int)$params['public'];
146  $data->recipients = $params['recipients']; // ? explode(",", $params['recipients']) : array();
147 
148  return $data;
149  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ Here is the caller graph for this function:

◆ checkUploadPath()

ilChatroomUploadFileTask::checkUploadPath (   $path)

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

Parameters
string$path

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

References $path, and ilUtil\makeDirParents().

Referenced by uploadFile().

157  {
158  $err = false;
159 
160  switch( true )
161  {
162  case !file_exists( $path ):
163  if( ! ilUtil::makeDirParents( $path ) )
164  {
165  $err = true;
166  $msg = 'Error: Upload path could not be created!';
167  }
168  break;
169 
170  case !is_dir( $path ):
171  $err = true;
172  $msg = 'Error: Upload path is not a directory!';
173  break;
174 
175  case !is_readable( $path ):
176  $err = true;
177  $msg = 'Error: Upload path is not readable!';
178  break;
179 
180  default:
181  }
182 
183  if( $err )
184  {
185  throw new Exception( $msg );
186  }
187  }
Util class various functions, usage as namespace.
if(!file_exists(getcwd().'/ilias.ini.php')) if(isset( $_GET["client_id"]))
registration confirmation script for ilias
Definition: confirmReg.php:20
$path
Definition: index.php:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deliverFile()

ilChatroomUploadFileTask::deliverFile ( )

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

131  {
132  // send file
133 
134  echo "hello world";
135  }

◆ displayLinkToUploadedFile()

ilChatroomUploadFileTask::displayLinkToUploadedFile (   $room,
  $chat_user 
)
protected
Todo:
erwartet message als json

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

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

Referenced by uploadFile().

94  {
95  global $ilCtrl;
96 
97  $scope = $room->getRoomId();
98  $params = array();
99  $params['public'] = 1;
103  $message = json_encode( $this->buildMessage(
104  json_encode(array(
105  'format' => array(),
106  'content' => ilUtil::stripSlashes(
107  'Eine neue Datei mit dem Link ' .
108  $ilCtrl->getLinkTarget($this->gui, 'uploadFile-deliverFile') .
109  ' wurde hochgeladen'
110  )
111  )) , $params, $chat_user
112  ) );
113 
114  $params = array_merge( $params, array('message' => $message) );
115  $query = http_build_query( $params );
116 
117  $connector = $this->gui->getConnector();
118  $response = $connector->post( $scope, $query );
119  $responseObject = json_decode( $response );
120  /*
121  if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
122  {
123  $room->addHistoryEntry( $message, $recipient, $publicMessage );
124  }
125  */
126  echo $response;
127  exit;
128  }
exit
Definition: login.php:54
global $ilCtrl
Definition: ilias.php:18
buildMessage($messageString, $params, ilChatroomUser $chat_user)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeDefault()

ilChatroomUploadFileTask::executeDefault (   $requestedMethod)

Default execute method.

Parameters
string$requestedMethod

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

36  {
37 
38  }

◆ getUploadPath()

ilChatroomUploadFileTask::getUploadPath ( )

Returns upload path.

Returns
string

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

References $path, and ilUtil\getDataDir().

Referenced by uploadFile().

195  {
196  $path = ilUtil::getDataDir() . "/chatroom/" . $this->gui->object->getId() . "/uploads/";
197 
198  return $path;
199  }
static getDataDir()
get data directory (outside webspace)
$path
Definition: index.php:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ uploadFile()

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, $ilCtrl, $ilUser, ilChatroom\byObjectId(), checkUploadPath(), ilChatroom\checkUserPermissions(), displayLinkToUploadedFile(), getUploadPath(), and ilUtil\moveUploadedFile().

46  {
47  global $ilCtrl;
48 
49  if ( !ilChatroom::checkUserPermissions( 'read', $this->gui->ref_id ) )
50  {
51  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
52  $ilCtrl->redirectByClass("ilrepositorygui", "");
53  }
54 
55  $upload_path = $this->getUploadPath();
56 
57  $this->checkUploadPath($upload_path);
58 
62  $file = $_FILES['file_to_upload']['tmp_name'];
63  $filename = $_FILES['file_to_upload']['name'];
64  $type = $_FILES['file_to_upload']['type'];
65  $target = $upload_path . $filename;
66 
67  if( ilUtil::moveUploadedFile( $file, $filename, $target ) )
68  {
69  global $ilUser;
70 
71  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
72  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
73 
74  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
75  $chat_user = new ilChatroomUser($ilUser, $room);
76  $user_id = $chat_user->getUserId();
77 
78  if( !$room )
79  {
80  throw new Exception('unkown room');
81  }
82  else if( !$room->isSubscribed( $chat_user->getUserId() ) )
83  {
84  throw new Exception('not subscribed');
85  }
86 
87  $room->saveFileUploadToDb($user_id, $filename, $type);
88  $this->displayLinkToUploadedFile($room, $chat_user);
89  }
90 
91  }
print $file
checkUploadPath($path)
Checks if given upload path exists, is readable or can be created.
global $ilCtrl
Definition: ilias.php:18
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
$filename
Definition: buildRTE.php:89
global $ilUser
Definition: imgupload.php:15
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
+ Here is the call graph for this function:

Field Documentation

◆ $gui

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: