diff --git a/application/controllers/EventRuleController.php b/application/controllers/EventRuleController.php index a72387782..7d46364f2 100644 --- a/application/controllers/EventRuleController.php +++ b/application/controllers/EventRuleController.php @@ -134,11 +134,12 @@ public function indexAction(): void $buttonsWrapper->add([$eventRuleConfigSubmitButton, $discardChangesButton, $deleteButton]); if ($ruleId > 0) { - $incidents = Incident::on(Database::get()) + $incidentCount = Incident::on(Database::get()) ->with('rule') - ->filter(Filter::equal('rule.id', $ruleId)); + ->filter(Filter::equal('rule.id', $ruleId)) + ->count(); - if ($incidents->count() > 0) { + if ($incidentCount) { $deleteButton->addAttributes([ 'disabled' => true, 'title' => t('There exist active incidents for this escalation and hence cannot be removed') diff --git a/application/forms/EventRuleConfigElements/EscalationRecipient.php b/application/forms/EventRuleConfigElements/EscalationRecipient.php index 46e9d2a3d..f0085a173 100644 --- a/application/forms/EventRuleConfigElements/EscalationRecipient.php +++ b/application/forms/EventRuleConfigElements/EscalationRecipient.php @@ -46,7 +46,9 @@ protected function assemble(): void $this->getElement('recipient-count')->setValue(++$recipientCount); } + $defaultOption = ['' => sprintf(' - %s - ', $this->translate('Please choose'))]; $removePosition = null; + foreach (range(1, $recipientCount) as $i) { $this->addElement('hidden', 'id_' . $i); @@ -55,9 +57,7 @@ protected function assemble(): void 'column_' . $i, [ 'class' => ['autosubmit', 'left-operand'], - 'options' => [ - '' => sprintf(' - %s - ', $this->translate('Please choose')) - ] + $this->fetchOptions(), + 'options' => $defaultOption + $this->fetchOptions(), 'disabledOptions' => [''], 'required' => true, 'value' => $this->getPopulatedValue('column_' . $i) @@ -66,8 +66,7 @@ protected function assemble(): void $this->registerElement($col); - $options = ['' => sprintf(' - %s - ', $this->translate('Please choose'))]; - $options += Channel::fetchChannelNames(Database::get()); + $options = $defaultOption + Channel::fetchChannelNames(Database::get()); $val = $this->createElement( 'select', diff --git a/application/forms/EventRuleConfigForm.php b/application/forms/EventRuleConfigForm.php index 53b895141..251236845 100644 --- a/application/forms/EventRuleConfigForm.php +++ b/application/forms/EventRuleConfigForm.php @@ -270,8 +270,7 @@ public function populate($values): self foreach ($values['rule_escalation'] as $position => $escalation) { $conditions = explode('|', $escalation['condition'] ?? ''); $conditionFormValues = []; - $conditionCount = count($conditions); - $conditionFormValues['condition-count'] = $conditionCount; + $conditionFormValues['condition-count'] = count($conditions); $conditionFormValues['id'] = $escalation['id'] ?? bin2hex(random_bytes(4)); foreach ($conditions as $key => $condition) { @@ -381,11 +380,12 @@ protected function createRemoveButton(string $prefix): SubmitButtonElement $escalationId = $escalations[$pos]['id'] ?? null; if ($escalationId && ctype_digit($escalationId)) { - $incident = Incident::on(Database::get())->with('rule_escalation'); - $incident->filter(Filter::equal('rule_escalation.id', $escalationId)); - if ($incident->count() > 0) { - $disableRemoveButton = true; - } + $incidentCount = Incident::on(Database::get()) + ->with('rule_escalation') + ->filter(Filter::equal('rule_escalation.id', $escalationId)) + ->count(); + + $disableRemoveButton = $incidentCount > 0; } $button = new SubmitButtonElement( @@ -639,7 +639,7 @@ protected function getPrefixesMap(int $escalationCount): string { $prefixesMap = []; for ($i = 1; $i <= $escalationCount; $i++) { - $prefixesMap[(string) $i] = bin2hex((string) $i); + $prefixesMap[] = bin2hex((string) $i); } return implode(',', $prefixesMap);