19declare(strict_types=1);
35use InvalidArgumentException;
44 protected Repository $mount_instructions_repository,
49 protected string $form_action,
50 protected string $save_command,
51 protected string $cancel_command,
52 protected bool $is_editable
61 $document_already_exists = $this->document->getId() > 0;
62 if ($document_already_exists) {
63 $this->
setTitle($this->
lng->txt(
'webdav_form_edit_doc_head'));
65 $this->
setTitle($this->
lng->txt(
'webdav_form_new_doc_head'));
71 $title->setInfo($this->
lng->txt(
'webdav_form_document_title_info'));
73 $title->setDisabled(!$this->is_editable);
74 $title->setValue($this->document->getTitle());
78 $document_label = $this->
lng->txt(
'webdav_form_document');
79 $document_by_line = $this->
lng->txt(
'webdav_form_document_info');
82 $this->
lng->txt(
'language'),
85 $language_selection->setRequired(
true);
88 foreach ($this->
lng->getInstalledLanguages() as
$lng) {
94 $language_selection->setOptions([
'' => $this->
lng->txt(
'please_choose')] +
$options);
95 $language_selection->setValue($this->document->getLanguage());
97 $this->
addItem($language_selection);
99 if ($document_already_exists) {
101 $document_id->setValue((
string) $this->document->getId());
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);
112 if ($this->is_editable) {
121 $this->mount_instructions_repository->createMountInstructionsDocumentEntry($this->document);
122 }
catch (InvalidArgumentException
$e) {
124 $this->translated_error .=
$e->getMessage();
135 $this->mount_instructions_repository->updateMountInstructions($this->document);
136 }
catch (InvalidArgumentException
$e) {
138 $this->translated_error .=
$e->getMessage();
147 return $this->translated_info !==
'';
152 return $this->translated_error !==
'';
168 throw new InvalidArgumentException($this->
lng->txt(
'form_input_not_valid'));
171 $document_already_exists = $document->
getId() > 0;
173 if (!$document_already_exists) {
177 if (!$document_already_exists && !$upload_result->isOK()) {
178 throw new InvalidArgumentException($this->
lng->txt(
'form_input_not_valid'));
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;
190 $mount_instruction_for_language_exists = $this->mount_instructions_repository->doMountInstructionsExistByLanguage(
194 if (!$document_already_exists && $mount_instruction_for_language_exists) {
195 throw new InvalidArgumentException($this->
lng->txt(
'webdav_choosen_language_already_used'));
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'));
204 if ($document_already_exists) {
205 $raw_mount_instructions =
'';
206 $processed_mount_instructions =
'';
209 $document_processor = $upload_result->getMimeType() ===
'text/html'
212 $processed_mount_instructions = $document_processor->processMountInstructions($raw_mount_instructions);
215 $id = $document_already_exists ? $document->
getId()
216 : $this->mount_instructions_repository->getNextMountInstructionsDocumentId();
221 $raw_mount_instructions,
222 json_encode($processed_mount_instructions),
227 $last_modified_usr_id,
234 if ($upload_result->
getName() ===
'') {
235 throw new InvalidArgumentException(
'uploaded file has no name');
238 if (!$upload_result->
isOK()) {
240 throw new InvalidArgumentException($this->
lng->txt(
'form_input_not_valid'));
243 $this->file_upload->moveOneFileTo(
245 '/mount_instructions',
251 $path_to_file =
'/mount_instructions/' . $upload_result->
getName();
252 if (!$this->tmp_filesystem->has($path_to_file)) {
254 throw new InvalidArgumentException($this->
lng->txt(
'form_input_not_valid'));
257 $raw_content = $this->tmp_filesystem->read($path_to_file);
259 $this->tmp_filesystem->delete($path_to_file);
266 if (!$this->file_upload->hasUploads()) {
267 throw new InvalidArgumentException(
'webdav_error_no_upload');
269 if (!$this->file_upload->hasBeenProcessed()) {
270 $this->file_upload->process();
273 $upload_result = array_values($this->file_upload->getResults())[0];
275 if (!$upload_result) {
277 throw new InvalidArgumentException($this->
lng->txt(
'form_input_not_valid'));
280 return $upload_result;
This class represents a text property in a property form.
Util class various functions, usage as namespace.
static now()
Return current timestamp in Y-m-d H:i:s format.
const TEMPORARY
The ILIAS temporary directory.
The filesystem interface provides the public interface for the Filesystem service API consumer.
Interface for html sanitizing functionality.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc