3use ILIAS\FileSystem\Filesystem;
65 FileSystem $a_tmp_filesystem,
67 string $a_form_action,
68 string $a_save_command,
69 string $a_cancel_command,
72 $this->document = $a_document;
74 $this->document_purifier = $a_document_purifier;
75 $this->actor = $a_actor;
76 $this->tmp_filesystem = $a_tmp_filesystem;
77 $this->file_upload = $a_fileupload;
78 $this->form_action = $a_form_action;
79 $this->save_command = $a_save_command;
80 $this->cancel_command = $a_cancel_command;
81 $this->is_editable = $a_is_editable;
93 $document_already_exists = $this->document->getId() > 0;
94 if ($document_already_exists) {
95 $this->
setTitle($this->lng->txt(
'webdav_form_edit_doc_head'));
97 $this->
setTitle($this->lng->txt(
'webdav_form_new_doc_head'));
102 $title =
new ilTextInputGUI($this->lng->txt(
'webdav_form_document_title'),
'title');
103 $title->setInfo($this->lng->txt(
'webdav_form_document_title_info'));
104 $title->setRequired(
true);
105 $title->setDisabled(!$this->is_editable);
106 $title->setValue($this->document->getTitle());
107 $title->setMaxLength(255);
110 if ($document_already_exists) {
111 $document_label = $this->lng->txt(
'webdav_form_document');
112 $document_by_line = $this->lng->txt(
'webdav_form_document_info');
114 $document_label = $this->lng->txt(
'webdav_form_document');
115 $document_by_line = $this->lng->txt(
'webdav_form_document_info');
119 $this->lng->txt(
'language'),
122 $language_selection->setRequired(
true);
125 foreach ($this->lng->getInstalledLanguages() as
$lng) {
126 $options[
$lng] = $this->lng->txt(
'meta_l_' .
$lng,
'meta');
131 $language_selection->setOptions([
'' => $this->lng->txt(
'please_choose')] + $options);
132 $language_selection->setValue((
string) ($this->document->getLanguage() ??
''));
134 $this->
addItem($language_selection);
136 if ($document_already_exists) {
138 $webdav_id->setValue($this->document->getId());
141 $document_upload =
new ilFileInputGUI($document_label,
'document');
142 $document_upload->setInfo($document_by_line);
143 $document_upload->setRequired($document_already_exists ?
false :
true);
144 $document_upload->setDisabled(!$this->is_editable);
145 $document_upload->setSuffixes([
'html',
'htm',
'txt']);
146 $this->
addItem($document_upload);
149 if ($this->is_editable) {
161 $this->document = $this->createFilledObject($this->document);
162 $this->mount_instructions_repository->createMountInstructionsDocumentEntry($this->document);
163 }
catch (InvalidArgumentException
$e) {
165 $this->translated_error .=
$e->getMessage();
178 $this->document = $this->createFilledObject($this->document);
179 $this->mount_instructions_repository->updateMountInstructions($this->document);
180 }
catch (InvalidArgumentException
$e) {
182 $this->translated_error .=
$e->getMessage();
194 return strlen($this->translated_info) > 0;
202 return strlen($this->translated_error) > 0;
232 throw new InvalidArgumentException($this->lng->txt(
'form_input_not_valid'));
236 $document_already_exists =
$document->getId() > 0;
238 if (!$document_already_exists) {
240 $upload_result = $this->getFileUploadResult();
244 if (!$document_already_exists && $upload_result->getStatus()->getCode() != ProcessingStatus::OK) {
245 throw new InvalidArgumentException($this->lng->txt(
'form_input_not_valid'));
252 $modification_ts = $document_already_exists ?
ilUtil::now() : $creation_ts;
253 $owner_id = $document_already_exists ?
$document->getOwnerUsrId() : $this->actor->getId();
254 $last_modified_usr_id = $this->actor->getId();
255 $sorting = $document_already_exists ?
$document->getSorting() : $this->mount_instructions_repository->getHighestSortingNumber() + 1;
258 if (!$document_already_exists && $this->mount_instructions_repository->doMountInstructionsExistByLanguage($language)) {
259 throw new InvalidArgumentException($this->lng->txt(
"webdav_choosen_language_already_used"));
263 if ($document_already_exists &&
$document->getLanguage() != $language
264 && $this->mount_instructions_repository->doMountInstructionsExistByLanguage($language) !=
$document->getId()) {
265 throw new InvalidArgumentException($this->lng->txt(
"webdav_chosen_language_already_used"));
268 if ($document_already_exists) {
269 $raw_mount_instructions =
'';
270 $processed_mount_instructions =
'';
274 $document_processor = $upload_result->getMimeType() ==
'text/html'
281 : $this->mount_instructions_repository->getNextMountInstructionsDocumentId();
287 $raw_mount_instructions,
288 json_encode($processed_mount_instructions),
293 $last_modified_usr_id,
311 if ($upload_result->
getName() ===
'') {
312 throw new InvalidArgumentException(
'uploaded file has no name');
316 if ($upload_result->
getStatus()->getCode() != ProcessingStatus::OK) {
318 throw new InvalidArgumentException($this->lng->txt(
'form_input_not_valid'));
322 $this->file_upload->moveOneFileTo(
324 '/mount_instructions',
330 $path_to_file =
'/mount_instructions/' . $upload_result->
getName();
331 if (!$this->tmp_filesystem->has($path_to_file)) {
332 $this->
getItemByPostVar(
'document')->setAlert($this->lng->txt(
'form_msg_file_no_upload'));
333 throw new InvalidArgumentException($this->lng->txt(
'form_input_not_valid'));
337 $raw_content = $content = $this->tmp_filesystem->read($path_to_file);
340 $this->tmp_filesystem->delete($path_to_file);
352 if (!$this->file_upload->hasUploads()) {
353 throw new InvalidArgumentException(
"webdav_error_no_upload");
354 } elseif ($this->file_upload->hasBeenProcessed()) {
355 throw new InvalidArgumentException(
"webdav_error_upload_already_processed");
358 $this->file_upload->process();
361 $upload_result = array_values($this->file_upload->getResults())[0];
363 if (!$upload_result) {
364 $this->
getItemByPostVar(
'document')->setAlert($this->lng->txt(
'form_msg_file_no_upload'));
365 throw new InvalidArgumentException($this->lng->txt(
'form_input_not_valid'));
368 return $upload_result;
An exception for terminatinating execution or to throw for unit testing.
This class represents a text property in a property form.
static now()
Return current timestamp in Y-m-d H:i:s format.
processMountInstructions(string $a_raw_mount_instructions)
Interface for html sanitizing functionality.
Interface ilWebDAVMountInstructionsRepository.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc