-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEscalationConditions.php
More file actions
94 lines (78 loc) · 2.53 KB
/
Copy pathEscalationConditions.php
File metadata and controls
94 lines (78 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
// SPDX-FileCopyrightText: 2025 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Module\Notifications\Forms\EventRuleConfigElements;
use Icinga\Module\Notifications\Web\FilterRenderer;
use ipl\Html\Attributes;
use ipl\Html\Contract\FormElement;
use ipl\Html\FormElement\FieldsetElement;
use ipl\Html\FormElement\SubmitButtonElement;
use ipl\Html\HtmlElement;
use ipl\Stdlib\Filter;
use ipl\Stdlib\Filter\Condition;
use ipl\Web\Filter\QueryString;
use ipl\Web\Widget\Icon;
/**
* @phpstan-import-type ConditionData from EscalationCondition
*/
class EscalationConditions extends FieldsetElement
{
use DynamicElements;
protected $defaultAttributes = ['class' => 'escalation-conditions'];
protected function createAddButton(): SubmitButtonElement
{
/** @var SubmitButtonElement $button */
$button = $this->createElement('submitButton', 'add-button', [
'title' => $this->translate('Add Condition'),
'label' => new Icon('plus'),
'class' => ['add-button', 'animated']
]);
$button->addWrapper(new HtmlElement('div', Attributes::create(['class' => 'add-button-wrapper'])));
return $button;
}
protected function createDynamicElement(int $no, ?SubmitButtonElement $removeButton): FormElement
{
$condition = new EscalationCondition($no);
if ($removeButton !== null) {
$condition->setRemoveButton($removeButton);
}
return $condition;
}
/**
* Prepare the conditions for display
*
* @param string $query The query string
*
* @return array<ConditionData>
*/
public static function prepare(string $query): array
{
$filters = QueryString::parse($query);
if ($filters instanceof Condition) {
$filters = [$filters];
}
$conditions = [];
foreach ($filters as $condition) {
$conditions[] = EscalationCondition::prepare($condition);
}
return $conditions;
}
/**
* Get the conditions to store
*
* @return ?string
*/
public function getConditions(): ?string
{
$filters = Filter::all();
foreach ($this->ensureAssembled()->getElements() as $element) {
if ($element instanceof EscalationCondition) {
$filters->add($element->getCondition());
}
}
if ($filters->isEmpty()) {
return null;
}
return (new FilterRenderer($filters))->render();
}
}