Fix searching for segments to work with nested segments block

[MAILPOET-3297]
This commit is contained in:
Rostislav Wolny
2020-12-28 10:08:44 +01:00
committed by Veljko V
parent 46f9860990
commit 36a7cc0b25
2 changed files with 40 additions and 17 deletions

View File

@ -209,27 +209,20 @@ class Forms extends APIEndpoint {
// check if the user gets to pick his own lists
// or if it's selected by the admin
$hasSegmentSelection = false;
$formEntity = new FormEntity($name);
$formEntity->setBody($body);
$listSelectionBlocks = $formEntity->getBlocksByType(FormEntity::SEGMENT_SELECTION_BLOCK_TYPE);
$listSelection = [];
foreach ($body as $i => $block) {
if ($block['type'] === 'segment') {
$hasSegmentSelection = true;
if (!empty($block['params']['values'])) {
$listSelection = array_filter(
array_map(function($segment) {
return (isset($segment['id'])
? $segment['id']
: null
);
}, $block['params']['values'])
);
}
break;
}
foreach ($listSelectionBlocks as $listSelectionBlock) {
$listSelection = array_unique(
array_merge(
$listSelection, array_column($listSelectionBlock['params']['values'] ?? [], 'id')
)
);
}
// check list selection
if ($hasSegmentSelection === true) {
if (count($listSelectionBlocks)) {
$settings['segments_selected_by'] = 'user';
$settings['segments'] = $listSelection;
} else {