IcingaTemplateChoice: new base object, host/service

This commit is contained in:
Thomas Gelf 2017-06-20 06:53:12 +02:00
parent 171e15e95a
commit cef947e6fc
3 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,88 @@
<?php
namespace Icinga\Module\Director\Objects;
class IcingaTemplateChoice extends IcingaObject
{
private $objectTable;
protected $defaultProperties = [
'id' => null,
'object_name' => null,
'description' => null,
'min_required' => 0,
'max_allowed' => 1,
];
private $choices;
private $unstoredChoices;
public function getObjectTableName()
{
return substr($this->table, 0, -16);
}
public function getChoices()
{
if ($this->choices === null) {
$this->choices = $this->fetchChoices();
}
return $this->choices;
}
public function fetchChoices()
{
if ($this->hasBeenLoadedFromDb()) {
$db = $this->getDb();
$query = $db->select()->from(
['o' => $this->objectTable],
['o.id', 'o.object_name']
)->where("o.object_type = 'template'")
->where('o.template_choice_id = ?', $this->get('id'));
return $db->fetchPairs($query);
} else {
return [];
}
}
public function enumChoices()
{
$choices = $this->getChoices();
return array_combine($choices, $choices);
}
/*
* TODO: mukti?
protected $relations = [
'depends_on' => 'IcingaHost',
];
*/
/**
* @param $type
* @codingStandardsIgnoreStart
*/
public function setObject_type($type)
{
// @codingStandardsIgnoreEnd
}
}
/*
Normale Imports -> Windows Basis Checks
Execution speed:
Add field
* Type: host/service template choice
*
Build a host:
* Kinds of templates
*/

View File

@ -0,0 +1,10 @@
<?php
namespace Icinga\Module\Director\Objects;
class IcingaTemplateChoiceHost extends IcingaTemplateChoice
{
protected $table = 'icinga_host_template_choice';
protected $objectTable = 'icinga_host';
}

View File

@ -0,0 +1,10 @@
<?php
namespace Icinga\Module\Director\Objects;
class IcingaTemplateChoiceHost extends IcingaTemplateChoice
{
protected $table = 'icinga_service_template_choice';
protected $objectTable = 'icinga_service';
}