12, 'height' => 5]; public const DEFAULT_REFRESH_RATE = 60; // Dashboard widget dynamic state. public const SIMPLE_ITEM = 0; public const DYNAMIC_ITEM = 1; final public function getForm(array $values, ?string $templateid): CWidgetForm { $form_class = implode('\\', [$this->getNamespace(), 'Includes', $this->manifest['widget']['form_class']]); if (!class_exists($form_class)) { $form_class = CWidgetForm::class; } $form = new $form_class($values, $templateid); $refresh_rates = self::getRefreshRates(); $form->addField( (new CWidgetFieldSelect('rf_rate', _('Refresh interval'), [ -1 => _('Default').' ('.$refresh_rates[$this->getDefaultRefreshRate()].')' ] + $refresh_rates ))->setDefault(-1) ); return $form ->addFields() ->setFieldsValues(); } final public function getActions(): array { $actions = parent::getActions() + [ 'widget.'.$this->getId().'.view' => [], 'widget.'.$this->getId().'.edit' => [] ]; $actions['widget.'.$this->getId().'.view'] += [ 'class' => CControllerDashboardWidgetView::class, 'view' => 'widget.view', 'layout' => 'layout.widget' ]; $actions['widget.'.$this->getId().'.edit'] += [ 'class' => CControllerDashboardWidgetEdit::class, 'view' => 'widget.edit', 'layout' => 'layout.json' ]; return $actions; } public function getDefaults(): array { return [ 'name' => $this->getDefaultName(), 'size' => $this->getDefaultSize(), 'js_class' => $this->getJSClass() ]; } public function isDeprecated(): bool { return false; } public function getDefaultName(): string { return $this->manifest['widget']['name'] !== '' ? $this->manifest['widget']['name'] : $this->getName(); } public function getDefaultSize(): array { $size = $this->manifest['widget']['size']; if (!array_key_exists('width', $size) || !array_key_exists('height', $size)) { return self::DEFAULT_SIZE; } if ($size['width'] < 1) { $size['width'] = 1; } if ($size['width'] > DASHBOARD_MAX_COLUMNS) { $size['width'] = DASHBOARD_MAX_COLUMNS; } if ($size['height'] < DASHBOARD_WIDGET_MIN_ROWS) { $size['height'] = DASHBOARD_WIDGET_MIN_ROWS; } if ($size['height'] > DASHBOARD_WIDGET_MAX_ROWS) { $size['height'] = DASHBOARD_WIDGET_MAX_ROWS; } return $size; } public function getJSClass(): string { return $this->manifest['widget']['js_class']; } public function getDefaultRefreshRate(): int { return array_key_exists($this->manifest['widget']['refresh_rate'], self::getRefreshRates()) ? (int) $this->manifest['widget']['refresh_rate'] : self::DEFAULT_REFRESH_RATE; } public function usesTimeSelector(array $fields_values): bool { return (bool) $this->manifest['widget']['use_time_selector']; } private static function getRefreshRates(): array { return [ 0 => _('No refresh'), 10 => _n('%1$s second', '%1$s seconds', 10), 30 => _n('%1$s second', '%1$s seconds', 30), 60 => _n('%1$s minute', '%1$s minutes', 1), 120 => _n('%1$s minute', '%1$s minutes', 2), 600 => _n('%1$s minute', '%1$s minutes', 10), 900 => _n('%1$s minute', '%1$s minutes', 15) ]; } }