Source
xxxxxxxxxx
* string $elements['time'] Time related to the item value, or current time if no data.
<?php declare(strict_types = 0);
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
namespace Widgets\Item\Actions;
use API,
CAggFunctionData,
CArrayHelper,
CControllerDashboardWidgetView,
CControllerResponseData,
CItemHelper,
CMacrosResolverHelper,
CNumberParser,
CSettingsHelper,
CUrl,
Manager;
use Widgets\Item\Widget;
class WidgetView extends CControllerDashboardWidgetView {
protected function init(): void {
parent::init();
$this->addValidationRules([
'has_custom_time_period' => 'in 1'
]);
}
protected function doAction(): void {
$item = $this->getItem();
$output = [
'name' => $this->getName($item),
'info' => $this->makeWidgetInfo(),
'user' => [
'debug_mode' => $this->getDebugMode()
]
];
if ($item !== null) {
$show = array_flip($this->fields_values['show']);
$show_change_indicator = array_key_exists(Widget::SHOW_CHANGE_INDICATOR, $show);
[$data_last, $data_prev] = $this->getItemValues($item, $show_change_indicator);
$output += [
'cells' => $this->arrangeAndConfigure(
$this->getElements($item, $data_last, $data_prev, $this->fields_values['aggregate_function'])
),
'url' => $this->getUrl($item),
'bg_color' => $this->getBgColor($item, $data_last, $this->fields_values['aggregate_function'])
];
}
else {
$output['error'] = _('No permissions to referred object or it does not exist!');
}
$this->setResponse(new CControllerResponseData($output));
}
private function getItem(): ?array {
$resolve_macros = !$this->isTemplateDashboard() || $this->fields_values['override_hostid'];
$item_options = [
'output' => ['itemid', 'hostid', $resolve_macros ? 'name_resolved' : 'name', 'history', 'trends',
'value_type', 'units'
],
'selectValueMap' => ['mappings'],
'webitems' => true
];
if ($this->fields_values['override_hostid']) {
$src_items = API::Item()->get([
'output' => ['key_'],
'itemids' => $this->fields_values['itemid'],
'webitems' => true
]);