Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom object items can be linked together on the import #317

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion EventListener/ImportSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public function onFieldMapping(ImportMappingEvent $event): void
$customObject = $this->customObjectModel->fetchEntity($customObjectId);
$customFields = $customObject->getCustomFields();
$specialFields = [
'linkedContactIds' => 'custom.item.link.contact.ids',
'linkedContactIds' => 'custom.item.link.contact.ids',
'linkedCustomItemsIds' => 'custom.item.link.custom_items.ids',
];

$fieldList = [
Expand Down
1 change: 1 addition & 0 deletions Model/CustomItemExportSchedulerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private function getCSVHeader(array $customFields): array
}

$header[] = 'linkedContactIds';
$header[] = 'linkedCustomItemsIds';

return $header;
}
Expand Down
26 changes: 22 additions & 4 deletions Model/CustomItemImportModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public function __construct(
*/
public function import(Import $import, array $rowData, CustomObject $customObject): bool
{
$matchedFields = $import->getMatchedFields();
$customItem = $this->getCustomItem($import, $customObject, $rowData);
$merged = (bool) $customItem->getId();
$contactIds = [];
$matchedFields = $import->getMatchedFields();
$customItem = $this->getCustomItem($import, $customObject, $rowData);
$merged = (bool) $customItem->getId();
$contactIds = [];
$customItemsIds = [];

$this->setOwner($import, $customItem);
foreach ($matchedFields as $csvField => $customFieldId) {
Expand All @@ -67,6 +68,12 @@ public function import(Import $import, array $rowData, CustomObject $customObjec
continue;
}

if (0 === strcasecmp('linkedCustomItemsIds', $customFieldId)) {
$customItemsIds = $this->formatterHelper->simpleCsvToArray($csvValue, 'int');

continue;
}

if (0 === strcasecmp('customItemName', $customFieldId)) {
$customItem->setName($csvValue);

Expand Down Expand Up @@ -95,6 +102,7 @@ public function import(Import $import, array $rowData, CustomObject $customObjec
}

$this->linkContacts($customItem, $contactIds);
$this->linkCustomObjects($customItem, $customItemsIds);

return $merged;
}
Expand All @@ -112,6 +120,16 @@ private function linkContacts(CustomItem $customItem, array $contactIds): Custom
return $customItem;
}

private function linkCustomObjects(CustomItem $customItem, array $customItemsIds): CustomItem
{
foreach ($customItemsIds as $customItemsId) {
$xref = $this->customItemModel->linkEntity($customItem, 'customItem', $customItemsId);
$customItem->addCustomItemReference($xref);
}

return $customItem;
}

private function setOwner(Import $import, CustomItem $customItem): CustomItem
{
$owner = $import->getDefault('owner');
Expand Down
1 change: 1 addition & 0 deletions Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ custom.item.field="Field"
custom.item.operator="Operator"
custom.item.field.value="Value"
custom.item.link.contact.ids="Link Contact IDs"
custom.item.link.custom_items.ids="Link Custom Items IDs"
custom.item.link="Link"
custom.item.unlink="Unlink"
custom.item.linked.items="Linked Items"
Expand Down