From 18bbc0af342321aa3488b25e03e1504923361e35 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Tue, 23 Apr 2024 17:03:09 +0200 Subject: [PATCH] Fix escalation condition and recipient removal --- .../EscalationCondition.php | 38 ++++++------------- .../EscalationRecipient.php | 11 ++++++ application/forms/EventRuleConfigForm.php | 4 +- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/application/forms/EventRuleConfigElements/EscalationCondition.php b/application/forms/EventRuleConfigElements/EscalationCondition.php index 9dda2bf32..4e1c0b865 100644 --- a/application/forms/EventRuleConfigElements/EscalationCondition.php +++ b/application/forms/EventRuleConfigElements/EscalationCondition.php @@ -51,6 +51,8 @@ protected function assemble(): void ['value' => (string) $defaultCount] ); + $this->addElement('hidden', 'remove-position'); + $addCondition = $this->createElement( 'submitButton', 'add-condition', @@ -76,7 +78,6 @@ protected function assemble(): void for ($i = 1; $i <= $conditionCount; $i++) { $colName = 'column_' . $i; $opName = 'operator_' . $i; - $typeName = 'type_' . $i; $valName = 'val_' . $i; $col = $this->createElement( @@ -126,18 +127,6 @@ protected function assemble(): void ] ); - if ( - $this->getPopulatedValue($typeName) !== 'incident_severity' - && $this->getPopulatedValue($valName) !== null - ) { - $this->clearPopulatedValue($typeName); - $this->clearPopulatedValue($valName); - } - - $this->addElement('hidden', $typeName, [ - 'value' => 'incident_severity' - ]); - break; case 'incident_age': $val = $this->createElement( @@ -166,18 +155,6 @@ protected function assemble(): void ] ); - if ( - $this->getPopulatedValue($typeName) !== 'incident_age' - && $this->getPopulatedValue($valName) !== null - ) { - $this->clearPopulatedValue($typeName); - $this->clearPopulatedValue($valName); - } - - $this->addElement('hidden', $typeName, [ - 'value' => 'incident_age' - ]); - break; default: $val = $this->createElement('text', $valName, [ @@ -197,6 +174,7 @@ protected function assemble(): void $removePosition = (int) $this->getValue('remove'); if ($removePosition) { + $this->getElement('remove-position')->setValue($removePosition); unset($this->conditions[$removePosition]); $conditionCount -= 1; if ($conditionCount === 1 && ! $this->allowZeroConditions && $removePosition === 2) { @@ -207,7 +185,7 @@ protected function assemble(): void $this->conditions[$nextCount]->conditionType->setName('column_' . $n); $this->conditions[$nextCount]->operator->setName('operator_' . $n); $this->conditions[$nextCount]->conditionVal->setName('val_' . $n); - if ($conditionCount === 1) { + if ($conditionCount === 1 && ! $this->allowZeroConditions) { $this->conditions[$nextCount]->removeButton = null; } elseif ($this->conditions[$nextCount]->removeButton) { $this->conditions[$nextCount]->removeButton->setValue((string) $n); @@ -275,9 +253,17 @@ public function getCondition(): string $filter = Filter::any(); /** @var int $count */ $count = $this->getValue('condition-count'); + $removePosition = $this->getValue('remove-position'); + if ($removePosition) { + $count += 1; + } if ($count > 0) { // if count is 0, loop runs in reverse direction foreach (range(1, $count) as $count) { + if ($count === (int) $removePosition) { + continue; + } + $chosenType = $this->getValue('column_' . $count, 'placeholder'); $filterStr = $chosenType diff --git a/application/forms/EventRuleConfigElements/EscalationRecipient.php b/application/forms/EventRuleConfigElements/EscalationRecipient.php index 24713b61d..f780f11a6 100644 --- a/application/forms/EventRuleConfigElements/EscalationRecipient.php +++ b/application/forms/EventRuleConfigElements/EscalationRecipient.php @@ -24,6 +24,8 @@ protected function assemble(): void { $this->addElement('hidden', 'recipient-count', ['value' => '1']); + $this->addElement('hidden', 'remove-position'); + $addRecipientButton = $this->createElement( 'submitButton', 'add-recipient', @@ -105,6 +107,7 @@ protected function assemble(): void $removePosition = (int) $this->getValue('remove'); if ($removePosition) { + $this->getElement('remove-position')->setValue($removePosition); unset($this->recipients[$removePosition]); $recipientCount -= 1; if ($recipientCount === 1 && $removePosition === 2) { @@ -201,9 +204,17 @@ public function getRecipients(): array { /** @var int $count */ $count = $this->getValue('recipient-count'); + $removePosition = $this->getValue('remove-position'); + if ($removePosition) { + $count += 1; + } $values = []; for ($i = 1; $i <= $count; $i++) { + if ($i === (int) $removePosition) { + continue; + } + $value = []; $value['channel_id'] = $this->getValue('val_' . $i); $value['id'] = $this->getValue('id_' . $i); diff --git a/application/forms/EventRuleConfigForm.php b/application/forms/EventRuleConfigForm.php index c1d48cfbe..f0a049499 100644 --- a/application/forms/EventRuleConfigForm.php +++ b/application/forms/EventRuleConfigForm.php @@ -247,7 +247,7 @@ protected function assemble(): void if ($noZeroEscalationConditions === true) { foreach ($escalations as $escalation) { - $escalation->getCondition() + $escalation->condition ->setAllowZeroConditions(true); } @@ -255,7 +255,7 @@ protected function assemble(): void ->setValue(null); } elseif ($zeroConditionEscalation) { $escalations[$zeroConditionEscalation] - ->getCondition() + ->condition ->setAllowZeroConditions(true); }