19declare(strict_types=1);
38 protected string $form_action,
39 protected string $save_command,
40 protected string $cancel_command,
41 protected bool $is_editable
50 $document_already_exists = $this->document->getId() > 0;
51 if ($document_already_exists) {
52 $this->
setTitle($this->
lng->txt(
'webdav_form_edit_doc_head'));
54 $this->
setTitle($this->
lng->txt(
'webdav_form_new_doc_head'));
60 $title->setInfo($this->
lng->txt(
'webdav_form_document_title_info'));
62 $title->setDisabled(!$this->is_editable);
63 $title->setValue($this->document->getTitle());
67 $document_label = $this->
lng->txt(
'webdav_form_document');
68 $document_by_line = $this->
lng->txt(
'webdav_form_document_info');
71 $this->
lng->txt(
'language'),
74 $language_selection->setRequired(
true);
77 foreach ($this->
lng->getInstalledLanguages() as
$lng) {
78 $options[
$lng] = $this->
lng->txt(
'meta_l_' . $lng,
'meta');
83 $language_selection->setOptions([
'' => $this->
lng->txt(
'please_choose')] + $options);
84 $language_selection->setValue($this->document->getLanguage());
86 $this->
addItem($language_selection);
88 if ($document_already_exists) {
90 $document_id->setValue((
string) $this->document->getId());
93 $document_upload =
new ilFileInputGUI($document_label,
'document');
94 $document_upload->setInfo($document_by_line);
95 $document_upload->setRequired(
true);
96 $document_upload->setDisabled(!$this->is_editable);
97 $document_upload->setSuffixes([
'html',
'htm',
'txt']);
98 $this->
addItem($document_upload);
101 if ($this->is_editable) {
110 $this->mount_instructions_repository->createMountInstructionsDocumentEntry($this->document);
111 }
catch (InvalidArgumentException
$e) {
113 $this->translated_error .=
$e->getMessage();
124 $this->mount_instructions_repository->updateMountInstructions($this->document);
125 }
catch (InvalidArgumentException
$e) {
127 $this->translated_error .=
$e->getMessage();
136 return strlen($this->translated_info) > 0;
141 return strlen($this->translated_error) > 0;
158 throw new InvalidArgumentException($this->
lng->txt(
'form_input_not_valid'));
161 $document_already_exists = $document->getId() > 0;
163 if (!$document_already_exists) {
167 if (!$document_already_exists && !$upload_result->isOK()) {
168 throw new InvalidArgumentException($this->
lng->txt(
'form_input_not_valid'));
173 $creation_ts = $document_already_exists ? $document->getCreationTs() :
ilUtil::now();
174 $modification_ts = $document_already_exists ?
ilUtil::now() : $creation_ts;
175 $owner_id = $document_already_exists ? $document->getOwnerUsrId() : $this->actor->getId();
176 $last_modified_usr_id = $this->actor->getId();
177 $sorting = $document_already_exists ? $document->getSorting(
178 ) : $this->mount_instructions_repository->getHighestSortingNumber() + 1;
180 $mount_instruction_for_language_exists = $this->mount_instructions_repository->doMountInstructionsExistByLanguage(
184 if (!$document_already_exists && $mount_instruction_for_language_exists) {
185 throw new InvalidArgumentException($this->
lng->txt(
"webdav_choosen_language_already_used"));
188 if ($document_already_exists && $document->getLanguage() != $language &&
189 $mount_instruction_for_language_exists > 0 &&
190 $mount_instruction_for_language_exists != $document->getId()) {
191 throw new InvalidArgumentException($this->
lng->txt(
"webdav_chosen_language_already_used"));
194 if ($document_already_exists) {
195 $raw_mount_instructions =
'';
196 $processed_mount_instructions =
'';
199 $document_processor = $upload_result->getMimeType() ===
'text/html'
205 $id = $document_already_exists ? $document->getId()
206 : $this->mount_instructions_repository->getNextMountInstructionsDocumentId();
211 $raw_mount_instructions,
212 json_encode($processed_mount_instructions),
217 $last_modified_usr_id,
224 if ($upload_result->
getName() ===
'') {
225 throw new InvalidArgumentException(
'uploaded file has no name');
228 if (!$upload_result->
isOK()) {
229 $this->getItemByPostVar(
'document')->setAlert($upload_result->
getStatus()->getMessage());
230 throw new InvalidArgumentException($this->
lng->txt(
'form_input_not_valid'));
233 $this->file_upload->moveOneFileTo(
235 '/mount_instructions',
241 $path_to_file =
'/mount_instructions/' . $upload_result->
getName();
242 if (!$this->tmp_filesystem->has($path_to_file)) {
243 $this->getItemByPostVar(
'document')->setAlert($this->
lng->txt(
'form_msg_file_no_upload'));
244 throw new InvalidArgumentException($this->
lng->txt(
'form_input_not_valid'));
247 $raw_content = $this->tmp_filesystem->read($path_to_file);
249 $this->tmp_filesystem->delete($path_to_file);
256 if (!$this->file_upload->hasUploads()) {
257 throw new InvalidArgumentException(
"webdav_error_no_upload");
259 if (!$this->file_upload->hasBeenProcessed()) {
260 $this->file_upload->process();
263 $upload_result = array_values($this->file_upload->getResults())[0];
265 if (!$upload_result) {
266 $this->getItemByPostVar(
'document')->setAlert($this->
lng->txt(
'form_msg_file_no_upload'));
267 throw new InvalidArgumentException($this->
lng->txt(
'form_input_not_valid'));
270 return $upload_result;
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)
The filesystem interface provides the public interface for the Filesystem service API consumer.
Interface for html sanitizing functionality.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))