width = $width; // Height. $this->height = $height; // Grid Width. $this->gridWidth = $gridWidth; // Cell Id. $this->cellId = $cellId; // Options. $this->values = $this->decoders($this->getOptionsWidget()); // Positions. $this->position = $this->getPositionWidget(); // Page. $this->page = basename(__FILE__); // ClassName. $class = new \ReflectionClass($this); $this->className = $class->getShortName(); // Title. $this->title = __('Color tabs modules'); // Name. if (empty($this->name) === true) { $this->name = 'single_graph'; } // This forces at least a first configuration. $this->configurationRequired = false; if (empty($this->values['moduleDataMatrix']) === true) { $this->configurationRequired = true; } $this->overflow_scrollbars = false; } /** * Decoders hack for retrocompability. * * @param array $decoder Values. * * @return array Returns the values with the correct key. */ public function decoders(array $decoder): array { $values = []; // Retrieve global - common inputs. $values = parent::decoders($decoder); $values['agentsDataMatrix'] = []; if (isset($decoder['agentsDataMatrix']) === true) { if (isset($decoder['agentsDataMatrix'][0]) === true && empty($decoder['agentsDataMatrix']) === false ) { $values['agentsDataMatrix'] = explode( ',', $decoder['agentsDataMatrix'][0] ); } } if (isset($decoder['selectionDataMatrix']) === true) { $values['selectionDataMatrix'] = $decoder['selectionDataMatrix']; } $values['moduleDataMatrix'] = []; if (isset($decoder['moduleDataMatrix']) === true) { if (empty($decoder['moduleDataMatrix']) === false) { $values['moduleDataMatrix'] = $decoder['moduleDataMatrix']; } } if (isset($decoder['formatData']) === true) { $values['formatData'] = $decoder['formatData']; } $values['label'] = 'module'; if (isset($decoder['label']) === true) { $values['label'] = $decoder['label']; } if (isset($decoder['fontColor']) === true) { $values['fontColor'] = $decoder['fontColor']; } if (isset($decoder['period']) === true) { $values['period'] = $decoder['period']; } if (isset($decoder['slice']) === true) { $values['slice'] = $decoder['slice']; } if (isset($decoder['limit']) === true) { $values['limit'] = $decoder['limit']; } return $values; } /** * Generates inputs for form (specific). * * @return array Of inputs. * * @throws Exception On error. */ public function getFormInputs(): array { global $config; $values = $this->values; // Retrieve global - common inputs. $inputs = parent::getFormInputs(); $blocks = [ 'row1', 'row2', ]; $inputs['blocks'] = $blocks; foreach ($inputs as $kInput => $vInput) { $inputs['inputs']['row1'][] = $vInput; } if (isset($values['formatData']) === false) { $values['formatData'] = 1; } // Format Data. $inputs['inputs']['row1'][] = [ 'label' => __('Format Data'), 'arguments' => [ 'name' => 'formatData', 'id' => 'formatData', 'type' => 'switch', 'value' => $values['formatData'], ], ]; if (isset($values['period']) === false) { $values['period'] = SECONDS_1DAY; } $inputs['inputs']['row1'][] = [ 'label' => __('Periodicity'), 'arguments' => [ 'name' => 'period', 'type' => 'interval', 'value' => $values['period'], 'nothing' => __('None'), 'nothing_value' => 0, 'style_icon' => 'flex-grow: 0', 'script' => 'check_period_warning(this, \''.__('Warning').'\', \''.__('Displaying items with extended historical data can have an impact on system performance. We do not recommend that you use intervals longer than 30 days, especially if you combine several of them in a report, dashboard or visual console.').'\')', 'script_input' => 'check_period_warning_manual(\'period\', \''.__('Warning').'\', \''.__('Displaying items with extended historical data can have an impact on system performance. We do not recommend that you use intervals longer than 30 days, especially if you combine several of them in a report, dashboard or visual console.').'\')', ], ]; if (isset($values['slice']) === false) { $values['slice'] = SECONDS_5MINUTES; } $inputs['inputs']['row1'][] = [ 'label' => __('Interval'), 'arguments' => [ 'name' => 'slice', 'type' => 'interval', 'value' => $values['slice'], 'nothing' => __('None'), 'nothing_value' => 0, 'style_icon' => 'flex-grow: 0', 'script' => 'check_period_warning(this, \''.__('Warning').'\', \''.__('Displaying items with extended historical data can have an impact on system performance. We do not recommend that you use intervals longer than 30 days, especially if you combine several of them in a report, dashboard or visual console.').'\')', 'script_input' => 'check_period_warning_manual(\'slice\', \''.__('Warning').'\', \''.__('Displaying items with extended historical data can have an impact on system performance. We do not recommend that you use intervals longer than 30 days, especially if you combine several of them in a report, dashboard or visual console.').'\')', ], ]; if (isset($values['limit']) === false) { $values['limit'] = $config['block_size']; } // Limit Default block_size. $blockSizeD4 = \format_integer_round(($config['block_size'] / 4)); $blockSizeD2 = \format_integer_round(($config['block_size'] / 2)); $fields = [ $config['block_size'] => $config['block_size'], $blockSizeD4 => $blockSizeD4, $blockSizeD2 => $blockSizeD2, ($config['block_size'] * 2) => ($config['block_size'] * 2), ($config['block_size'] * 3) => ($config['block_size'] * 3), ]; $inputs['inputs']['row1'][] = [ 'label' => \__('Limit'), 'arguments' => [ 'type' => 'select', 'fields' => $fields, 'class' => 'event-widget-input', 'name' => 'limit', 'selected' => $values['limit'], 'return' => true, ], ]; // Type Label. $fields = [ 'module' => __('Module'), 'agent' => __('Agent'), 'agent_module' => __('Agent / module'), ]; $inputs['inputs']['row2'][] = [ 'label' => __('Label'), 'arguments' => [ 'type' => 'select', 'fields' => $fields, 'name' => 'label', 'selected' => $values['label'], 'return' => true, ], ]; $inputs['inputs']['row2'][] = [ 'arguments' => [ 'type' => 'select_multiple_modules_filtered_select2', 'agent_values' => agents_get_agents_selected(0), 'agent_name' => 'agentsDataMatrix[]', 'agent_ids' => $values['agentsDataMatrix'], 'selectionModules' => $values['selectionDataMatrix'], 'selectionModulesNameId' => 'selectionDataMatrix', 'modules_ids' => $values['moduleDataMatrix'], 'modules_name' => 'moduleDataMatrix[]', 'notStringModules' => true, ], ]; return $inputs; } /** * Get Post for widget. * * @return array */ public function getPost():array { // Retrieve global - common inputs. $values = parent::getPost(); $values['agentsDataMatrix'] = \get_parameter( 'agentsDataMatrix', [] ); $values['selectionDataMatrix'] = \get_parameter( 'selectionDataMatrix', 0 ); $values['moduleDataMatrix'] = \get_parameter( 'moduleDataMatrix' ); $agColor = []; if (isset($values['agentsDataMatrix'][0]) === true && empty($values['agentsDataMatrix'][0]) === false ) { $agColor = explode(',', $values['agentsDataMatrix'][0]); } $agModule = []; if (isset($values['moduleDataMatrix'][0]) === true && empty($values['moduleDataMatrix'][0]) === false ) { $agModule = explode(',', $values['moduleDataMatrix'][0]); } $values['moduleDataMatrix'] = \get_same_modules_all( $agColor, $agModule ); $values['formatData'] = \get_parameter_switch('formatData'); $values['fontColor'] = \get_parameter('fontColor', '#2c3e50'); $values['label'] = \get_parameter('label', 'module'); $values['period'] = \get_parameter('period', 0); $values['slice'] = \get_parameter('slice', 0); $values['limit'] = \get_parameter('limit', 20); return $values; } /** * Draw widget. * * @return string; */ public function load() { $this->size = parent::getSize(); $output = ''; if (count($this->values['moduleDataMatrix']) > self::MAX_MODULES) { $output .= '