summaryrefslogtreecommitdiffstats
path: root/application/forms/IcingaTimePeriodForm.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
commitcd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch)
treefbff2135e7013f196b891bbde54618eb050e4aaf /application/forms/IcingaTimePeriodForm.php
parentInitial commit. (diff)
downloadicingaweb2-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.php82
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;
+ }
+}