Skip to content

Commit 1929cd3

Browse files
committed
fix: compatibility with GLPI 9.5
and a minor refactor Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent cd8ca59 commit 1929cd3

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

inc/fields/filefield.class.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,27 @@ public function parseAnswerValues($input, $nonDestructive = false) {
210210
return false;
211211
}
212212

213-
if (isset($input["_$key"])) {
213+
if (PLUGIN_FORMCREATOR_TEXTAREA_FIX && version_compare(GLPI_VERSION, '9.5.0-dev') < 0) {
214+
$answer_value = [];
215+
$index = 0;
216+
if ($nonDestructive) {
217+
$index = count($input["_$key"]);
218+
} else {
219+
foreach ($input["_$key"] as $document) {
220+
$document = Toolbox::stripslashes_deep($document);
221+
if (is_file(GLPI_TMP_DIR . '/' . $document)) {
222+
$prefix = $input['_prefix_formcreator_field_' . $this->question->getID()][$index];
223+
$answer_value[] = $this->saveDocument($document, $prefix);
224+
}
225+
$index++;
226+
}
227+
}
228+
$this->uploadData = $answer_value;
229+
$this->value = __('Attached document', 'formcreator');
230+
231+
return true;
232+
}
233+
if ($this->hasInput($input)) {
214234
$this->value = __('Attached document', 'formcreator');
215235
}
216236
return true;

inc/fields/textareafield.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ public function hasInput($input) {
162162
}
163163

164164
public function parseAnswerValues($input, $nonDestructive = false) {
165+
if (PLUGIN_FORMCREATOR_TEXTAREA_FIX && version_compare(GLPI_VERSION, '9.5.0-dev') < 0) {
166+
$input = $this->question->addFiles(
167+
$input,
168+
[
169+
'force_update' => true,
170+
'content_field' => 'formcreator_field_' . $this->question->getID(),
171+
]
172+
);
173+
174+
return parent::parseAnswerValues($input, $nonDestructive);
175+
}
176+
165177
parent::parseAnswerValues($input, $nonDestructive);
166178
$key = 'formcreator_field_' . $this->question->getID();
167179
if (isset($input['_tag_' . $key]) && isset($input['_' . $key]) && isset($input['_prefix_' . $key])) {

inc/formanswer.class.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,17 +1116,14 @@ public function getFullForm($richText = false) {
11161116

11171117
public function post_addItem() {
11181118
// Save questions answers
1119-
$question = new PluginFormcreatorQuestion();
1120-
$this->questions = $question->getQuestionsFromForm($this->input['plugin_formcreator_forms_id']);
1121-
1122-
foreach ($this->questions as $questionId => $question) {
1119+
foreach ($this->questionFields as $questionId => $field) {
11231120
$answer = new PluginFormcreatorAnswer();
11241121
$answer->add([
11251122
'plugin_formcreator_formanswers_id' => $this->getID(),
1126-
'plugin_formcreator_questions_id' => $question->getID(),
1127-
'answer' => $this->questionFields[$questionId]->serializeValue(),
1123+
'plugin_formcreator_questions_id' => $questionId,
1124+
'answer' => $field->serializeValue(),
11281125
], [], 0);
1129-
foreach ($this->questionFields[$questionId]->getDocumentsForTarget() as $documentId) {
1126+
foreach ($field->getDocumentsForTarget() as $documentId) {
11301127
$docItem = new Document_Item();
11311128
$docItem->add([
11321129
'documents_id' => $documentId,

0 commit comments

Comments
 (0)