ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilCloudPluginUploadGUI Class Reference

Class ilCloudPluginUploadGUI. More...

+ Inheritance diagram for ilCloudPluginUploadGUI:
+ Collaboration diagram for ilCloudPluginUploadGUI:

Public Member Functions

 executeCommand ()
 execute command More...
 
 asyncUploadFile ()
 
 initUploadForm ()
 
 cancelAll ()
 
 uploadFiles ()
 Update properties. More...
 
 handleFileUpload ($file_upload)
 
- Public Member Functions inherited from ilCloudPluginGUI
 __construct ($plugin_service_class)
 
 getPluginObject ()
 
 getPluginHookObject ()
 
 getAdminConfigObject ()
 
 getService ()
 
 txt ($var="")
 
 executeCommand ()
 

Protected Member Functions

 uploadDirectory ($dir, $parent_id, $file_tree, $keep_structure=true)
 Recursive Method to upload a directory. More...
 

Protected Attributes

 $form
 
- Protected Attributes inherited from ilCloudPluginGUI
 $service = null
 

Detailed Description

Class ilCloudPluginUploadGUI.

Standard class for uploading files. Can be overwritten if needed.

Author
Timon Amstutz timon.nosp@m..ams.nosp@m.tutz@.nosp@m.ilub.nosp@m..unib.nosp@m.e.ch
Version
$Id:

Definition at line 17 of file class.ilCloudPluginUploadGUI.php.

Member Function Documentation

◆ asyncUploadFile()

ilCloudPluginUploadGUI::asyncUploadFile ( )

Definition at line 44 of file class.ilCloudPluginUploadGUI.php.

45 {
46 global $DIC;
47 $ilTabs = $DIC['ilTabs'];
48
49 $ilTabs->activateTab("content");
50 $this->initUploadForm();
51 echo $this->form->getHTML();
52
53 $options = new stdClass();
54 $options->dropZone = "#ilFileUploadDropZone_1";
55 $options->fileInput = "#ilFileUploadInput_1";
56 $options->submitButton = "uploadFiles";
57 $options->cancelButton = "cancelAll";
58 $options->dropArea = "#ilFileUploadDropArea_1";
59 $options->fileList = "#ilFileUploadList_1";
60 $options->fileSelectButton = "#ilFileUploadFileSelect_1";
61 echo "<script language='javascript' type='text/javascript'>var fileUpload1 = new ilFileUpload(1, " . ilJsonUtil::encode($options) . ");</script>";
62
63 $_SESSION["cld_folder_id"] = $_POST["folder_id"];
64
65 exit;
66 }
$_POST["username"]
$_SESSION["AccountId"]
static encode($mixed, $suppress_native=false)
exit
Definition: login.php:29
$DIC
Definition: xapitoken.php:46

References $_POST, $_SESSION, $DIC, ilJsonUtil\encode(), exit, and initUploadForm().

+ Here is the call graph for this function:

◆ cancelAll()

ilCloudPluginUploadGUI::cancelAll ( )

Definition at line 101 of file class.ilCloudPluginUploadGUI.php.

102 {
103 echo "<script language='javascript' type='text/javascript'>window.parent.il.CloudFileList.afterUpload('cancel');</script>";
104 exit;
105 }

References exit.

◆ executeCommand()

ilCloudPluginUploadGUI::executeCommand ( )

execute command

Reimplemented from ilCloudPluginGUI.

Definition at line 29 of file class.ilCloudPluginUploadGUI.php.

30 {
31 global $DIC;
32 $ilCtrl = $DIC['ilCtrl'];
33
34 $cmd = $ilCtrl->getCmd();
35
36 switch ($cmd) {
37 default:
38 $this->$cmd();
39 break;
40 }
41 }
global $ilCtrl
Definition: ilias.php:18

References $DIC, and $ilCtrl.

◆ handleFileUpload()

ilCloudPluginUploadGUI::handleFileUpload (   $file_upload)

Definition at line 141 of file class.ilCloudPluginUploadGUI.php.

142 {
143 // create answer object
144 $response = new stdClass();
145 $response->fileName = $_POST["title"];
146 $response->fileSize = intval($file_upload["size"]);
147 $response->fileType = $file_upload["type"];
148 $response->fileUnzipped = $file_upload["extract"];
149 $response->error = null;
150
152
153 if ($file_upload["extract"]) {
154 $newdir = ilUtil::ilTempnam();
155 ilUtil::makeDir($newdir);
156
157 include_once './Services/Utilities/classes/class.ilFileUtils.php';
158 try {
159 ilFileUtils::processZipFile($newdir, $file_upload["tmp_name"], $file_upload["keep_structure"]);
160 } catch (Exception $e) {
161 $response->error = $e->getMessage();
162 ilUtil::delDir($newdir);
163 exit;
164 }
165
166 try {
167 $this->uploadDirectory($newdir, $_SESSION["cld_folder_id"], $file_tree, $file_upload["keep_structure"]);
168 } catch (Exception $e) {
169 $response->error = $e->getMessage();
170 ilUtil::delDir($newdir);
171 exit;
172 }
173
174 ilUtil::delDir($newdir);
175
176 return $response;
177 } else {
178 $file_tree->uploadFileToService($_SESSION["cld_folder_id"], $file_upload["tmp_name"], $_POST["title"]);
179
180 return $response;
181 }
182 }
uploadDirectory($dir, $parent_id, $file_tree, $keep_structure=true)
Recursive Method to upload a directory.
static processZipFile($a_directory, $a_file, $structure, $ref_id=null, $containerType=null, $tree=null, $access_handler=null)
unzips in given directory and processes uploaded zip for use as single files
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
$response

