ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
ILIAS\WebDAV\Mount\DocumentFormGUI Class Reference
+ Inheritance diagram for ILIAS\WebDAV\Mount\DocumentFormGUI:
+ Collaboration diagram for ILIAS\WebDAV\Mount\DocumentFormGUI:

Public Member Functions

 __construct (protected Document $document, protected Repository $mount_instructions_repository, protected ilHtmlPurifierInterface $document_purifier, protected ilObjUser $actor, protected Filesystem $tmp_filesystem, protected FileUpload $file_upload, protected string $form_action, protected string $save_command, protected string $cancel_command, protected bool $is_editable)
 
 saveObject ()
 
 updateObject ()
 
 hasTranslatedInfo ()
 
 hasTranslatedError ()
 
 getTranslatedInfo ()
 
 getTranslatedError ()
 
- Public Member Functions inherited from ilPropertyFormGUI
 __construct ()
 
 executeCommand ()
 
 setTableWidth (string $a_width)
 
 getTableWidth ()
 
 setMode (string $a_mode)
 
 getMode ()
 
 setTitle (string $a_title)
 
 getTitle ()
 
 setTitleIcon (string $a_titleicon)
 
 getTitleIcon ()
 
 setDescription (string $a_val)
 
 getDescription ()
 
 setTopAnchor (string $a_val)
 
 getTopAnchor ()
 
 setShowTopButtons (bool $a_val)
 
 getShowTopButtons ()
 
 setForceTopButtons (bool $a_val)
 
 getForceTopButtons ()
 
 addItem ($a_item)
 
 removeItemByPostVar (string $a_post_var, bool $a_remove_unused_headers=false)
 
 getItemByPostVar (string $a_post_var)
 
 setItems (array $a_items)
 
 getItems ()
 
 getInputItemsRecursive ()
 returns a flat array of all input items including the possibly existing subitems recursively More...
 
 setDisableStandardMessage (bool $a_val)
 
 getDisableStandardMessage ()
 
 getHideLabels ()
 
 setHideLabels (bool $a_value=true)
 
 setValuesByArray (array $a_values, bool $a_restrict_to_value_keys=false)
 
 setValuesByPost ()
 
 checkInput ()
 
 getInput (string $a_post_var, bool $ensureValidation=true)
 Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-POST variable, identified by the passed postvar. More...
 
 addCommandButton (string $a_cmd, string $a_text, string $a_id="")
 
 getCommandButtons ()
 
 clearCommandButtons ()
 
 getContent ()
 
 insertItem ( $item, bool $a_sub_item=false)
 
 addAsyncOnloadCode (string $code)
 
 getHTML ()
 
 getHTMLAsync ()
 
 getFileUpload (string $a_field, ?string $a_index=null, ?string $a_sub_index=null)
 Get file upload data. More...
 
 hasFileUpload (string $a_field, ?string $a_index=null, ?string $a_sub_index=null)
 
 moveFileUpload (string $a_target_directory, string $a_field, ?string $a_target_name=null, ?string $a_index=null, ?string $a_sub_index=null)
 Move upload to target directory. More...
 
- Public Member Functions inherited from ilFormGUI
 setFormAction (string $a_formaction)
 
 getFormAction ()
 
 setTarget (string $a_target)
 
 getTarget ()
 
 setMultipart (bool $a_multipart)
 
 getMultipart ()
 
 setId (string $a_id)
 
 getId ()
 
 setName (string $a_name)
 
 getName ()
 
 setKeepOpen (bool $a_keepopen)
 
 getKeepOpen ()
 
 setOpenTag (bool $a_open)
 
 getOpenTag ()
 
 setCloseTag (bool $a_val)
 
 getCloseTag ()
 
 setPreventDoubleSubmission (bool $a_val)
 
 getPreventDoubleSubmission ()
 
 getHTML ()
 
 getContent ()
 

Protected Member Functions

 initForm ()
 
 createFilledObject (Document $document)
 
 getRawMountInstructionsFromFileUpload (UploadResult $upload_result)
 
 getFileUploadResult ()
 
- Protected Member Functions inherited from ilPropertyFormGUI
 getRequestedPostVar ()
 
 getFileHash ()
 
 hideRequired (string $a_type)
 
 appendOnloadCode (string $html)
 
 rebuildUploadedFiles ()
 
 checkForRequiredField ()
 

Protected Attributes

string $translated_error = ''
 
string $translated_info = ''
 
- Protected Attributes inherited from ilPropertyFormGUI
bool $required_text = false
 
ilLanguage $lng
 
ilCtrl $ctrl
 
ilTemplate $tpl
 
ilObjUser $user = null
 
ilSetting $settings = null
 
string $mode = "std"
 
bool $check_input_called = false
 
