IcingaObjectMultiRelations: Enable more config options

This commit is contained in:
Markus Frosch 2018-09-13 13:56:11 +02:00
parent 3ae39af1cb
commit 63eda31a64
1 changed files with 25 additions and 6 deletions

View File

@ -28,17 +28,26 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen
protected $relationIdColumn; protected $relationIdColumn;
protected $relatedShortName;
private $position = 0; private $position = 0;
private $db; private $db;
protected $idx = array(); protected $idx = array();
public function __construct(IcingaObject $object, $propertyName, $relatedObjectClass) public function __construct(IcingaObject $object, $propertyName, $config)
{ {
$this->object = $object; $this->object = $object;
$this->propertyName = $propertyName; $this->propertyName = $propertyName;
$this->relatedObjectClass = $relatedObjectClass;
if (is_object($config) || is_array($config)) {
foreach ($config as $k => $v) {
$this->$k = $v;
}
} else {
$this->relatedObjectClass = $config;
}
} }
public function getObjects() public function getObjects()
@ -238,15 +247,26 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen
return $this->propertyName; return $this->propertyName;
} }
protected function getRelatedShortName()
{
if ($this->relatedShortName === null) {
/** @var IcingaObject $class */
$class = $this->getRelatedClassName();
$this->relatedShortName = $class::create()->getShortTableName();
}
return $this->relatedShortName;
}
protected function getTableName() protected function getTableName()
{ {
$class = $this->getRelatedClassName(); return $this->object->getTableName() . '_' . $this->getRelatedShortName();
return $this->object->getTableName() . '_' . $class::create()->getShortTableName();
} }
protected function getRelatedTableName() protected function getRelatedTableName()
{ {
if ($this->relatedTableName === null) { if ($this->relatedTableName === null) {
/** @var IcingaObject $class */
$class = $this->getRelatedClassName(); $class = $this->getRelatedClassName();
$this->relatedTableName = $class::create()->getTableName(); $this->relatedTableName = $class::create()->getTableName();
} }
@ -257,8 +277,7 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen
protected function getRelationIdColumn() protected function getRelationIdColumn()
{ {
if ($this->relationIdColumn === null) { if ($this->relationIdColumn === null) {
$class = $this->getRelatedClassName(); $this->relationIdColumn = $this->getRelatedShortName();
$this->relationIdColumn = $class::create()->getShortTableName();
} }
return $this->relationIdColumn; return $this->relationIdColumn;