mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-22 13:24:25 +02:00
parent
c5e25cdcc7
commit
e5595431df
@ -13,6 +13,7 @@ next (will be 1.9.0)
|
|||||||
|
|
||||||
### Import and Sync
|
### Import and Sync
|
||||||
* FEATURE: introduce 'disable' as your purge action on Sync (#2285)
|
* FEATURE: introduce 'disable' as your purge action on Sync (#2285)
|
||||||
|
* FEATURE: there is now a simple "group by" Property Modifier (#2317)
|
||||||
|
|
||||||
### Configuration Baskets
|
### Configuration Baskets
|
||||||
* FEATURE: it's now possible to purge objects of specific types (#2201)
|
* FEATURE: it's now possible to purge objects of specific types (#2201)
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\PropertyModifier;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
||||||
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||||
|
|
||||||
|
class PropertyModifierSimpleGroupBy extends PropertyModifierHook
|
||||||
|
{
|
||||||
|
private $keptRows = [];
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return mt('director', 'Group by a column, aggregate others');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requiresRow()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transform($value)
|
||||||
|
{
|
||||||
|
$row = $this->getRow();
|
||||||
|
$aggregationColumns = preg_split(
|
||||||
|
'/\s*,\s*/',
|
||||||
|
$this->getSetting('aggregation_columns'),
|
||||||
|
-1,
|
||||||
|
PREG_SPLIT_NO_EMPTY
|
||||||
|
);
|
||||||
|
if (isset($this->keptRows[$value])) {
|
||||||
|
foreach ($aggregationColumns as $column) {
|
||||||
|
if (isset($row->$column)) {
|
||||||
|
$this->keptRows[$value]->{$column} = array_unique(array_merge(
|
||||||
|
$this->keptRows[$value]->{$column},
|
||||||
|
[$row->$column]
|
||||||
|
));
|
||||||
|
sort($this->keptRows[$value]->{$column});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->rejectRow();
|
||||||
|
} else {
|
||||||
|
foreach ($aggregationColumns as $column) {
|
||||||
|
if (isset($row->$column)) {
|
||||||
|
$row->$column = [$row->$column];
|
||||||
|
} else {
|
||||||
|
$row->$column = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->keptRows[$value] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addSettingsFormFields(QuickForm $form)
|
||||||
|
{
|
||||||
|
$form->addElement('text', 'aggregation_columns', [
|
||||||
|
'label' => $form->translate('Aggregation Columns'),
|
||||||
|
'description' => $form->translate(
|
||||||
|
'Comma-separated list of columns that should be aggregated (transformed into an Array).'
|
||||||
|
. ' For all other columns only the first value will be kept.'
|
||||||
|
),
|
||||||
|
'required' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -45,6 +45,7 @@ use Icinga\Module\Director\PropertyModifier\PropertyModifierRegexSplit;
|
|||||||
use Icinga\Module\Director\PropertyModifier\PropertyModifierRejectOrSelect;
|
use Icinga\Module\Director\PropertyModifier\PropertyModifierRejectOrSelect;
|
||||||
use Icinga\Module\Director\PropertyModifier\PropertyModifierRenameColumn;
|
use Icinga\Module\Director\PropertyModifier\PropertyModifierRenameColumn;
|
||||||
use Icinga\Module\Director\PropertyModifier\PropertyModifierReplace;
|
use Icinga\Module\Director\PropertyModifier\PropertyModifierReplace;
|
||||||
|
use Icinga\Module\Director\PropertyModifier\PropertyModifierSimpleGroupBy;
|
||||||
use Icinga\Module\Director\PropertyModifier\PropertyModifierSkipDuplicates;
|
use Icinga\Module\Director\PropertyModifier\PropertyModifierSkipDuplicates;
|
||||||
use Icinga\Module\Director\PropertyModifier\PropertyModifierSplit;
|
use Icinga\Module\Director\PropertyModifier\PropertyModifierSplit;
|
||||||
use Icinga\Module\Director\PropertyModifier\PropertyModifierStripDomain;
|
use Icinga\Module\Director\PropertyModifier\PropertyModifierStripDomain;
|
||||||
@ -115,6 +116,7 @@ $directorHooks = [
|
|||||||
PropertyModifierRejectOrSelect::class,
|
PropertyModifierRejectOrSelect::class,
|
||||||
PropertyModifierRenameColumn::class,
|
PropertyModifierRenameColumn::class,
|
||||||
PropertyModifierReplace::class,
|
PropertyModifierReplace::class,
|
||||||
|
PropertyModifierSimpleGroupBy::class,
|
||||||
PropertyModifierSkipDuplicates::class,
|
PropertyModifierSkipDuplicates::class,
|
||||||
PropertyModifierSplit::class,
|
PropertyModifierSplit::class,
|
||||||
PropertyModifierStripDomain::class,
|
PropertyModifierStripDomain::class,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user