<?php declare(strict_types = 0);
namespace Widgets\HostCard\Includes;
use Zabbix\Widgets\CWidgetField;
class CWidgetFieldHostSections extends CWidgetField {
public const DEFAULT_VIEW = CWidgetFieldHostSectionsView::class;
public const DEFAULT_VALUE = [];
public const SECTION_HOST_GROUPS = 0;
public const SECTION_DESCRIPTION = 1;
public const SECTION_MONITORING = 2;
public const SECTION_AVAILABILITY = 3;
public const SECTION_MONITORED_BY = 4;
public const SECTION_TEMPLATES = 5;
public const SECTION_INVENTORY = 6;
public const SECTION_TAGS = 7;
public function __construct(string $name, string $label = null) {
parent::__construct($name, $label);
$this
->setDefault(self::DEFAULT_VALUE)
->setValidationRules(['type' => API_INTS32, 'flags' => API_NORMALIZE, 'uniq' => true, 'in' => implode(',', [
self::SECTION_HOST_GROUPS,
self::SECTION_DESCRIPTION,
self::SECTION_MONITORING,
self::SECTION_AVAILABILITY,
self::SECTION_MONITORED_BY,
self::SECTION_TEMPLATES,
self::SECTION_INVENTORY,
self::SECTION_TAGS
])]);
}
public function toApi(array &$widget_fields = []): void {
foreach ($this->getValue() as $index => $value) {
$widget_fields[] = [
'type' => ZBX_WIDGET_FIELD_TYPE_INT32,
'name' => $this->name.'.'.$index,
'value' => $value
];
}
}
}