Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'ui/include/classes/widgets/fields/CWidgetFieldGraphOverride.php')
-rw-r--r--ui/include/classes/widgets/fields/CWidgetFieldGraphOverride.php119
1 files changed, 43 insertions, 76 deletions
diff --git a/ui/include/classes/widgets/fields/CWidgetFieldGraphOverride.php b/ui/include/classes/widgets/fields/CWidgetFieldGraphOverride.php
index f9a6a6ba166..ef9558b47bf 100644
--- a/ui/include/classes/widgets/fields/CWidgetFieldGraphOverride.php
+++ b/ui/include/classes/widgets/fields/CWidgetFieldGraphOverride.php
@@ -1,4 +1,4 @@
-<?php
+<?php declare(strict_types = 0);
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
@@ -19,43 +19,43 @@
**/
+namespace Zabbix\Widgets\Fields;
+
+use Zabbix\Widgets\CWidgetField;
+
/**
* Class for override widget field used in Graph widget configuration overrides tab.
*/
class CWidgetFieldGraphOverride extends CWidgetField {
- /**
- * Create widget field for Graph Override selection.
- *
- * @param string $name Field name in form.
- * @param string $label Label for the field in form.
- */
- public function __construct($name, $label) {
+ public const DEFAULT_VALUE = [];
+
+ public function __construct(string $name, string $label = null) {
parent::__construct($name, $label);
- $this->setSaveType(ZBX_WIDGET_FIELD_TYPE_STR);
- $this->setValidationRules(['type' => API_OBJECTS, 'fields' => [
- 'hosts' => ['type' => API_STRINGS_UTF8, 'flags' => API_REQUIRED],
- 'items' => ['type' => API_STRINGS_UTF8, 'flags' => API_REQUIRED],
- 'color' => ['type' => API_COLOR],
- 'type' => ['type' => API_INT32, 'in' => implode(',', [SVG_GRAPH_TYPE_LINE, SVG_GRAPH_TYPE_POINTS, SVG_GRAPH_TYPE_STAIRCASE, SVG_GRAPH_TYPE_BAR])],
- 'width' => ['type' => API_INT32, 'in' => implode(',', range(0, 10))],
- 'pointsize' => ['type' => API_INT32, 'in' => implode(',', range(1, 10))],
- 'transparency' => ['type' => API_INT32, 'in' => implode(',', range(0, 10))],
- 'fill' => ['type' => API_INT32, 'in' => implode(',', range(0, 10))],
- 'missingdatafunc' => ['type' => API_INT32, 'in' => implode(',', [SVG_GRAPH_MISSING_DATA_NONE, SVG_GRAPH_MISSING_DATA_CONNECTED, SVG_GRAPH_MISSING_DATA_TREAT_AS_ZERO])],
- 'axisy' => ['type' => API_INT32, 'in' => implode(',', [GRAPH_YAXIS_SIDE_LEFT, GRAPH_YAXIS_SIDE_RIGHT])],
- 'timeshift' => ['type' => API_TIME_UNIT, 'in' => implode(':', [ZBX_MIN_TIMESHIFT, ZBX_MAX_TIMESHIFT])]
- ]]);
- $this->setDefault([]);
+ $this
+ ->setDefault(self::DEFAULT_VALUE)
+ ->setSaveType(ZBX_WIDGET_FIELD_TYPE_STR)
+ ->setValidationRules(['type' => API_OBJECTS, 'fields' => [
+ 'hosts' => ['type' => API_STRINGS_UTF8, 'flags' => API_REQUIRED],
+ 'items' => ['type' => API_STRINGS_UTF8, 'flags' => API_REQUIRED],
+ 'color' => ['type' => API_COLOR],
+ 'type' => ['type' => API_INT32, 'in' => implode(',', [SVG_GRAPH_TYPE_LINE, SVG_GRAPH_TYPE_POINTS, SVG_GRAPH_TYPE_STAIRCASE, SVG_GRAPH_TYPE_BAR])],
+ 'width' => ['type' => API_INT32, 'in' => implode(',', range(0, 10))],
+ 'pointsize' => ['type' => API_INT32, 'in' => implode(',', range(1, 10))],
+ 'transparency' => ['type' => API_INT32, 'in' => implode(',', range(0, 10))],
+ 'fill' => ['type' => API_INT32, 'in' => implode(',', range(0, 10))],
+ 'missingdatafunc' => ['type' => API_INT32, 'in' => implode(',', [SVG_GRAPH_MISSING_DATA_NONE, SVG_GRAPH_MISSING_DATA_CONNECTED, SVG_GRAPH_MISSING_DATA_TREAT_AS_ZERO])],
+ 'axisy' => ['type' => API_INT32, 'in' => implode(',', [GRAPH_YAXIS_SIDE_LEFT, GRAPH_YAXIS_SIDE_RIGHT])],
+ 'timeshift' => ['type' => API_TIME_UNIT, 'in' => implode(':', [ZBX_MIN_TIMESHIFT, ZBX_MAX_TIMESHIFT])]
+ ]]);
+ }
+
+ public function getOverrideOptions(): array {
+ return ['color', 'width', 'type', 'transparency', 'fill', 'pointsize', 'missingdatafunc', 'axisy', 'timeshift'];
}
- /**
- * Set field values for the overrides.
- *
- * @return $this
- */
- public function setValue($value) {
+ public function setValue($value): self {
$overrides = [];
foreach ((array) $value as $override) {
@@ -65,17 +65,17 @@ class CWidgetFieldGraphOverride extends CWidgetField {
return parent::setValue($overrides);
}
- /**
- * Set additional flags, which can be used in configuration form.
- *
- * @param int $flags
- *
- * @return $this
- */
- public function setFlags($flags) {
+ public static function getDefaults(): array {
+ return [
+ 'hosts' => [],
+ 'items' => []
+ ];
+ }
+
+ public function setFlags(int $flags): self {
parent::setFlags($flags);
- if ($flags & self::FLAG_NOT_EMPTY) {
+ if (($flags & self::FLAG_NOT_EMPTY) !== 0) {
$strict_validation_rules = $this->getValidationRules();
self::setValidationRuleFlag($strict_validation_rules['fields']['hosts'], API_NOT_EMPTY);
self::setValidationRuleFlag($strict_validation_rules['fields']['items'], API_NOT_EMPTY);
@@ -84,47 +84,21 @@ class CWidgetFieldGraphOverride extends CWidgetField {
$this->setStrictValidationRules($strict_validation_rules);
}
else {
- $this->setStrictValidationRules(null);
+ $this->setStrictValidationRules();
}
return $this;
}
- /**
- * Default values filled in newly created data set or used as unspecified values.
- *
- * @return array
- */
- public static function getDefaults() {
- return [
- 'hosts' => [],
- 'items' => []
- ];
- }
-
- /**
- * Returns array of supported override options.
- *
- * @return array
- */
- public static function getOverrideOptions() {
- return ['color', 'width', 'type', 'transparency', 'fill', 'pointsize', 'missingdatafunc', 'axisy', 'timeshift'];
- }
-
- /**
- * @param bool $strict
- *
- * @return array
- */
public function validate(bool $strict = false): array {
$errors = parent::validate($strict);
$value = $this->getValue();
- $label = ($this->label === null) ? $this->name : $this->label;
+ $label = $this->label ?? $this->name;
// Validate options.
if (!$errors && $strict) {
foreach ($value as $index => $overrides) {
- if (!array_intersect(self::getOverrideOptions(), array_keys($overrides))) {
+ if (!array_intersect($this->getOverrideOptions(), array_keys($overrides))) {
$errors[] = _s('Invalid parameter "%1$s": %2$s.', $label.'/'.($index + 1),
_('at least one override option must be specified')
);
@@ -136,14 +110,7 @@ class CWidgetFieldGraphOverride extends CWidgetField {
return $errors;
}
- /**
- * Prepares array entry for widget field, ready to be passed to CDashboard API functions.
- * Reference is needed here to avoid array merging in CWidgetForm::fieldsToApi method. With large number of widget
- * fields it causes significant performance decrease.
- *
- * @param array $widget_fields reference to Array of widget fields.
- */
- public function toApi(array &$widget_fields = []) {
+ public function toApi(array &$widget_fields = []): void {
$value = $this->getValue();
foreach ($value as $index => $val) {
@@ -163,7 +130,7 @@ class CWidgetFieldGraphOverride extends CWidgetField {
];
}
- foreach (self::getOverrideOptions() as $opt) {
+ foreach ($this->getOverrideOptions() as $opt) {
if (array_key_exists($opt, $val)) {
$widget_fields[] = [
'type' => ($opt === 'color' || $opt === 'timeshift')