ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilFileStandardDropzoneInputGUI Class Reference

Class ilFileStandardDropzoneInputGUI. More...

+ Inheritance diagram for ilFileStandardDropzoneInputGUI:
+ Collaboration diagram for ilFileStandardDropzoneInputGUI:

Public Member Functions

 __construct ($cancel_command, $a_title="", $a_postvar="")
 ilFileStandardDropzoneInputGUI constructor. More...
 
 getUploadUrl ()
 
 setUploadUrl ($upload_url)
 Set the URL (using ilCtrl->getFormAction() ) to override the Endpoint the Form will be sent to. More...
 
 getMaxFiles ()
 
 setMaxFiles ($max_files)
 
 getMaxFilesize ()
 
 setMaxFilesize (\ILIAS\Data\DataSize $max_file_size)
 
 getDropzoneMessage ()
 
 setDropzoneMessage ($dropzone_message)
 
 render ($a_mode="")
 
 checkInput ()
 
- Public Member Functions inherited from ilFileInputGUI
 __construct ($a_title="", $a_postvar="")
 Constructor. More...
 
 setValueByArray ($a_values)
 Set value by array. More...
 
 setValue ($a_value)
 Set Value. More...
 
 getValue ()
 Get Value. More...
 
 setSize ($a_size)
 Set Size. More...
 
 getSize ()
 Get Size. More...
 
 setFilename ($a_val)
 Set filename value (if filename selection is enabled) More...
 
 getFilename ()
 Get Value. More...
 
 setSuffixes ($a_suffixes)
 Set Accepted Suffixes. More...
 
 getSuffixes ()
 Get Accepted Suffixes. More...
 
 setForbiddenSuffixes ($a_suffixes)
 Set forbidden Suffixes. More...
 
 getForbiddenSuffixes ()
 Get Accepted Suffixes. More...
 
 setPending ($a_val)
 Set pending filename value. More...
 
 getPending ()
 Get pending filename. More...
 
 enableFileNameSelection ($a_post_var)
 If enabled, users get the possibility to enter a filename for the uploaded file. More...
 
 isFileNameSelectionEnabled ()
 Check if filename selection is enabled. More...
 
 getFileNamePostVar ()
 Get file name post var. More...
 
 setALlowDeletion ($a_val)
 Set allow deletion. More...
 
 getALlowDeletion ()
 Get allow deletion. More...
 
 checkInput ()
 Check input, strip slashes etc. More...
 
 render ($a_mode="")
 Render html. More...
 
 insert ($a_tpl)
 Insert property html. More...
 
 getDeletionFlag ()
 Get deletion flag. More...
 
 getToolbarHTML ()
 Get HTML for toolbar. More...
 
- Public Member Functions inherited from ilSubEnabledFormPropertyGUI
 addSubItem ($a_item)
 Add Subitem. More...
 
 getSubItems ()
 Get Subitems. More...
 
 getSubInputItemsRecursive ()
 returns a flat array of possibly existing subitems recursively More...
 
 checkSubItemsInput ()
 Check SubItems. More...
 
 getSubForm ()
 Get sub form html. More...
 
 getItemByPostVar ($a_post_var)
 Get item by post var. More...
 
