ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
 
 $rbacsystem
 

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

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

Member Function Documentation

◆ buildMessage()

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

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

166 {
167 $data = new stdClass();
168
169 $data->user = $this->gui->object->getPersonalInformation($chat_user);
170 $data->message = $messageString;
171 $data->timestamp = date('c');
172 $data->type = 'message';
173 $data->public = (int)$params['public'];
174 $data->recipients = $params['recipients']; // ? explode(",", $params['recipients']) : array();
175
176 return $data;
177 }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$params
Definition: example_049.php:96

References $data, $params, and date.

Referenced by displayLinkToUploadedFile().

+ 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 95 of file class.ilChatroomUploadFileGUI.php.

96 {
97 $err = false;
98
99 switch(true)
100 {
101 case !file_exists($path):
102 if(!ilUtil::makeDirParents($path))
103 {
104 $err = true;
105 $msg = 'Error: Upload path could not be created!';
106 }
107 break;
108
109 case !is_dir($path):
110 $err = true;
111 $msg = 'Error: Upload path is not a directory!';
112 break;
113
114 case !is_readable($path):
115 $err = true;
116 $msg = 'Error: Upload path is not readable!';
117 break;
118
119 default:
120 }
121
122 if($err)
123 {
124 throw new Exception($msg);
125 }
126 }
$path
Definition: aliased.php:25
PHPExcel root directory.
Definition: PHPExcel.php:30
Util class various functions, usage as namespace.

References $path, and ilUtil\makeDirParents().

Referenced by uploadFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deliverFile()

ilChatroomUploadFileGUI::deliverFile ( )

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

180 {
181 // send file
182
183 echo "hello world";
184 }

◆ displayLinkToUploadedFile()

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

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

129 {
130 global $ilCtrl;
131
132 $scope = $room->getRoomId();
133 $params = array();
134 $params['public'] = 1;
138 $message = json_encode($this->buildMessage(
139 json_encode(array(
140 'format' => array(),
141 'content' => ilUtil::stripSlashes(
142 'Eine neue Datei mit dem Link ' .
143 $ilCtrl->getLinkTarget($this->gui, 'uploadFile-deliverFile') .
144 ' wurde hochgeladen'
145 )
146 )), $params, $chat_user
147 ));
148
149 $params = array_merge($params, array('message' => $message));
150 $query = http_build_query($params);
151
152 $connector = $this->gui->getConnector();
153 $response = $connector->post($scope, $query);
154 $responseObject = json_decode($response);
155 /*
156 if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
157 {
158 $room->addHistoryEntry( $message, $recipient, $publicMessage );
159 }
160 */
161 echo $response;
162 exit;
163 }
buildMessage($messageString, $params, ilChatroomUser $chat_user)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled

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

Referenced by uploadFile().

+ 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

Reimplemented from ilChatroomGUIHandler.

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

24 {
25
26 }

◆ getUploadPath()

ilChatroomUploadFileGUI::getUploadPath ( )

Returns upload path.

Returns
string

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

85 {
86 $path = ilUtil::getDataDir() . "/chatroom/" . $this->gui->object->getId() . "/uploads/";
87
88 return $path;
89 }
static getDataDir()
get data directory (outside webspace)

References $path, and ilUtil\getDataDir().

Referenced by uploadFile().

+ 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.

@global ilObjUser $ilUser

Todo:
: filename must be unique.

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

33 {
34 global $ilCtrl;
35
36 if(!ilChatroom::checkUserPermissions('read', $this->gui->ref_id))
37 {
38 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
39 $ilCtrl->redirectByClass("ilrepositorygui", "");
40 }
41
42 $upload_path = $this->getUploadPath();
43
44 $this->checkUploadPath($upload_path);
45
49 $file = $_FILES['file_to_upload']['tmp_name'];
50 $filename = $_FILES['file_to_upload']['name'];
51 $type = $_FILES['file_to_upload']['type'];
52 $target = $upload_path . $filename;
53
55 {
56 global $ilUser;
57
58 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
59 require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
60
61 $room = ilChatroom::byObjectId($this->gui->object->getId());
62 $chat_user = new ilChatroomUser($ilUser, $room);
63 $user_id = $chat_user->getUserId();
64
65 if(!$room)
66 {
67 throw new Exception('unkown room');
68 }
69 else if(!$room->isSubscribed($chat_user->getUserId()))
70 {
71 throw new Exception('not subscribed');
72 }
73
74 $room->saveFileUploadToDb($user_id, $filename, $type);
75 $this->displayLinkToUploadedFile($room, $chat_user);
76 }
77
78 }
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.
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
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $file, $filename, ilChatroomGUIHandler\$ilCtrl, ilChatroomGUIHandler\$ilUser, $target, ilChatroom\byObjectId(), checkUploadPath(), ilChatroom\checkUserPermissions(), displayLinkToUploadedFile(), getUploadPath(), and ilUtil\moveUploadedFile().

+ Here is the call graph for this function:

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