ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilFileVersionFormGUI.php
Go to the documentation of this file.
1<?php
2
6
13{
14 const MODE_ADD = 1;
15 const MODE_REPLACE = 2;
16 const F_TITLE = 'title';
17 const F_DESCRIPTION = "description";
18 const F_FILE = "file";
19 const F_SAVE_MODE = 'save_mode';
23 protected $dnd = true;
31 private $upload;
35 private $file;
39 private $calling_gui;
40
41
47 public function __construct(ilFileVersionsGUI $file_version_gui, $mode = self::MODE_ADD)
48 {
49 global $DIC;
50 $this->file = $file_version_gui->getFile();
51 $this->upload = $DIC->upload();
52 $this->calling_gui = $file_version_gui;
53 $this->lng = $DIC->language();
54 $this->save_mode = $mode;
55 parent::__construct();
56 $this->initForm();
57 $this->setTarget('_top');
58 $this->setFormAction($DIC->ctrl()->getFormAction($file_version_gui));
59 }
60
61
62 private function initForm()
63 {
64 // Buttons and Title
65 $this->lng->loadLanguageModule('file');
66 switch ($this->save_mode) {
68 ilUtil::sendInfo($this->lng->txt('replace_file_info'));
69 $this->setTitle($this->lng->txt('replace_file'));
70 $this->addCommandButton(ilFileVersionsGUI::CMD_CREATE_REPLACING_VERSION, $this->lng->txt('replace_file'));
71 break;
72 case self::MODE_ADD:
73 ilUtil::sendInfo($this->lng->txt('file_new_version_info'));
74 $this->setTitle($this->lng->txt('file_new_version'));
75 $this->addCommandButton(ilFileVersionsGUI::CMD_CREATE_NEW_VERSION, $this->lng->txt('file_new_version'));
76 break;
77 }
78 $this->addCommandButton(ilFileVersionsGUI::CMD_DEFAULT, $this->lng->txt('cancel'));
79
80 // Title
81 $title = new ilTextInputGUI($this->lng->txt(self::F_TITLE), self::F_TITLE);
82 $title->setInfo($this->lng->txt("if_no_title_then_filename"));
83 $title->setSize(min(40, ilObject::TITLE_LENGTH));
84
85 $title->setMaxLength(ilObject::TITLE_LENGTH);
86
87 $this->addItem($title);
88
89 // File Description
90 $description = new ilTextAreaInputGUI($this->lng->txt(self::F_DESCRIPTION), self::F_DESCRIPTION);
91 $this->addItem($description);
92
93 // File
94 if ($this->dnd) {
95 // File (D&D)
98 $this->lng->txt(self::F_FILE),
99 self::F_FILE
100 );
101 $file->setRequired(true);
102 // $file->setUploadUrl($this->ctrl->getLinkTarget($this->calling_gui, ilFileVersionsGUI::C, "", true, true));
103 $file->setMaxFiles(1);
104 $this->addItem($file);
105 } else {
106 // File (classical)
107 $in_file = new ilFileInputGUI($this->lng->txt(self::F_FILE), self::F_FILE);
108 $in_file->setRequired(true);
109 $this->addItem($in_file);
110 }
111 }
112
113
119 public function saveObject()
120 {
121 if (!$this->checkInput()) {
122 return false;
123 }
124 if (!$this->upload->hasUploads()) {
125 return false;
126 }
127
128 // bugfix mantis 26271
129 global $DIC;
130 $DIC->upload()->register(new ilCountPDFPagesPreProcessors());
131
132 $file = $this->getInput(self::F_FILE);
133 $file_temp_name = $file['tmp_name'];
134
135 $this->upload->process();
136
140 $result = $this->upload->getResults()[$file_temp_name];
141 if ($result->getStatus() === ProcessingStatus::REJECTED) {
142 return false;
143 }
144 $input_title = (string) ilUtil::stripSlashes($this->getInput(self::F_TITLE));
145 // bugfix mantis 0026160
146 $file_name = $this->file->getFileName();
147 if (strlen(trim($input_title)) == 0) {
148 $input_title = $file_name;
149 } else {
150 $input_title = $this->file->checkFileExtension($file_name, $input_title);
151 }
152
153
154 switch ($this->save_mode) {
155 case self::MODE_ADD:
156 $this->file->addFileVersion($file_temp_name, $result->getName());
157 break;
159 $this->file->deleteVersions();
160 $this->file->clearDataDirectory();
161 $this->file->replaceFile($file_temp_name, $result->getName());
162 break;
163 }
164
165 $this->file->setFileType($result->getMimeType());
166 $this->file->setFileSize($result->getSize());
167 $this->file->setFilename($result->getName());
168 $this->file->setTitle($input_title);
169 $this->file->setDescription($this->getInput((string) self::F_DESCRIPTION));
170 $this->file->update();
171
172 return true;
173 }
174
175
176 public function fillForm()
177 {
178 $values = [];
179 $values[self::F_TITLE] = $this->file->getTitle();
180 $values[self::F_DESCRIPTION] = $this->file->getDescription();
181
183 }
184}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilCountPDFPagesPreProcessors.
This class represents a file property in a property form.
Class ilFileStandardDropzoneInputGUI.
Class ilFileVersionFormGUI.
__construct(ilFileVersionsGUI $file_version_gui, $mode=self::MODE_ADD)
ilFileVersionFormGUI constructor.
Class ilFileVersionsGUI.
setTarget($a_target)
Set Target.
setFormAction($a_formaction)
Set FormAction.
const TITLE_LENGTH
max length of object title
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
addCommandButton($a_cmd, $a_text, $a_id="")
Add Command button.
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
checkInput()
Check Post Input.
setTitle($a_title)
Set Title.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $DIC
Definition: saml.php:7
$values