Skip to content

Commit

Permalink
style: indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Oct 20, 2023
1 parent 14caee3 commit d6c09cc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 55 deletions.
1 change: 0 additions & 1 deletion inc/field/glpiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ public function provideFile(): bool {
return false;
}


public function getAvailableValues(array $values = null): array {
return [];
}
Expand Down
108 changes: 54 additions & 54 deletions inc/field/uploadable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,62 +42,62 @@ trait Uploadable {
protected $uploadData = [];

/** @var array $uploads uploaded files on form submit */
protected $uploads = [
'_filename' => [],
'_prefix_filename' => [],
'_tag_filename' => [],
];
protected $uploads = [
'_filename' => [],
'_prefix_filename' => [],
'_tag_filename' => [],
];

/**
* Save an uploaded file into a document object, link it to the answers
* and returns the document ID
* @param PluginFormcreatorForm $form
* @param PluginFormcreatorQuestion $question
* @param array $file an item from $_FILES array
*
* @return integer|NULL
*/
protected function saveDocument($file, $prefix) {
$form = PluginFormcreatorForm::getByItem($this->question);
if ($form === null) {
// A problem occured while finding the form of the field
return;
}
/**
* Save an uploaded file into a document object, link it to the answers
* and returns the document ID
* @param PluginFormcreatorForm $form
* @param PluginFormcreatorQuestion $question
* @param array $file an item from $_FILES array
*
* @return integer|null
*/
protected function saveDocument($file, $prefix) {
$form = PluginFormcreatorForm::getByItem($this->question);
if ($form === null) {
// A problem occured while finding the form of the field
return;
}

$file_data = [
'name' => Toolbox::addslashes_deep($form->fields['name'] . ' - ' . $this->question->fields['name']),
'entities_id' => $_SESSION['glpiactive_entity'] ?? $form->getField('entities_id'),
'is_recursive' => $form->getField('is_recursive'),
'_filename' => [$file],
'_prefix_filename' => [$prefix],
];
$doc = new Document();
if ($docID = $doc->add($file_data)) {
return $docID;
}
return null;
}
$file_data = [
'name' => Toolbox::addslashes_deep($form->fields['name'] . ' - ' . $this->question->fields['name']),
'entities_id' => $_SESSION['glpiactive_entity'] ?? $form->getField('entities_id'),
'is_recursive' => $form->getField('is_recursive'),
'_filename' => [$file],
'_prefix_filename' => [$prefix],
];
$doc = new Document();
if ($docID = $doc->add($file_data)) {
return $docID;
}
return null;
}

public function moveUploads() {
parent::moveUploads();
public function moveUploads() {
parent::moveUploads();

$key = 'formcreator_field_' . $this->question->getID();
if (!is_array($this->uploads) || !isset($this->uploads["_$key"])) {
return;
}
$answer_value = [];
foreach ($this->uploads["_$key"] as $index => $document) {
$document = Toolbox::stripslashes_deep($document);
if (is_file(GLPI_TMP_DIR . '/' . $document)) {
$prefix = $this->uploads['_prefix_' . $key][$index];
$answer_value[] = $this->saveDocument($document, $prefix);
}
$index++;
}
$this->uploadData = $answer_value;
}
$key = 'formcreator_field_' . $this->question->getID();
if (!is_array($this->uploads) || !isset($this->uploads["_$key"])) {
return;
}
$answer_value = [];
foreach ($this->uploads["_$key"] as $index => $document) {
$document = Toolbox::stripslashes_deep($document);
if (is_file(GLPI_TMP_DIR . '/' . $document)) {
$prefix = $this->uploads['_prefix_' . $key][$index];
$answer_value[] = $this->saveDocument($document, $prefix);
}
$index++;
}
$this->uploadData = $answer_value;
}

public function getDocumentsForTarget(): array {
return $this->uploadData;
}
}
public function getDocumentsForTarget(): array {
return $this->uploadData;
}
}
2 changes: 2 additions & 0 deletions inc/fieldinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* ---------------------------------------------------------------------
*/

use SebastianBergmann\CodeUnit\FunctionUnit;

if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
Expand Down

0 comments on commit d6c09cc

Please sign in to comment.