2016-03-09 20:53:57 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Objects;
|
|
|
|
|
2016-10-24 23:55:02 +02:00
|
|
|
use Icinga\Application\Config;
|
|
|
|
use Icinga\Exception\IcingaException;
|
|
|
|
use Icinga\Module\Director\Db;
|
2016-05-02 10:26:41 +02:00
|
|
|
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
|
|
|
|
2016-03-09 20:53:57 +01:00
|
|
|
abstract class IcingaObjectGroup extends IcingaObject
|
|
|
|
{
|
|
|
|
protected $supportsImports = true;
|
|
|
|
|
2016-10-13 15:44:53 +02:00
|
|
|
protected $supportedInLegacy = true;
|
|
|
|
|
2016-03-09 20:53:57 +01:00
|
|
|
protected $defaultProperties = array(
|
2016-10-24 05:41:37 +02:00
|
|
|
'id' => null,
|
|
|
|
'object_name' => null,
|
|
|
|
'object_type' => null,
|
|
|
|
'disabled' => 'n',
|
|
|
|
'display_name' => null,
|
|
|
|
'assign_filter' => null,
|
2016-03-09 20:53:57 +01:00
|
|
|
);
|
2016-05-02 10:26:41 +02:00
|
|
|
|
|
|
|
public function getRenderingZone(IcingaConfig $config = null)
|
|
|
|
{
|
|
|
|
return $this->connection->getDefaultGlobalZoneName();
|
|
|
|
}
|
2016-10-24 23:55:02 +02:00
|
|
|
|
|
|
|
public static function enumForType($type, Db $connection = null)
|
|
|
|
{
|
|
|
|
if ($connection === null) {
|
|
|
|
// TODO: not nice :(
|
|
|
|
$connection = Db::fromResourceName(
|
|
|
|
Config::module('director')->get('db', 'resource')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last resort defense against potentiall lousy checks:
|
|
|
|
if (! ctype_alpha($type)) {
|
|
|
|
throw new IcingaException(
|
|
|
|
'Holy shit, you should never have reached this'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$db = $connection->getDbAdapter();
|
|
|
|
$select = $db->select()->from(
|
|
|
|
'icinga_' . $type . 'group',
|
|
|
|
array(
|
|
|
|
'name' => 'object_name',
|
|
|
|
'display' => 'COALESCE(display_name, object_name)'
|
|
|
|
)
|
|
|
|
)->where('object_type = ?', 'object')->order('display');
|
|
|
|
|
|
|
|
return $db->fetchPairs($select);
|
|
|
|
}
|
2016-03-09 20:53:57 +01:00
|
|
|
}
|