mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
parent
1f5a580739
commit
b75aac7323
@ -59,6 +59,21 @@ abstract class PropertyModifierHook
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This creates one cloned row for every entry of the result array
|
||||
*
|
||||
* When set to true and given that the property modifier returns an Array,
|
||||
* the current row will be cloned for every entry of that array. The modified
|
||||
* property will then be replace each time accordingly. An empty Array
|
||||
* completely removes the corrent row.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function expandsRows()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject this whole row
|
||||
*
|
||||
|
@ -307,22 +307,38 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
foreach ($modifiers as $modPair) {
|
||||
/** @var PropertyModifierHook $modifier */
|
||||
list($property, $modifier) = $modPair;
|
||||
$rejected = [];
|
||||
$newRows = [];
|
||||
foreach ($data as $key => $row) {
|
||||
$this->applyPropertyModifierToRow($modifier, $property, $row);
|
||||
if ($modifier->rejectsRow()) {
|
||||
$rejected[] = $key;
|
||||
$modifier->rejectRow(false);
|
||||
}
|
||||
if ($modifier->expandsRows()) {
|
||||
$target = $modifier->getTargetProperty($property);
|
||||
|
||||
$newValue = $row->$target;
|
||||
if (\is_array($newValue)) {
|
||||
foreach ($newValue as $val) {
|
||||
$newRow = clone $row;
|
||||
$newRow->$target = $val;
|
||||
$newRows[] = $newRow;
|
||||
}
|
||||
$rejected[] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($rejected as $key) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
foreach ($newRows as $row) {
|
||||
$data[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
Loading…
x
Reference in New Issue
Block a user