width = $width; // Height. $this->height = $height; // Grid Width. $this->gridWidth = $gridWidth; // 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 = __('Clock'); // Name. if (empty($this->name) === true) { $this->name = 'clock'; } // This forces at least a first configuration. $this->configurationRequired = false; if (empty($this->values['clockType']) === 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); if (isset($decoder['clock_type']) === true) { $values['clockType'] = $decoder['clock_type']; } if (isset($decoder['clockType']) === true) { $values['clockType'] = $decoder['clockType']; } return $values; } /** * Generates inputs for form (specific). * * @return array Of inputs. * * @throws Exception On error. */ public function getFormInputs(): array { $values = $this->values; // Retrieve global - common inputs. $inputs = parent::getFormInputs(); // Type clock. $fields = [ 'analogic' => __('Analogic'), 'digital' => __('Digital'), ]; $inputs[] = [ 'label' => __('Type'), 'arguments' => [ 'type' => 'select', 'fields' => $fields, 'name' => 'clockType', 'selected' => $values['clockType'], 'return' => true, ], ]; return $inputs; } /** * Get Post for widget. * * @return array */ public function getPost():array { // Retrieve global - common inputs. $values = parent::getPost(); $values['clockType'] = \get_parameter('clockType', 0); return $values; } /** * Draw widget. * * @return string; */ public function load() { global $config; $size = parent::getSize(); include_once $config['homedir'].'/include/graphs/functions_d3.php'; $id = \uniqid(); $output = '
'; if ($this->values['clockType'] === 'analogic') { $posAnolgic = (int) $size['height']; if ((int) $size['width'] < (int) $size['height']) { $posAnolgic = (int) $size['width']; } $output .= "
"; $output .= print_clock_analogic_1( 'time', $config['timezone'], 'analogic_1', $posAnolgic, $posAnolgic, $id, '#000000', false ); $output .= '
'; } else { $output .= "
"; $output .= print_clock_digital_1( 'time', $config['timezone'], 'digital_1', $size['width'], $size['height'], $id, '#000000' ); $output .= '
'; } $output .= '
'; return $output; } /** * Get description. * * @return string. */ public static function getDescription() { return __('Clock'); } /** * Get Name. * * @return string. */ public static function getName() { return 'clock'; } /** * Get size Modal Configuration. * * @return array */ public function getSizeModalConfiguration(): array { $size = [ 'width' => 400, 'height' => 270, ]; return $size; } }