Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/support/2.13.0' into support/2.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Oct 31, 2023
2 parents adbd465 + 46559a0 commit b238087
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 86 deletions.
23 changes: 23 additions & 0 deletions inc/abstractitiltarget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,29 @@ protected function prepareUploadsFromTextarea(array $data, PluginFormcreatorForm
return $data;
}

/**
* Undocumented function
*
* @param array $data
* @param PluginFormcreatorFormAnswer $formanswer
* @return array
*/
protected function setDocuments($data, PluginFormcreatorFormAnswer $formanswer): array {
foreach ($formanswer->getQuestionFields($formanswer->getForm()->getID()) ?? [] as $field) {
$question = $field->getQuestion();
if ($question->fields['fieldtype'] !== 'glpiselect') {
continue;
}
if ($question->fields['itemtype'] !== Document::class) {
continue;
}

$data['_documents_id'][] = $field->getRawValue();
}

return $data;
}

/**
* Emulate file uploads for documents provided to file questions
*
Expand Down
1 change: 1 addition & 0 deletions inc/exportabletrait.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function importChildrenObjects(PluginFormcreatorExportableInterface $pare
}
}
// Delete all other restrictions
/** @var PluginFormcreatorExportableInterface $subItem */
$subItem = new $itemtype();
$subItem->deleteObsoleteItems($parent, $importedItems);
}
Expand Down
29 changes: 22 additions & 7 deletions inc/field/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,21 @@ public function getRenderedHtml($domain, $canEdit = true): string {
if (!$canEdit) {
$value = '';
if ($item->getFromDB($this->value)) {
$column = 'name';
$value = $item->fields['name'];
if ($item instanceof CommonTreeDropdown) {
$column = 'completename';
$value = $item->fields['completename'];
} else {
/** @var CommonDBTM $item */
switch ($item->getType()) {
case User::class:
$value = (new DbUtils())->getUserName($item->getID());
break;
case Document::class:
/** @var Document $item */
$value = $item->getDownloadLink($this->form_answer);
break;
}
}
$value = $item->fields[$column];
}

return $value;
Expand Down Expand Up @@ -571,7 +581,12 @@ public function moveUploads() {
}

public function getDocumentsForTarget(): array {
return [];
$itemtype = $this->getSubItemtype();
if ($itemtype !== Document::class) {
return [];
}

return [$this->value]; // Array of a single document ID
}

public static function getName(): string {
Expand Down Expand Up @@ -752,7 +767,7 @@ private function getMyGroups($userID) {
}

public function equals($value): bool {
$value = html_entity_decode($value);
$value = html_entity_decode($value ?? '');
$itemtype = $this->question->fields['itemtype'];
$dropdown = new $itemtype();
if ($dropdown->isNewId($this->value)) {
Expand All @@ -774,7 +789,7 @@ public function notEquals($value): bool {
}

public function greaterThan($value): bool {
$value = html_entity_decode($value);
$value = html_entity_decode($value ?? '');
$itemtype = $this->question->fields['itemtype'];
$dropdown = new $itemtype();
if (!$dropdown->getFromDB($this->value)) {
Expand All @@ -793,7 +808,7 @@ public function lessThan($value): bool {
}

public function regex($value): bool {
$value = html_entity_decode($value);
$value = html_entity_decode($value ?? '');
$itemtype = $this->question->fields['itemtype'];
$dropdown = new $itemtype();
if (!$dropdown->getFromDB($this->value)) {
Expand Down
4 changes: 2 additions & 2 deletions inc/field/glpiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function buildParams($rand = null) {
}

public function equals($value): bool {
$value = html_entity_decode($value);
$value = html_entity_decode($value ?? '');
$itemtype = $this->getSubItemtype();
$item = new $itemtype();
if ($item->isNewId($this->value)) {
Expand All @@ -190,7 +190,7 @@ public function notEquals($value): bool {
}

public function greaterThan($value): bool {
$value = html_entity_decode($value);
$value = html_entity_decode($value ?? '');
$itemtype = $this->getSubItemtype();
$item = new $itemtype();
if (!$item->getFromDB($this->value)) {
Expand Down
2 changes: 1 addition & 1 deletion inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,7 @@ private function updateIssue() {
/**
* get all fields from a form
*
* @param int $formId ID of the form where come the fileds to load
* @param int $formId ID of the form where come the fields to load
* @return PluginFormcreatorAbstractField[]
*/
public function getQuestionFields($formId) : array {
Expand Down
85 changes: 43 additions & 42 deletions inc/target_actor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,51 +172,52 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
'uuid',
$input['uuid']
);
// Convert UUIDs or names into IDs
switch ($input['actor_type']) {
case self::ACTOR_TYPE_QUESTION_PERSON :
case self::ACTOR_TYPE_QUESTION_GROUP :
case self::ACTOR_TYPE_QUESTION_SUPPLIER :
case self::ACTOR_TYPE_QUESTION_ACTORS :
case self::ACTOR_TYPE_GROUP_FROM_OBJECT :
case self::ACTOR_TYPE_TECH_GROUP_FROM_OBJECT :
/** @var PluginFormcreatorQuestion $question */
$question = $linker->getObject($input['actor_value'], PluginFormcreatorQuestion::class);
if ($question === false) {
$linker->postpone($input[$idKey], $item->getType(), $input, $containerId);
return false;
}
$input['actor_value'] = $question->getID();
break;
}

case self::ACTOR_TYPE_PERSON:
case self::ACTOR_TYPE_AUTHORS_SUPERVISOR:
$user = new User;
$users_id = plugin_formcreator_getFromDBByField($user, 'name', $input['actor_value']);
if ($users_id === false) {
throw new ImportFailureException(sprintf(__('Failed to find a user: %1$s'), $input['actor_value']));
}
$input['actor_value'] = $users_id;
break;
// Convert UUIDs or names into IDs
switch ($input['actor_type']) {
case self::ACTOR_TYPE_QUESTION_PERSON :
case self::ACTOR_TYPE_QUESTION_GROUP :
case self::ACTOR_TYPE_QUESTION_SUPPLIER :
case self::ACTOR_TYPE_QUESTION_ACTORS :
case self::ACTOR_TYPE_GROUP_FROM_OBJECT :
case self::ACTOR_TYPE_TECH_GROUP_FROM_OBJECT :
/** @var PluginFormcreatorQuestion $question */
$question = $linker->getObject($input['actor_value'], PluginFormcreatorQuestion::class);
if ($question === false) {
$linker->postpone($input[$idKey], $item->getType(), $input, $containerId);
return false;
}
$input['actor_value'] = $question->getID();
break;

case self::ACTOR_TYPE_GROUP:
$group = new Group;
$groups_id = plugin_formcreator_getFromDBByField($group, 'completename', $input['actor_value']);
if ($groups_id === false) {
throw new ImportFailureException(sprintf(__('Failed to find a group: %1$s'), $input['actor_value']));
}
$input['actor_value'] = $groups_id;
break;
case self::ACTOR_TYPE_PERSON:
case self::ACTOR_TYPE_AUTHORS_SUPERVISOR:
$user = new User;
$users_id = plugin_formcreator_getFromDBByField($user, 'name', $input['actor_value']);
if ($users_id === false) {
throw new ImportFailureException(sprintf(__('Failed to find a user: %1$s'), $input['actor_value']));
}
$input['actor_value'] = $users_id;
break;

case self::ACTOR_TYPE_SUPPLIER:
$supplier = new Supplier;
$suppliers_id = plugin_formcreator_getFromDBByField($supplier, 'name', $input['actor_value']);
if ($suppliers_id === false) {
throw new ImportFailureException(sprintf(__('Failed to find a supplier: %1$s'), $input['actor_value']));
}
$input['actor_value'] = $suppliers_id;
break;
}
case self::ACTOR_TYPE_GROUP:
$group = new Group;
$groups_id = plugin_formcreator_getFromDBByField($group, 'completename', $input['actor_value']);
if ($groups_id === false) {
throw new ImportFailureException(sprintf(__('Failed to find a group: %1$s'), $input['actor_value']));
}
$input['actor_value'] = $groups_id;
break;

case self::ACTOR_TYPE_SUPPLIER:
$supplier = new Supplier;
$suppliers_id = plugin_formcreator_getFromDBByField($supplier, 'name', $input['actor_value']);
if ($suppliers_id === false) {
throw new ImportFailureException(sprintf(__('Failed to find a supplier: %1$s'), $input['actor_value']));
}
$input['actor_value'] = $suppliers_id;
break;
}

$originalId = $input[$idKey];
Expand Down
1 change: 1 addition & 0 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
$data = $this->setTargeAssigned($data, $formanswer);
$data = $this->setTargetSuppliers($data, $formanswer);

$data = $this->setDocuments($data, $formanswer);
$data = $this->prepareUploadedFiles($data, $formanswer);

$data = $this->appendFieldsData($data, $formanswer);
Expand Down
Loading

0 comments on commit b238087

Please sign in to comment.