diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
commit | cd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /application/forms/IcingaTimePeriodForm.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.tar.xz icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.zip |
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/forms/IcingaTimePeriodForm.php')
-rw-r--r-- | application/forms/IcingaTimePeriodForm.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/application/forms/IcingaTimePeriodForm.php b/application/forms/IcingaTimePeriodForm.php new file mode 100644 index 0000000..8afcdf3 --- /dev/null +++ b/application/forms/IcingaTimePeriodForm.php @@ -0,0 +1,82 @@ +<?php + +namespace Icinga\Module\Director\Forms; + +use Icinga\Module\Director\Web\Form\DirectorObjectForm; + +class IcingaTimePeriodForm extends DirectorObjectForm +{ + /** + * @throws \Zend_Form_Exception + */ + public function setup() + { + $this->addElement('text', 'object_name', [ + 'label' => $this->translate('Name'), + 'required' => true, + ]); + + $this->addElement('text', 'display_name', [ + 'label' => $this->translate('Display Name'), + ]); + + if ($this->isTemplate()) { + $this->addElement('text', 'update_method', [ + 'label' => $this->translate('Update Method'), + 'value' => 'LegacyTimePeriod', + ]); + } else { + // TODO: I'd like to skip this for objects inheriting from a template + // with a defined update_method. However, unfortunately it's too + // early for $this->object()->getResolvedProperty('update_method'). + // Should be fixed. + $this->addHidden('update_method', 'LegacyTimePeriod'); + } + + $this->addIncludeExclude() + ->addImportsElement() + ->setButtons(); + } + + /** + * @return $this + * @throws \Zend_Form_Exception + */ + protected function addIncludeExclude() + { + $periods = []; + foreach ($this->db->enumTimeperiods() as $id => $period) { + if ($this->object === null || $this->object->get('object_name') !== $period) { + $periods[$period] = $period; + } + } + + if (empty($periods)) { + return $this; + } + + $this->addElement('extensibleSet', 'includes', [ + 'label' => $this->translate('Include period'), + 'multiOptions' => $this->optionalEnum($periods), + 'description' => $this->translate( + 'Include other time periods into this.' + ), + ]); + + $this->addElement('extensibleSet', 'excludes', [ + 'label' => $this->translate('Exclude period'), + 'multiOptions' => $this->optionalEnum($periods), + 'description' => $this->translate( + 'Exclude other time periods from this.' + ), + ]); + + $this->optionalBoolean( + 'prefer_includes', + $this->translate('Prefer includes'), + $this->translate('Whether to prefer timeperiods includes or excludes. Default to true.') + ); + + return $this; + } +} |