- Public Member Functions inherited from ilFormPropertyGUI
 __construct ($a_title="", $a_postvar="")
 Constructor. More...
 
 executeCommand ()
 Execute command. More...
 
 getType ()
 Get Type. More...
 
 setTitle ($a_title)
 Set Title. More...
 
 getTitle ()
 Get Title. More...
 
 setPostVar ($a_postvar)
 Set Post Variable. More...
 
 getPostVar ()
 Get Post Variable. More...
 
 getFieldId ()
 Get Post Variable. More...
 
 setInfo ($a_info)
 Set Information Text. More...
 
 getInfo ()
 Get Information Text. More...
 
 setAlert ($a_alert)
 Set Alert Text. More...
 
 getAlert ()
 Get Alert Text. More...
 
 setRequired ($a_required)
 Set Required. More...
 
 getRequired ()
 Get Required. More...
 
 setDisabled ($a_disabled)
 Set Disabled. More...
 
 getDisabled ()
 Get Disabled. More...
 
 checkInput ()
 Check input, strip slashes etc. More...
 
 setParentForm ($a_parentform)
 Set Parent Form. More...
 
 getParentForm ()
 Get Parent Form. More...
 
 setParent ($a_val)
 Set Parent GUI object. More...
 
 getParent ()
 Get Parent GUI object. More...
 
 getSubForm ()
 Get sub form html. More...
 
 hideSubForm ()
 Sub form hidden on init? More...
 
 setHiddenTitle ($a_val)
 Set hidden title (for screenreaders) More...
 
 getHiddenTitle ()
 Get hidden title. More...
 
 getItemByPostVar ($a_post_var)
 Get item by post var. More...
 
 serializeData ()
 serialize data More...
 
 unserializeData ($a_data)
 unserialize data More...
 
 writeToSession ()
 Write to session. More...
 
 clearFromSession ()
 Clear session value. More...
 
 readFromSession ()
 Read from session. More...
 
 getHiddenTag ($a_post_var, $a_value)
 Get hidden tag (used for disabled properties) More...
 
 setMulti ($a_multi, $a_sortable=false, $a_addremove=true)
 Set Multi. More...
 
 getMulti ()
 Get Multi. More...
 
 setMultiValues (array $a_values)
 Set multi values. More...
 
 getMultiValues ()
 Get multi values. More...
 
 getContentOutsideFormTag ()
 Get content that has to reside outside of the parent form tag, e.g. More...
 
 stripSlashesAddSpaceFallback ($a_str)
 Strip slashes with add space fallback, see https://www.ilias.de/mantis/view.php?id=19727. More...
 
 getTableFilterLabelFor ()
 Get label "for" attribute value for filter. More...
 
 getFormLabelFor ()
 Get label "for" attribute value for form. More...
 

Data Fields

const ASYNC_FILEUPLOAD = "async_fileupload"
 

Protected Member Functions

 handleUploadURL ()
 
 handleSuffixes ()
 
 handleMaxFileSize ($dropzone)
 
 initDropzoneMessage ()
 
- Protected Member Functions inherited from ilFileInputGUI
 outputSuffixes ($a_tpl, $a_block="allowed_suffixes")
 
 getMaxFileSizeString ()
 
 getMaxFileUploads ()
 Get number of maximum file uploads as declared in php.ini. More...
 
- Protected Member Functions inherited from ilFormPropertyGUI
 setType ($a_type)
 Set Type. More...
 
 getMultiIconsHTML ()
 Get HTML for multiple value icons. More...
 

Protected Attributes

 $upload_url = ''
 
 $max_files = 1
 
 $max_file_size
 
 $dropzone_message = ''
 
 $cancel_command
 
- Protected Attributes inherited from ilFileInputGUI
 $lng
 
 $size = 40
 
 $pending
 
 $allow_deletion
 
 $forbidden_suffixes = array()
 
- Protected Attributes inherited from ilSubEnabledFormPropertyGUI
 $sub_items = array()
 
- Protected Attributes inherited from ilFormPropertyGUI
 $ctrl
 
 $lng
 
 $type
 
 $title
 
 $postvar
 
 $info
 
 $alert
 
 $required = false
 
 $parentgui
 
 $parentform
 
 $hidden_title = ""
 
 $multi = false
 
 $multi_sortable = false
 
 $multi_addremove = true
 
 $multi_values
 

Static Protected Attributes

static $count = 0
 
- Static Protected Attributes inherited from ilFileInputGUI
static $check_wsp_quota
 

Additional Inherited Members

- Static Public Member Functions inherited from ilFileInputGUI
static setPersonalWorkspaceQuotaCheck ($a_value)
 
- Static Public Member Functions inherited from ilFormPropertyGUI
static removeProhibitedCharacters ($a_text)
 Remove prohibited characters see #19159. More...
 

Detailed Description

Class ilFileStandardDropzoneInputGUI.

