Create DirectorDatafieldCategory for DirectorDatafield
This commit is contained in:
parent
c1306c11f7
commit
50c477acce
|
@ -19,14 +19,19 @@ class DirectorDatafield extends DbObjectWithSettings
|
||||||
|
|
||||||
protected $autoincKeyName = 'id';
|
protected $autoincKeyName = 'id';
|
||||||
|
|
||||||
protected $defaultProperties = array(
|
protected $defaultProperties = [
|
||||||
'id' => null,
|
'id' => null,
|
||||||
|
'category_id' => null,
|
||||||
'varname' => null,
|
'varname' => null,
|
||||||
'caption' => null,
|
'caption' => null,
|
||||||
'description' => null,
|
'description' => null,
|
||||||
'datatype' => null,
|
'datatype' => null,
|
||||||
'format' => null,
|
'format' => null,
|
||||||
);
|
];
|
||||||
|
|
||||||
|
protected $relations = [
|
||||||
|
'category' => 'DirectorDatafieldCategory'
|
||||||
|
];
|
||||||
|
|
||||||
protected $settingsTable = 'director_datafield_setting';
|
protected $settingsTable = 'director_datafield_setting';
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Objects;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Data\Db\DbObject;
|
||||||
|
|
||||||
|
class DirectorDatafieldCategory extends DbObject
|
||||||
|
{
|
||||||
|
protected $table = 'director_datafield_category';
|
||||||
|
|
||||||
|
protected $keyName = 'id';
|
||||||
|
|
||||||
|
protected $autoincKeyName = 'id';
|
||||||
|
|
||||||
|
protected $defaultProperties = [
|
||||||
|
'id' => null,
|
||||||
|
'category_name' => null,
|
||||||
|
'description' => null,
|
||||||
|
];
|
||||||
|
}
|
|
@ -229,6 +229,39 @@ class IcingaObjectFieldLoader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ZfElement[] $elements
|
||||||
|
* @param DirectorObjectForm $form
|
||||||
|
*/
|
||||||
|
protected function attachGroupElements(array $elements, DirectorObjectForm $form)
|
||||||
|
{
|
||||||
|
$categories = [];
|
||||||
|
foreach ($this->fields as $key => $field) {
|
||||||
|
if ($category = $field->category) {
|
||||||
|
$categories[$key] = $category;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($elements as $key => $element) {
|
||||||
|
if (isset($categories[$key])) {
|
||||||
|
$category = $categories[$key];
|
||||||
|
$form->addElementsToGroup(
|
||||||
|
[$element],
|
||||||
|
'custom_fields_' . $category->get('id'),
|
||||||
|
50,
|
||||||
|
$category->get('category_name')
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$form->addElementsToGroup(
|
||||||
|
[$element],
|
||||||
|
'custom_fields',
|
||||||
|
50,
|
||||||
|
$form->translate('Custom properties')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ZfElement[] $elements
|
* @param ZfElement[] $elements
|
||||||
* @return ZfElement[]
|
* @return ZfElement[]
|
||||||
|
|
Loading…
Reference in New Issue