Skip to content

Commit

Permalink
fix: compatibility with GLPI 9.5
Browse files Browse the repository at this point in the history
and a minor refactor

Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed May 6, 2020
1 parent 258ad70 commit a49a6e0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
22 changes: 21 additions & 1 deletion inc/fields/filefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,27 @@ public function parseAnswerValues($input, $nonDestructive = false) {
return false;
}

if (isset($input["_$key"])) {
if (PLUGIN_FORMCREATOR_TEXTAREA_FIX && version_compare(GLPI_VERSION, '9.5.0-dev') < 0) {
$answer_value = [];
$index = 0;
if ($nonDestructive) {
$index = count($input["_$key"]);
} else {
foreach ($input["_$key"] as $document) {
$document = Toolbox::stripslashes_deep($document);
if (is_file(GLPI_TMP_DIR . '/' . $document)) {
$prefix = $input['_prefix_formcreator_field_' . $this->question->getID()][$index];
$answer_value[] = $this->saveDocument($document, $prefix);
}
$index++;
}
}
$this->uploadData = $answer_value;
$this->value = __('Attached document', 'formcreator');

return true;
}
if ($this->hasInput($input)) {
$this->value = __('Attached document', 'formcreator');
}
return true;
Expand Down
12 changes: 12 additions & 0 deletions inc/fields/textareafield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ public function hasInput($input) {
}

public function parseAnswerValues($input, $nonDestructive = false) {
if (PLUGIN_FORMCREATOR_TEXTAREA_FIX && version_compare(GLPI_VERSION, '9.5.0-dev') < 0) {
$input = $this->question->addFiles(
$input,
[
'force_update' => true,
'content_field' => 'formcreator_field_' . $this->question->getID(),
]
);

return parent::parseAnswerValues($input, $nonDestructive);
}

parent::parseAnswerValues($input, $nonDestructive);
$key = 'formcreator_field_' . $this->question->getID();
if (isset($input['_tag_' . $key]) && isset($input['_' . $key]) && isset($input['_prefix_' . $key])) {
Expand Down
11 changes: 4 additions & 7 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1103,17 +1103,14 @@ public function getFullForm($richText = false) {

public function post_addItem() {
// Save questions answers
$question = new PluginFormcreatorQuestion();
$this->questions = $question->getQuestionsFromForm($this->input['plugin_formcreator_forms_id']);

foreach ($this->questions as $questionId => $question) {
foreach ($this->questionFields as $questionId => $field) {
$answer = new PluginFormcreatorAnswer();
$answer->add([
'plugin_formcreator_formanswers_id' => $this->getID(),
'plugin_formcreator_questions_id' => $question->getID(),
'answer' => $this->questionFields[$questionId]->serializeValue(),
'plugin_formcreator_questions_id' => $questionId,
'answer' => $field->serializeValue(),
], [], 0);
foreach ($this->questionFields[$questionId]->getDocumentsForTarget() as $documentId) {
foreach ($field->getDocumentsForTarget() as $documentId) {
$docItem = new Document_Item();
$docItem->add([
'documents_id' => $documentId,
Expand Down

0 comments on commit a49a6e0

Please sign in to comment.