A ilFileStandardDropzoneInputGUI is used in a (legacy) Form to upload Files using the Dropzone of the UI-Framework introduced with ILIAS 5.3. In some cases this can be used as a Drop-In-Replacement of the ilFileInputGUI, but check your usecase after. If you need an example how to use it, see e.g. in UI/examples/Dropzone/File/Standard/with_usage_in_legacy_form.php

Why make it a Drop-In-Replacement and not just replace ilFileInputGUI?

  • There are a lot of different ways a form is handled in ILIAS, sometimes only checkInput is called, sometime developers send their own error-messages and so on. The ilFileStandardDropzoneInputGUI excepts some standard-behavior and would fail in some cases when just replacing the ilFileInputGUI
  • There are a lot of options in ilFileInputGUI which would be difficult to reimplement in ilFileStandardDropzoneInputGUI without discussing them with all devs.
  • Beside ilFileInputGUI there are many other File-InputGUIs with different functionality. We should consolidate their use-cases first.

Attention: This ilFileStandardDropzoneInputGUI changes the behaviour of your form when used: The Form will be sent asynchronously due to limitations of dropped files (see https://stackoverflow.com/questions/1017224/dynamically-set-value-of-a-file-input )

Attention 2: Your form will be sent for every single file (if e.g. setMaxFiles > 1 is set). This is due to the library used, but also because D&D uploads can only be handled asynchronously. Therefore, the endpoint of the form must be able to handle this accordingly. If you have any questions, please contact fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 33 of file class.ilFileStandardDropzoneInputGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileStandardDropzoneInputGUI::__construct (   $cancel_command,
  $a_title = "",
  $a_postvar = "" 
)

ilFileStandardDropzoneInputGUI constructor.

Parameters
string$cancel_commandrequired as a bugfix for mantis 0025881
string$a_title
string$a_postvar

Definition at line 76 of file class.ilFileStandardDropzoneInputGUI.php.

References $cancel_command.

77  {
78  $this->cancel_command = $cancel_command;
79  parent::__construct($a_title, $a_postvar);
80  }

Member Function Documentation

◆ checkInput()

ilFileStandardDropzoneInputGUI::checkInput ( )

Definition at line 206 of file class.ilFileStandardDropzoneInputGUI.php.

References $_POST, ilFormPropertyGUI\getPostVar(), and ilFormPropertyGUI\getRequired().

207  {
208  $hasUploads = $this->dic()->upload()->hasUploads();
209  if ($this->getRequired() && !$hasUploads) {
210  return false; // No file uploaded but is was required
211  }
212 
213  if ($hasUploads) {
214  try {
215  $_POST[$this->getPostVar()] = $_FILES[$this->getPostVar()];
216  } catch (Exception $e) {
217  return false;
218  }
219 
220  return true;
221  }
222 
223  return true;
224  }
getPostVar()
Get Post Variable.
$_POST["username"]
+ Here is the call graph for this function:

◆ getDropzoneMessage()

ilFileStandardDropzoneInputGUI::getDropzoneMessage ( )
Returns
string The message which will be rendered within the dropzone.

Definition at line 150 of file class.ilFileStandardDropzoneInputGUI.php.

References $dropzone_message.

Referenced by initDropzoneMessage(), and render().

+ Here is the caller graph for this function:

◆ getMaxFiles()

ilFileStandardDropzoneInputGUI::getMaxFiles ( )
Returns
int Amount of allowed files in this input

Definition at line 111 of file class.ilFileStandardDropzoneInputGUI.php.

References $max_files.

Referenced by initDropzoneMessage(), and render().

+ Here is the caller graph for this function:

◆ getMaxFilesize()

ilFileStandardDropzoneInputGUI::getMaxFilesize ( )
Returns
allowed size of files which can be uploaded

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

References $max_file_size.

Referenced by handleMaxFileSize().

+ Here is the caller graph for this function:

◆ getUploadUrl()

ilFileStandardDropzoneInputGUI::getUploadUrl ( )
Returns
string the URL where the form will be sent to.

Definition at line 85 of file class.ilFileStandardDropzoneInputGUI.php.

References $upload_url.

Referenced by handleUploadURL(), and render().

+ Here is the caller graph for this function:

◆ handleMaxFileSize()

ilFileStandardDropzoneInputGUI::handleMaxFileSize (   $dropzone)
protected
Parameters
ILIAS\UI\Component\Dropzone\File\Standard$dropzone
Returns
ILIAS

Definition at line 254 of file class.ilFileStandardDropzoneInputGUI.php.

References getMaxFilesize().

Referenced by render().

255  {
256  if ($this->getMaxFilesize()) {
257  $dropzone = $dropzone->withFileSizeLimit($this->getMaxFilesize());
258  }
259 
260  return $dropzone;
261  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleSuffixes()

ilFileStandardDropzoneInputGUI::handleSuffixes ( )
protected

Definition at line 241 of file class.ilFileStandardDropzoneInputGUI.php.

References ilFileInputGUI\getSuffixes(), and ilFileInputGUI\setSuffixes().

Referenced by render().

242  {
243  if (!is_array($this->getSuffixes())) {
244  $this->setSuffixes(array());
245  }
246  }
getSuffixes()
Get Accepted Suffixes.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleUploadURL()

ilFileStandardDropzoneInputGUI::handleUploadURL ( )
protected

Definition at line 227 of file class.ilFileStandardDropzoneInputGUI.php.

References getUploadUrl(), and setUploadUrl().

Referenced by render().

228  {
229  if (!$this->getUploadUrl()) {
230  $parentWrapper = $this;
231  while (!$parentWrapper instanceof ilPropertyFormGUI && $parentWrapper !== null) {
232  $parentWrapper = $parentWrapper->getParent();
233  }
234 
235  $str_replace = str_replace("&", "&", $parentWrapper->getFormAction());
236  $this->setUploadUrl($str_replace . "&" . self::ASYNC_FILEUPLOAD . "=true");
237  }
238  }
This class represents a property form user interface.
setUploadUrl($upload_url)
Set the URL (using ilCtrl->getFormAction() ) to override the Endpoint the Form will be sent to...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initDropzoneMessage()

ilFileStandardDropzoneInputGUI::initDropzoneMessage ( )
protected

Definition at line 264 of file class.ilFileStandardDropzoneInputGUI.php.

References getDropzoneMessage(), getMaxFiles(), and setDropzoneMessage().

Referenced by render().

265  {
266  if (!$this->getDropzoneMessage()) {
267  if ($this->getMaxFiles() === 1) {
268  $this->setDropzoneMessage($this->lng()->txt('drag_file_here'));
269  } else {
270  $this->setDropzoneMessage($this->lng()->txt('drag_files_here'));
271  }
272  }
273  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

ilFileStandardDropzoneInputGUI::render (   $a_mode = "")

Definition at line 168 of file class.ilFileStandardDropzoneInputGUI.php.

References $f, $n, $out, $r, getDropzoneMessage(), getMaxFiles(), ilFormPropertyGUI\getPostVar(), ilFileInputGUI\getSuffixes(), getUploadUrl(), handleMaxFileSize(), handleSuffixes(), handleUploadURL(), initDropzoneMessage(), and ilFileInputGUI\isFileNameSelectionEnabled().

169  {
170  $this->handleUploadURL();
171  $this->handleSuffixes();
172 
173  $f = $this->ui()->factory();
174  $r = $this->ui()->renderer();
175 
176  $this->initDropzoneMessage();
177 
178  $dropzone = $f->dropzone()
179  ->file()
180  ->standard($this->getUploadUrl())
181  ->withParameterName($this->getPostVar())
182  ->withMaxFiles($this->getMaxFiles())
183  ->withMessage($this->getDropzoneMessage())
184  ->withAllowedFileTypes($this->getSuffixes());
185  $dropzone = $this->handleMaxFileSize($dropzone);
186  if ($this->isFileNameSelectionEnabled()) {
187  $dropzone = $dropzone->withUserDefinedFileNamesEnabled(true);
188  }
189 
190  $render = $r->render($dropzone);
191 
192  $n = ++self::$count;
193  $out = "<div id='ilFileStandardDropzoneInputGUIWrapper{$n}'>" . $render . '</div>';
194  // We need some javascript magic
195 
196  $this->ui()->mainTemplate()->addJavaScript('./Services/Form/js/ilFileStandardDropzoneInputGUI.js');
197  $this->ui()->mainTemplate()->addOnLoadCode("ilFileStandardDropzoneInputGUI.init('ilFileStandardDropzoneInputGUIWrapper{$n}', '{$this->cancel_command}');");
198 
199  return $out;
200  }
getSuffixes()
Get Accepted Suffixes.
getPostVar()
Get Post Variable.
isFileNameSelectionEnabled()
Check if filename selection is enabled.
$r
Definition: example_031.php:79
$n
Definition: RandomTest.php:85
+ Here is the call graph for this function:

◆ setDropzoneMessage()

ilFileStandardDropzoneInputGUI::setDropzoneMessage (   $dropzone_message)
Parameters
string$dropzone_messageThe message which will be rendered within the dropzone.

Definition at line 159 of file class.ilFileStandardDropzoneInputGUI.php.

References $dropzone_message.

Referenced by initDropzoneMessage().

160  {
161  $this->dropzone_message = $dropzone_message;
162  }
+ Here is the caller graph for this function:

◆ setMaxFiles()

ilFileStandardDropzoneInputGUI::setMaxFiles (   $max_files)
Parameters
int$max_filesThe amount of files which can be uploaded. Standard is 1 since the old ilFileInputGUI in most cases allows one.

Definition at line 121 of file class.ilFileStandardDropzoneInputGUI.php.

References $max_files.

122  {
123  $this->max_files = $max_files;
124  }

◆ setMaxFilesize()

ilFileStandardDropzoneInputGUI::setMaxFilesize ( \ILIAS\Data\DataSize  $max_file_size)
Parameters
\ILIAS\Data\DataSize$max_file_sizeonly files beneath this size will be accepted to upload. Currently this uses the defined valued of the php.ini

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

References $max_file_size.

142  {
143  $this->max_file_size = $max_file_size;
144  }

◆ setUploadUrl()

ilFileStandardDropzoneInputGUI::setUploadUrl (   $upload_url)

Set the URL (using ilCtrl->getFormAction() ) to override the Endpoint the Form will be sent to.

If not set, the ilFileStandardDropzoneInputGUI will get the Form-Action of it's nearest form

Parameters
string$upload_url
Returns
$this

Definition at line 100 of file class.ilFileStandardDropzoneInputGUI.php.

References $upload_url.

Referenced by handleUploadURL(), and ilObjMediaPoolGUI\initBulkUploadForm().

101  {
102  $this->upload_url = $upload_url;
103 
104  return $this;
105  }
+ Here is the caller graph for this function:

Field Documentation

◆ $cancel_command

ilFileStandardDropzoneInputGUI::$cancel_command
protected

Definition at line 68 of file class.ilFileStandardDropzoneInputGUI.php.

Referenced by __construct().

◆ $count

ilFileStandardDropzoneInputGUI::$count = 0
staticprotected

Definition at line 43 of file class.ilFileStandardDropzoneInputGUI.php.

◆ $dropzone_message

ilFileStandardDropzoneInputGUI::$dropzone_message = ''
protected

◆ $max_file_size

ilFileStandardDropzoneInputGUI::$max_file_size
protected

Definition at line 59 of file class.ilFileStandardDropzoneInputGUI.php.

Referenced by getMaxFilesize(), and setMaxFilesize().

◆ $max_files

ilFileStandardDropzoneInputGUI::$max_files = 1
protected

Definition at line 54 of file class.ilFileStandardDropzoneInputGUI.php.

Referenced by getMaxFiles(), and setMaxFiles().

◆ $upload_url

ilFileStandardDropzoneInputGUI::$upload_url = ''
protected

Definition at line 49 of file class.ilFileStandardDropzoneInputGUI.php.

Referenced by getUploadUrl(), and setUploadUrl().

◆ ASYNC_FILEUPLOAD

const ilFileStandardDropzoneInputGUI::ASYNC_FILEUPLOAD = "async_fileupload"

Definition at line 37 of file class.ilFileStandardDropzoneInputGUI.php.


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