bool $disable_standard_message = false
 
string $top_anchor = "il_form_top"
 
string $title = ''
 
string $titleicon = ""
 
string $description = ""
 
string $tbl_width = ""
 
bool $show_top_buttons = true
 
bool $hide_labels = false
 
bool $force_top_buttons = false
 
HTTP Services $http
 
Refinery Factory $refinery = null
 
ilGlobalTemplateInterface $global_tpl = null
 
 $onload_code = []
 
- Protected Attributes inherited from ilFormGUI
string $formaction = ""
 
bool $multipart = false
 
bool $keepopen = false
 
bool $opentag = true
 
string $id = ''
 
string $name = ''
 
string $target = ''
 
bool $prevent_double_submission = false
 

Detailed Description

Definition at line 37 of file DocumentFormGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\WebDAV\Mount\DocumentFormGUI::__construct ( protected Document  $document,
protected Repository  $mount_instructions_repository,
protected ilHtmlPurifierInterface  $document_purifier,
protected ilObjUser  $actor,
protected Filesystem  $tmp_filesystem,
protected FileUpload  $file_upload,
protected string  $form_action,
protected string  $save_command,
protected string  $cancel_command,
protected bool  $is_editable 
)

Definition at line 42 of file DocumentFormGUI.php.

53 {
55
56 $this->initForm();
57 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\WebDAV\Mount\DocumentFormGUI\initForm().

+ Here is the call graph for this function:

Member Function Documentation

◆ createFilledObject()

ILIAS\WebDAV\Mount\DocumentFormGUI::createFilledObject ( Document  $document)
protected

Definition at line 165 of file DocumentFormGUI.php.

165 : Document
166 {
167 if (!$this->checkInput()) {
168 throw new InvalidArgumentException($this->lng->txt('form_input_not_valid'));
169 }
170
171 $document_already_exists = $document->getId() > 0;
172
173 if (!$document_already_exists) {
174 $upload_result = $this->getFileUploadResult();
175 }
176
177 if (!$document_already_exists && !$upload_result->isOK()) {
178 throw new InvalidArgumentException($this->lng->txt('form_input_not_valid'));
179 }
180
181 $title = $this->getInput('title');
182 $language = $this->getInput('lng');
183 $creation_ts = $document_already_exists ? $document->getCreationTs() : ilUtil::now();
184 $modification_ts = $document_already_exists ? ilUtil::now() : $creation_ts;
185 $owner_id = $document_already_exists ? $document->getOwnerUsrId() : $this->actor->getId();
186 $last_modified_usr_id = $this->actor->getId();
187 $sorting = $document_already_exists ? $document->getSorting()
188 : $this->mount_instructions_repository->getHighestSortingNumber() + 1;
189
190 $mount_instruction_for_language_exists = $this->mount_instructions_repository->doMountInstructionsExistByLanguage(
191 $language
192 );
193
194 if (!$document_already_exists && $mount_instruction_for_language_exists) {
195 throw new InvalidArgumentException($this->lng->txt('webdav_choosen_language_already_used'));
196 }
197
198 if ($document_already_exists && $document->getLanguage() !== $language &&
199 $mount_instruction_for_language_exists > 0 &&
200 $mount_instruction_for_language_exists !== $document->getId()) {
201 throw new InvalidArgumentException($this->lng->txt('webdav_chosen_language_already_used'));
202 }
203
204 if ($document_already_exists) {
205 $raw_mount_instructions = '';
206 $processed_mount_instructions = '';
207 } else {
208 $raw_mount_instructions = $this->getRawMountInstructionsFromFileUpload($upload_result);
209 $document_processor = $upload_result->getMimeType() === 'text/html'
210 ? new HtmlDocumentProcessor($this->document_purifier)
211 : new TextDocumentProcessor();
212 $processed_mount_instructions = $document_processor->processMountInstructions($raw_mount_instructions);
213 }
214
215 $id = $document_already_exists ? $document->getId()
216 : $this->mount_instructions_repository->getNextMountInstructionsDocumentId();
217
218 return new Document(
219 $id,
220 $title,
221 $raw_mount_instructions,
222 json_encode($processed_mount_instructions),
223 $language,
224 $creation_ts,
225 $modification_ts,
226 $owner_id,
227 $last_modified_usr_id,
228 $sorting
229 );
230 }
getRawMountInstructionsFromFileUpload(UploadResult $upload_result)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
static now()
Return current timestamp in Y-m-d H:i:s format.

References ilFormGUI\$id, ilPropertyFormGUI\$title, ilPropertyFormGUI\checkInput(), ILIAS\WebDAV\Mount\Document\getCreationTs(), ILIAS\WebDAV\Mount\DocumentFormGUI\getFileUploadResult(), ILIAS\WebDAV\Mount\Document\getId(), ilPropertyFormGUI\getInput(), ILIAS\WebDAV\Mount\Document\getLanguage(), ILIAS\WebDAV\Mount\Document\getOwnerUsrId(), ILIAS\WebDAV\Mount\DocumentFormGUI\getRawMountInstructionsFromFileUpload(), ILIAS\WebDAV\Mount\Document\getSorting(), ILIAS\Repository\lng(), and ilUtil\now().

Referenced by ILIAS\WebDAV\Mount\DocumentFormGUI\saveObject(), and ILIAS\WebDAV\Mount\DocumentFormGUI\updateObject().

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

◆ getFileUploadResult()

ILIAS\WebDAV\Mount\DocumentFormGUI::getFileUploadResult ( )
protected

Definition at line 264 of file DocumentFormGUI.php.

264 : UploadResult
265 {
266 if (!$this->file_upload->hasUploads()) {
267 throw new InvalidArgumentException('webdav_error_no_upload');
268 }
269 if (!$this->file_upload->hasBeenProcessed()) {
270 $this->file_upload->process();
271 }
272
273 $upload_result = array_values($this->file_upload->getResults())[0];
274
275 if (!$upload_result) {
276 $this->getItemByPostVar('document')->setAlert($this->lng->txt('form_msg_file_no_upload'));
277 throw new InvalidArgumentException($this->lng->txt('form_input_not_valid'));
278 }
279
280 return $upload_result;
281 }
getItemByPostVar(string $a_post_var)

References ilPropertyFormGUI\getItemByPostVar(), and ILIAS\Repository\lng().

Referenced by ILIAS\WebDAV\Mount\DocumentFormGUI\createFilledObject().

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

◆ getRawMountInstructionsFromFileUpload()

ILIAS\WebDAV\Mount\DocumentFormGUI::getRawMountInstructionsFromFileUpload ( UploadResult  $upload_result)
protected

Definition at line 232 of file DocumentFormGUI.php.

232 : string
233 {
234 if ($upload_result->getName() === '') {
235 throw new InvalidArgumentException('uploaded file has no name');
236 }
237
238 if (!$upload_result->isOK()) {
239 $this->getItemByPostVar('document')->setAlert($upload_result->getStatus()->getMessage());
240 throw new InvalidArgumentException($this->lng->txt('form_input_not_valid'));
241 }
242
243 $this->file_upload->moveOneFileTo(
244 $upload_result,
245 '/mount_instructions',
247 '',
248 true
249 );
250
251 $path_to_file = '/mount_instructions/' . $upload_result->getName();
252 if (!$this->tmp_filesystem->has($path_to_file)) {
253 $this->getItemByPostVar('document')->setAlert($this->lng->txt('form_msg_file_no_upload'));
254 throw new InvalidArgumentException($this->lng->txt('form_input_not_valid'));
255 }
256
257 $raw_content = $this->tmp_filesystem->read($path_to_file);
258
259 $this->tmp_filesystem->delete($path_to_file);
260
261 return $raw_content;
262 }
const TEMPORARY
The ILIAS temporary directory.
Definition: Location.php:53

References ilPropertyFormGUI\getItemByPostVar(), ILIAS\FileUpload\DTO\UploadResult\getName(), ILIAS\FileUpload\DTO\UploadResult\getStatus(), ILIAS\FileUpload\DTO\UploadResult\isOK(), ILIAS\Repository\lng(), and ILIAS\FileUpload\Location\TEMPORARY.

Referenced by ILIAS\WebDAV\Mount\DocumentFormGUI\createFilledObject().

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

◆ getTranslatedError()

ILIAS\WebDAV\Mount\DocumentFormGUI::getTranslatedError ( )

Definition at line 160 of file DocumentFormGUI.php.

160 : string
161 {
163 }

References ILIAS\WebDAV\Mount\DocumentFormGUI\$translated_error.

◆ getTranslatedInfo()

ILIAS\WebDAV\Mount\DocumentFormGUI::getTranslatedInfo ( )

Definition at line 155 of file DocumentFormGUI.php.

155 : string
156 {
158 }

References ILIAS\WebDAV\Mount\DocumentFormGUI\$translated_info.

◆ hasTranslatedError()

ILIAS\WebDAV\Mount\DocumentFormGUI::hasTranslatedError ( )

Definition at line 150 of file DocumentFormGUI.php.

150 : bool
151 {
152 return $this->translated_error !== '';
153 }

◆ hasTranslatedInfo()

ILIAS\WebDAV\Mount\DocumentFormGUI::hasTranslatedInfo ( )

Definition at line 145 of file DocumentFormGUI.php.

145 : bool
146 {
147 return $this->translated_info !== '';
148 }

◆ initForm()

ILIAS\WebDAV\Mount\DocumentFormGUI::initForm ( )
protected

Definition at line 59 of file DocumentFormGUI.php.

59 : void
60 {
61 $document_already_exists = $this->document->getId() > 0;
62 if ($document_already_exists) {
63 $this->setTitle($this->lng->txt('webdav_form_edit_doc_head'));
64 } else {
65 $this->setTitle($this->lng->txt('webdav_form_new_doc_head'));
66 }
67
68 $this->setFormAction($this->form_action);
69
70 $title = new ilTextInputGUI($this->lng->txt('webdav_form_document_title'), 'title');
71 $title->setInfo($this->lng->txt('webdav_form_document_title_info'));
72 $title->setRequired(true);
73 $title->setDisabled(!$this->is_editable);
74 $title->setValue($this->document->getTitle());
75 $title->setMaxLength(255);
76 $this->addItem($title);
77
78 $document_label = $this->lng->txt('webdav_form_document');
79 $document_by_line = $this->lng->txt('webdav_form_document_info');
80
81 $language_selection = new ilSelectInputGUI(
82 $this->lng->txt('language'),
83 'lng'
84 );
85 $language_selection->setRequired(true);
86
87 $options = [];
88 foreach ($this->lng->getInstalledLanguages() as $lng) {
89 $options[$lng] = $this->lng->txt('meta_l_' . $lng, 'meta');
90 }
91
92 asort($options);
93
94 $language_selection->setOptions(['' => $this->lng->txt('please_choose')] + $options);
95 $language_selection->setValue($this->document->getLanguage());
96
97 $this->addItem($language_selection);
98
99 if ($document_already_exists) {
100 $document_id = new ilHiddenInputGUI('document_id');
101 $document_id->setValue((string) $this->document->getId());
102 $this->addItem($document_id);
103 } else {
104 $document_upload = new ilFileInputGUI($document_label, 'document');
105 $document_upload->setInfo($document_by_line);
106 $document_upload->setRequired(true);
107 $document_upload->setDisabled(!$this->is_editable);
108 $document_upload->setSuffixes(['html', 'htm', 'txt']);
109 $this->addItem($document_upload);
110 }
111
112 if ($this->is_editable) {
113 $this->addCommandButton($this->save_command, $this->lng->txt('save'));
114 }
115 }
This class represents a file property in a property form.
setFormAction(string $a_formaction)
This class represents a hidden form property in a property form.
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
This class represents a selection list property in a property form.
This class represents a text property in a property form.

References ilPropertyFormGUI\$lng, ILIAS\UI\Implementation\Component\Input\Field\$options, ilPropertyFormGUI\$title, ilPropertyFormGUI\addCommandButton(), ilPropertyFormGUI\addItem(), ILIAS\Repository\lng(), ilFormGUI\setFormAction(), and ilPropertyFormGUI\setTitle().

Referenced by ILIAS\WebDAV\Mount\DocumentFormGUI\__construct().

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

◆ saveObject()

ILIAS\WebDAV\Mount\DocumentFormGUI::saveObject ( )

Definition at line 117 of file DocumentFormGUI.php.

117 : bool
118 {
119 try {
120 $this->document = $this->createFilledObject($this->document);
121 $this->mount_instructions_repository->createMountInstructionsDocumentEntry($this->document);
122 } catch (InvalidArgumentException $e) {
123 $this->setValuesByPost();
124 $this->translated_error .= $e->getMessage();
125 return false;
126 }
127
128 return true;
129 }

References Vendor\Package\$e, ILIAS\WebDAV\Mount\DocumentFormGUI\createFilledObject(), and ilPropertyFormGUI\setValuesByPost().

+ Here is the call graph for this function:

◆ updateObject()

ILIAS\WebDAV\Mount\DocumentFormGUI::updateObject ( )

Definition at line 131 of file DocumentFormGUI.php.

131 : bool
132 {
133 try {
134 $this->document = $this->createFilledObject($this->document);
135 $this->mount_instructions_repository->updateMountInstructions($this->document);
136 } catch (InvalidArgumentException $e) {
137 $this->setValuesByPost();
138 $this->translated_error .= $e->getMessage();
139 return false;
140 }
141
142 return true;
143 }

References Vendor\Package\$e, ILIAS\WebDAV\Mount\DocumentFormGUI\createFilledObject(), and ilPropertyFormGUI\setValuesByPost().

+ Here is the call graph for this function:

Field Documentation

◆ $translated_error

string ILIAS\WebDAV\Mount\DocumentFormGUI::$translated_error = ''
protected

◆ $translated_info

string ILIAS\WebDAV\Mount\DocumentFormGUI::$translated_info = ''
protected

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