ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilChatroomUploadFileGUI Class Reference

Class ilChatroomUploadFileGUI Provides methods to upload a file. More...

+ Inheritance diagram for ilChatroomUploadFileGUI:
+ Collaboration diagram for ilChatroomUploadFileGUI:

Public Member Functions

 __construct ()
 
 executeDefault ($requestedMethod)
 Default execute method. More...
 
 uploadFile ()
 Saves file, fetched from $_FILES to specified upload path. More...
 
 getUploadPath ()
 Returns upload path. More...
 
 checkUploadPath ($path)
 Checks if given upload path exists, is readable or can be created. More...
 
 deliverFile ()
 
- Public Member Functions inherited from ilChatroomGUIHandler
 __construct (ilChatroomObjectGUI $gui)
 
 sendResponse ($response)
 Sends a json encoded response and exits the php process. More...
 
 hasPermission ($permission)
 Checks for access with ilRbacSystem. More...
 
 execute ($method)
 Executes given $method if existing, otherwise executes executeDefault() method. More...
 
 executeDefault ($requestedMethod)
 
 redirectIfNoPermission ($permission)
 Checks for requested permissions and redirects if the permission check failed. More...
 
 isSuccessful ($response)
 Checks for success param in an json decoded response. More...
 

Protected Member Functions

 displayLinkToUploadedFile ($room, $chat_user)
 
- Protected Member Functions inherited from ilChatroomGUIHandler
 getRoomByObjectId ($objectId)
 
 exitIfNoRoomExists ($room)
 Checks if a ilChatroom exists. More...
 
 exitIfNoRoomPermission ($room, $subRoom, $chat_user)
 Check if user can moderate a chatroom. More...
 
 canModerate ($room, $subRoom, $user_id)
 Checks if the user has permission to moderate a ilChatroom. More...
 
 isMainRoom ($subRoomId)
 

Private Member Functions

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

Additional Inherited Members

- Protected Attributes inherited from ilChatroomGUIHandler
 $gui
 
 $ilUser
 
 $ilCtrl
 
 $ilLng
 
 $webDirectory
 
 $upload
 

Detailed Description

Class ilChatroomUploadFileGUI 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 11 of file class.ilChatroomUploadFileGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilChatroomUploadFileGUI::__construct ( )

Definition at line 13 of file class.ilChatroomUploadFileGUI.php.

14  {
15  throw new Exception('METHOD_NOT_IN_USE', 1456435027);
16  }

Member Function Documentation

◆ buildMessage()

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

Definition at line 151 of file class.ilChatroomUploadFileGUI.php.

References $data, $params, and date.

Referenced by displayLinkToUploadedFile().

152  {
153  $data = new stdClass();
154 
155  $data->user = $this->gui->object->getPersonalInformation($chat_user);
156  $data->message = $messageString;
157  $data->timestamp = date('c');
158  $data->type = 'message';
159  $data->public = (int) $params['public'];
160  $data->recipients = $params['recipients']; // ? explode(",", $params['recipients']) : array();
161 
162  return $data;
163  }
$params
Definition: disable.php:11
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
+ Here is the caller graph for this function:

◆ checkUploadPath()

ilChatroomUploadFileGUI::checkUploadPath (   $path)

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

Parameters
string$path

Definition at line 82 of file class.ilChatroomUploadFileGUI.php.

References $path, and ilUtil\makeDirParents().

Referenced by uploadFile().

83  {
84  $err = false;
85 
86  switch (true) {
87  case !file_exists($path):
88  if (!ilUtil::makeDirParents($path)) {
89  $err = true;
90  $msg = 'Error: Upload path could not be created!';
91  }
92  break;
93 
94  case !is_dir($path):
95  $err = true;
96  $msg = 'Error: Upload path is not a directory!';
97  break;
98 
99  case !is_readable($path):
100  $err = true;
101  $msg = 'Error: Upload path is not readable!';
102  break;
103 
104  default:
105  }
106 
107  if ($err) {
108  throw new Exception($msg);
109  }
110  }
PHPExcel root directory.
Definition: Database.php:30
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deliverFile()

