Create DirectorDatafieldCategory for DirectorDatafield

This commit is contained in:
Valentina Da Rold 2019-10-01 15:33:42 +02:00
parent c1306c11f7
commit 50c477acce
3 changed files with 60 additions and 2 deletions

View File

@ -19,14 +19,19 @@ class DirectorDatafield extends DbObjectWithSettings
protected $autoincKeyName = 'id';
protected $defaultProperties = array(
protected $defaultProperties = [
'id' => null,
'category_id' => null,
'varname' => null,
'caption' => null,
'description' => null,
'datatype' => null,
'format' => null,
);
];
protected $relations = [
'category' => 'DirectorDatafieldCategory'
];
protected $settingsTable = 'director_datafield_setting';

View File

@ -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,
];
}

View File

@ -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
* @return ZfElement[]