References $_POST, $_SESSION, Vendor\Package\$e, $response, ilUtil\delDir(), exit, ilCloudFileTree\getFileTreeFromSession(), ilUtil\ilTempnam(), ilUtil\makeDir(), ilFileUtils\processZipFile(), and uploadDirectory().

Referenced by uploadFiles().

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

◆ initUploadForm()

ilCloudPluginUploadGUI::initUploadForm ( )

Definition at line 69 of file class.ilCloudPluginUploadGUI.php.

70 {
71 global $DIC;
72 $ilCtrl = $DIC['ilCtrl'];
73 $lng = $DIC['lng'];
74
75 include_once("./Services/Form/classes/class.ilDragDropFileInputGUI.php");
76 include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
77
78 $this->form = new ilPropertyFormGUI();
79 $this->form->setId("upload");
80 $this->form->setMultipart(true);
81 $this->form->setHideLabels();
82
83 $file = new ilDragDropFileInputGUI($lng->txt("cld_upload_files"), "upload_files");
84 $file->setRequired(true);
85 $this->form->addItem($file);
86
87 $this->form->addCommandButton("uploadFiles", $lng->txt("upload"));
88 $this->form->addCommandButton("cancelAll", $lng->txt("cancel"));
89
90 $this->form->setTableWidth("100%");
91 $this->form->setTitle($lng->txt("upload_files_title"));
92 // $this->form->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $lng->txt('obj_file'));
93 $this->form->setTitleIcon(ilUtil::getImagePath('icon_dcl_file.svg'), $lng->txt('obj_file'));
94
95 $this->form->setTitle($lng->txt("upload_files"));
96 $this->form->setFormAction($ilCtrl->getFormAction($this, "uploadFiles"));
97 $this->form->setTarget("cld_blank_target");
98 }
This class represents a file input property where multiple files can be dopped in a property form.
This class represents a property form user interface.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$lng

References $DIC, $ilCtrl, $lng, and ilUtil\getImagePath().

Referenced by asyncUploadFile(), and uploadFiles().

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

◆ uploadDirectory()

ilCloudPluginUploadGUI::uploadDirectory (   $dir,
  $parent_id,
  $file_tree,
  $keep_structure = true 
)
protected

Recursive Method to upload a directory.

Parameters
string$dirpath to directory
int$parent_idid of parent folder
ilCloudFileTree$file_tree
bool$keep_structureif false, only files will be extracted, without folder structure
Exceptions
ilCloudException

Definition at line 195 of file class.ilCloudPluginUploadGUI.php.

196 {
197 $dirlist = opendir($dir);
198
199 while (false !== ($file = readdir($dirlist))) {
200 if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file)) {
201 global $DIC;
202 $lng = $DIC['lng'];
203 throw new ilCloudException($lng->txt("filenames_not_supported"), ilFileUtilsException::$BROKEN_FILE);
204 }
205 if ($file != '.' && $file != '..') {
206 $newpath = $dir . '/' . $file;
207 if (is_dir($newpath)) {
208 if ($keep_structure) {
209 $newnode = $file_tree->addFolderToService($parent_id, basename($newpath));
210 $this->uploadDirectory($newpath, $newnode->getId(), $file_tree);
211 } else {
212 $this->uploadDirectory($newpath, $parent_id, $file_tree, false);
213 }
214 } else {
215 $file_tree->uploadFileToService($parent_id, $newpath, basename($newpath));
216 }
217 }
218 }
219 closedir($dirlist);
220 }
Class ilCloudException.

References ilFileUtilsException\$BROKEN_FILE, $DIC, $lng, and uploadDirectory().

Referenced by handleFileUpload(), and uploadDirectory().

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

◆ uploadFiles()

ilCloudPluginUploadGUI::uploadFiles ( )

Update properties.

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

113 {
114 $response = new stdClass();
115 $response->error = null;
116 $response->debug = null;
117
118 $this->initUploadForm();
119 if ($this->form->checkInput()) {
120 try {
121 $fileresult = $this->handleFileUpload($this->form->getInput("upload_files"));
122 if ($fileresult) {
123 $response = (object) array_merge((array) $response, (array) $fileresult);
124 }
125 } catch (ilException $e) {
126 $response->error = $e->getMessage();
127 }
128 } else {
130 $response->error = $error->getMessage();
131 }
132
133 // send response object (don't use 'application/json' as IE wants to download it!)
134 header('Vary: Accept');
135 header('Content-type: text/plain');
137 exit;
138 }
Base class for ILIAS Exception handling.

References Vendor\Package\$e, $response, ilJsonUtil\encode(), exit, handleFileUpload(), initUploadForm(), and ilCloudException\UPLOAD_FAILED.

+ Here is the call graph for this function:

Field Documentation

◆ $form

ilCloudPluginUploadGUI::$form
protected

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


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