error = $widget_settings['error']; $this->sysmap_data = $sysmap_data; $this->current_sysmapid = $widget_settings['current_sysmapid']; $this->filter_widget_reference = $widget_settings['filter_widget_reference']; $this->source_type = $widget_settings['source_type']; $this->previous_map = $widget_settings['previous_map']; $this->initial_load = $widget_settings['initial_load']; } /** * A javascript that is used as widget's script_inline parameter. */ public function getScriptData(): array { $map_data = [ 'current_sysmapid' => null, 'filter_widget_reference' => null, 'map_options' => null ]; if ($this->current_sysmapid !== null && $this->initial_load) { $map_data['current_sysmapid'] = $this->current_sysmapid; } if ($this->source_type == Widget::SOURCETYPE_FILTER && $this->filter_widget_reference && $this->initial_load) { $map_data['filter_widget_reference'] = $this->filter_widget_reference; } if ($this->sysmap_data && $this->error === null) { $map_data['map_options'] = $this->sysmap_data; } elseif ($this->error !== null && $this->source_type == Widget::SOURCETYPE_FILTER) { $map_data['error_msg'] = (new CTableInfo()) ->setNoDataMessage($this->error) ->toString(); } return $map_data; } public function toString($destroy = true): string { $this->build(); return parent::toString($destroy); } private function build(): void { $this->addClass(ZBX_STYLE_SYSMAP); $this->setId(uniqid('', true)); if ($this->error === null) { if ($this->previous_map) { $go_back_div = (new CDiv()) ->addClass(ZBX_STYLE_BTN_BACK_MAP_CONTAINER) ->addItem( (new CLink( (new CSpan()) ->addClass(ZBX_STYLE_BTN_BACK_MAP) ->addItem( (new CDiv()) ->addClass(ZBX_STYLE_BTN_BACK_MAP_ICON) ->addClass(ZBX_ICON_CHEVRON_LEFT) ) ->addItem( (new CDiv()) ->addClass(ZBX_STYLE_BTN_BACK_MAP_CONTENT) ->addItem(_s('Go back to %1$s', $this->previous_map['name'])) ), '#' ))->addClass('js-previous-map') ); $this->addItem($go_back_div); } $map_div = (new CDiv( (new CDiv($this->sysmap_data['aria_label']))->addClass(ZBX_STYLE_SYSMAP_CAPTION)) )->addClass('sysmap-widget-container'); $this->addStyle('position:relative;'); $this->addItem($map_div); } elseif ($this->source_type == Widget::SOURCETYPE_MAP) { $this->addItem( (new CTableInfo())->setNoDataMessage($this->error) ); } } }