Merge branch 'feature/choice-with-required-import-1178'

This commit is contained in:
Thomas Gelf 2021-01-15 11:51:45 +01:00
commit fb2872ac7b
2 changed files with 22 additions and 1 deletions

View File

@ -91,6 +91,15 @@ class IcingaTemplateChoiceForm extends DirectorObjectForm
'value' => 1,
));
$this->addElement('select', 'required_template', [
'label' => $this->translate('Associated Template'),
'description' => $this->translate(
'Choose Choice Associated Template'
),
'required' => true,
'multiOptions' => $this->fetchUnboundTemplates(),
]);
$this->setButtons();
}

View File

@ -1180,9 +1180,21 @@ abstract class DirectorObjectForm extends DirectorForm
$connection = $this->getDb();
$choiceType = 'TemplateChoice' . ucfirst($type);
$table = "icinga_$type";
$choices = IcingaObject::loadAllByType($choiceType, $connection);
$chosenTemplates = $this->getSentOrObjectValue('imports');
$db = $connection->getDbAdapter();
$importedIds = $db->fetchCol(
$db->select()->from($table, 'id')
->where('object_name in (?)', (array)$chosenTemplates)
->where('object_type = ?', 'template')
);
foreach ($choices as $choice) {
$this->addChoiceElement($choice);
$required = $choice->get('required_template_id');
if ($required === null || in_array($required, $importedIds, false)) {
$this->addChoiceElement($choice);
}
}
return $this;