featureStatus = $featureStatus; $this->features = [ ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS => [ 'label' => t('Active Checks'), 'permission' => 'icingadb/command/feature/object/active-checks' ], ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS => [ 'label' => t('Passive Checks'), 'permission' => 'icingadb/command/feature/object/passive-checks' ], ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS => [ 'label' => t('Notifications'), 'permission' => 'icingadb/command/feature/object/notifications' ], ToggleObjectFeatureCommand::FEATURE_EVENT_HANDLER => [ 'label' => t('Event Handler'), 'permission' => 'icingadb/command/feature/object/event-handler' ], ToggleObjectFeatureCommand::FEATURE_FLAP_DETECTION => [ 'label' => t('Flap Detection'), 'permission' => 'icingadb/command/feature/object/flap-detection' ] ]; $this->getAttributes()->add('class', 'object-features'); } protected function assembleElements() { $decorator = new IcingaFormDecorator(); foreach ($this->features as $feature => $spec) { $options = [ 'class' => 'autosubmit', 'disabled' => $this->featureStatus instanceof Model ? ! $this->isGrantedOn($spec['permission'], $this->featureStatus) : false, 'label' => $spec['label'] ]; if ($this->featureStatus[$feature] === 2) { $this->addElement( 'select', $feature, $options + [ 'description' => t('Multiple Values'), 'options' => [ self::LEAVE_UNCHANGED => t('Leave Unchanged'), t('Disable All'), t('Enable All') ] ] ); $decorator->decorate($this->getElement($feature)); $this->getElement($feature) ->getWrapper() ->getAttributes() ->add('class', 'indeterminate'); } else { $options['value'] = (bool) $this->featureStatus[$feature]; $this->addElement('checkbox', $feature, $options); $decorator->decorate($this->getElement($feature)); } } } protected function assembleSubmitButton() { } protected function getCommand(Model $object) { foreach ($this->features as $feature => $spec) { $featureState = $this->getElement($feature)->isChecked(); if ( ! $this->isGrantedOn($spec['permission'], $object) || $featureState === self::LEAVE_UNCHANGED || (int) $featureState === (int) $this->featureStatus[$feature] ) { continue; } $command = new ToggleObjectFeatureCommand(); $command->setObject($object); $command->setFeature($feature); $command->setEnabled((int) $featureState); yield $command; } } }