Source
$result[CWidgetFieldColumnsList::HISTORY_DATA_HISTORY][$db_item_value['itemid']][] = $db_item_value
<?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\ItemHistory\Actions;
use API,
CArrayHelper,
CControllerDashboardWidgetView,
CControllerResponseData,
CItemHelper,
CNumberParser;
use Widgets\ItemHistory\Includes\CWidgetFieldColumnsList;
class WidgetView extends CControllerDashboardWidgetView {
protected function init(): void {
parent::init();
$this->addValidationRules([
'has_custom_time_period' => 'in 1'
]);
}
protected function doAction(): void {
$name = $this->widget->getDefaultName();
$data = [
'name' => $this->getInput('name', $name),
'info' => $this->makeWidgetInfo(),
'columns' => [],
'item_values' => [],
'layout' => $this->fields_values['layout'],
'show_lines' => $this->fields_values['show_lines'],
'show_column_header' => $this->fields_values['show_column_header'],
'show_thumbnail' => false,
'show_timestamp' => $this->fields_values['show_timestamp'],
'sortorder' => $this->fields_values['sortorder'],
'error' => null,
'user' => [
'debug_mode' => $this->getDebugMode()
]
];
if (!$this->fields_values['override_hostid'] && $this->isTemplateDashboard()) {
$data['error'] = _('No data.');
$this->setResponse(new CControllerResponseData($data));
return;
}
$columns = $this->fields_values['columns'];
$db_items = [];
if ($columns) {
if ($this->fields_values['override_hostid']) {
$db_item_keys = API::Item()->get([
'output' => ['key_'],
'itemids' => array_column($columns, 'itemid'),
'webitems' => true,
'preservekeys' => true
]);
if ($db_item_keys) {
$db_items = API::Item()->get([
'output' => ['key_', 'value_type', 'units', 'valuemapid', 'history', 'trends'],
'selectValueMap' => ['mappings'],
'hostids' => $this->fields_values['override_hostid'],
'filter' => [
'key_' => array_column($db_item_keys, 'key_')
],
'webitems' => true,
'preservekeys' => true
]);
$itemid_by_key = $db_items
? array_combine(array_column($db_items, 'key_'), array_keys($db_items))