IcingaTemplateChoiceForm: allow to require...
...a specific template/import fixes #1178
This commit is contained in:
parent
6687524d2f
commit
121dd774c4
|
@ -91,6 +91,15 @@ class IcingaTemplateChoiceForm extends DirectorObjectForm
|
||||||
'value' => 1,
|
'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();
|
$this->setButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1180,9 +1180,21 @@ abstract class DirectorObjectForm extends DirectorForm
|
||||||
|
|
||||||
$connection = $this->getDb();
|
$connection = $this->getDb();
|
||||||
$choiceType = 'TemplateChoice' . ucfirst($type);
|
$choiceType = 'TemplateChoice' . ucfirst($type);
|
||||||
|
$table = "icinga_$type";
|
||||||
$choices = IcingaObject::loadAllByType($choiceType, $connection);
|
$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) {
|
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;
|
return $this;
|
||||||
|
|
Loading…
Reference in New Issue