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

Class ilFileStandardDropzoneInputGUI. More...

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

Public Member Functions

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

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 ()
 
- 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 = ''
 
- 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 )

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

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

Member Function Documentation

◆ checkInput()

ilFileStandardDropzoneInputGUI::checkInput ( )

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

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

186  {
187  $hasUploads = $this->dic()->upload()->hasUploads();
188  if ($this->getRequired() && !$hasUploads) {
189  return false; // No file uploaded but is was required
190  }
191 
192  if ($hasUploads) {
193  try {
194  $_POST[$this->getPostVar()] = $_FILES[$this->getPostVar()];
195  } catch (Exception $e) {
196  return false;
197  }
198 
199  return true;
200  }
201 
202  return true;
203  }
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 129 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 90 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 109 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 64 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 233 of file class.ilFileStandardDropzoneInputGUI.php.

References getMaxFilesize().

Referenced by render().

234  {
235  if ($this->getMaxFilesize()) {
236  $dropzone = $dropzone->withFileSizeLimit($this->getMaxFilesize());
237  }
238 
239  return $dropzone;
240  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleSuffixes()

ilFileStandardDropzoneInputGUI::handleSuffixes ( )
protected

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

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

Referenced by render().

221  {
222  if (!is_array($this->getSuffixes())) {
223  $this->setSuffixes(array());
224  }
225  }
getSuffixes()
Get Accepted Suffixes.
Create styles array
The data for the language used.
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 206 of file class.ilFileStandardDropzoneInputGUI.php.

References getUploadUrl(), and setUploadUrl().

Referenced by render().

207  {
208  if (!$this->getUploadUrl()) {
209  $parentWrapper = $this;
210  while (!$parentWrapper instanceof ilPropertyFormGUI && $parentWrapper !== null) {
211  $parentWrapper = $parentWrapper->getParent();
212  }
213 
214  $str_replace = str_replace("&", "&", $parentWrapper->getFormAction());
215  $this->setUploadUrl($str_replace . "&" . self::ASYNC_FILEUPLOAD . "=true");
216  }
217  }
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 243 of file class.ilFileStandardDropzoneInputGUI.php.

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

Referenced by render().

244  {
245  if (!$this->getDropzoneMessage()) {
246  if ($this->getMaxFiles() === 1) {
247  $this->setDropzoneMessage($this->lng()->txt('drag_file_here'));
248  } else {
249  $this->setDropzoneMessage($this->lng()->txt('drag_files_here'));
250  }
251  }
252  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

ilFileStandardDropzoneInputGUI::render (   $a_mode = "")

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

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

148  {
149  $this->handleUploadURL();
150  $this->handleSuffixes();
151 
152  $f = $this->ui()->factory();
153  $r = $this->ui()->renderer();
154 
155  $this->initDropzoneMessage();
156 
157  $dropzone = $f->dropzone()
158  ->file()
159  ->standard($this->getUploadUrl())
160  ->withParameterName($this->getPostVar())
161  ->withMaxFiles($this->getMaxFiles())
162  ->withMessage($this->getDropzoneMessage())
163  ->withAllowedFileTypes($this->getSuffixes());
164  $dropzone = $this->handleMaxFileSize($dropzone);
165  if ($this->isFileNameSelectionEnabled()) {
166  $dropzone = $dropzone->withUserDefinedFileNamesEnabled(true);
167  }
168 
169  $render = $r->render($dropzone);
170 
171  $n = ++self::$count;
172  $out = "<div id='ilFileStandardDropzoneInputGUIWrapper{$n}'>" . $render . '</div>';
173  // We need some javascript magic
174 
175  $this->ui()->mainTemplate()->addJavaScript('./Services/Form/js/ilFileStandardDropzoneInputGUI.js');
176  $this->ui()->mainTemplate()->addOnLoadCode("ilFileStandardDropzoneInputGUI.init('ilFileStandardDropzoneInputGUIWrapper{$n}');");
177 
178  return $out;
179  }
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 138 of file class.ilFileStandardDropzoneInputGUI.php.

References $dropzone_message.

Referenced by initDropzoneMessage().

139  {
140  $this->dropzone_message = $dropzone_message;
141  }
+ 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 100 of file class.ilFileStandardDropzoneInputGUI.php.

References $max_files.

101  {
102  $this->max_files = $max_files;
103  }

◆ 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 120 of file class.ilFileStandardDropzoneInputGUI.php.

References $max_file_size.

121  {
122  $this->max_file_size = $max_file_size;
123  }

◆ 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 79 of file class.ilFileStandardDropzoneInputGUI.php.

References $upload_url.

Referenced by handleUploadURL().

80  {
81  $this->upload_url = $upload_url;
82 
83  return $this;
84  }
+ Here is the caller graph for this function:

Field Documentation

◆ $count

ilFileStandardDropzoneInputGUI::$count = 0
staticprotected

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

◆ $dropzone_message

ilFileStandardDropzoneInputGUI::$dropzone_message = ''
protected

◆ $max_file_size

ilFileStandardDropzoneInputGUI::$max_file_size
protected

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

Referenced by getMaxFilesize(), and setMaxFilesize().

◆ $max_files

ilFileStandardDropzoneInputGUI::$max_files = 1
protected

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

Referenced by getMaxFiles(), and setMaxFiles().

◆ $upload_url

ilFileStandardDropzoneInputGUI::$upload_url = ''
protected

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

Referenced by getUploadUrl(), and setUploadUrl().

◆ ASYNC_FILEUPLOAD

const ilFileStandardDropzoneInputGUI::ASYNC_FILEUPLOAD = "async_fileupload"

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


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