ilChatroomUploadFileGUI::deliverFile ( )

Definition at line 165 of file class.ilChatroomUploadFileGUI.php.

166  {
167  // send file
168 
169  echo "hello world";
170  }

◆ displayLinkToUploadedFile()

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

Definition at line 112 of file class.ilChatroomUploadFileGUI.php.

References ilChatroomGUIHandler\$ilCtrl, $message, $params, $query, $response, array, buildMessage(), exit, and ilUtil\stripSlashes().

Referenced by uploadFile().

113  {
114  global $ilCtrl;
115 
116  $scope = $room->getRoomId();
117  $params = array();
118  $params['public'] = 1;
122  $message = json_encode($this->buildMessage(
123  json_encode(array(
124  'format' => array(),
125  'content' => ilUtil::stripSlashes(
126  'Eine neue Datei mit dem Link ' .
127  $ilCtrl->getLinkTarget($this->gui, 'uploadFile-deliverFile') .
128  ' wurde hochgeladen'
129  )
130  )),
131  $params,
132  $chat_user
133  ));
134 
135  $params = array_merge($params, array('message' => $message));
136  $query = http_build_query($params);
137 
138  $connector = $this->gui->getConnector();
139  $response = $connector->post($scope, $query);
140  $responseObject = json_decode($response);
141  /*
142  if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
143  {
144  $room->addHistoryEntry( $message, $recipient, $publicMessage );
145  }
146  */
147  echo $response;
148  exit;
149  }
$params
Definition: disable.php:11
catch(Exception $e) $message
$query
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
buildMessage($messageString, $params, ilChatroomUser $chat_user)
Create styles array
The data for the language used.
$response
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeDefault()

ilChatroomUploadFileGUI::executeDefault (   $requestedMethod)

Default execute method.

Parameters
string$requestedMethod

Definition at line 22 of file class.ilChatroomUploadFileGUI.php.

23  {
24  }

◆ getUploadPath()

ilChatroomUploadFileGUI::getUploadPath ( )

Returns upload path.

Returns
string

Definition at line 71 of file class.ilChatroomUploadFileGUI.php.

References $path, and ilUtil\getDataDir().

Referenced by uploadFile().

72  {
73  $path = ilUtil::getDataDir() . "/chatroom/" . $this->gui->object->getId() . "/uploads/";
74 
75  return $path;
76  }
static getDataDir()
get data directory (outside webspace)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ uploadFile()

ilChatroomUploadFileGUI::uploadFile ( )

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

ilObjUser $ilUser

Todo:
: filename must be unique.

Definition at line 30 of file class.ilChatroomUploadFileGUI.php.

References $file, $filename, ilChatroomGUIHandler\$ilUser, $target, $type, ilChatroom\byObjectId(), checkUploadPath(), displayLinkToUploadedFile(), getUploadPath(), and ilChatroomGUIHandler\redirectIfNoPermission().

31  {
32  $this->redirectIfNoPermission('read');
33 
34  $upload_path = $this->getUploadPath();
35 
36  $this->checkUploadPath($upload_path);
37 
41  $file = $_FILES['file_to_upload']['tmp_name'];
42  $filename = $_FILES['file_to_upload']['name'];
43  $type = $_FILES['file_to_upload']['type'];
44  $target = $upload_path . $filename;
45 
46  if (ilUtil::moveUploadedFile($file, $filename, $target)) {
47  global $ilUser;
48 
49  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
50  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
51 
52  $room = ilChatroom::byObjectId($this->gui->object->getId());
53  $chat_user = new ilChatroomUser($ilUser, $room);
54  $user_id = $chat_user->getUserId();
55 
56  if (!$room) {
57  throw new Exception('unkown room');
58  } elseif (!$room->isSubscribed($chat_user->getUserId())) {
59  throw new Exception('not subscribed');
60  }
61 
62  $room->saveFileUploadToDb($user_id, $filename, $type);
63  $this->displayLinkToUploadedFile($room, $chat_user);
64  }
65  }
$type
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
checkUploadPath($path)
Checks if given upload path exists, is readable or can be created.
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

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