---
title: "Dashboard Plugin"
url: https://festi.dev/8.0/Plugins/Dashboard/
---

# Dashboard Plugin

The Dashboard plugin provides a flexible and extensible dashboard system for creating customizable user interfaces with various widget types. It allows users to create, manage, and customize their own dashboards with different types of widgets.

## Features

- Create and manage multiple dashboards
- Support for various widget types:
  - Data Grid Store (DGS) widgets
  - Chart widgets (bar, line, pie, etc.)
  - Custom widgets with filters
  - Detailed widgets
- Drag-and-drop widget layout
- Widget refresh functionality
- Permission-based widget access
- Customizable widget filters
- Responsive design

## Widget Types

### 1. Data Grid Store (DGS) Widgets

DGS widgets are used to display tabular data with sorting, filtering, and pagination capabilities.

```php
<?php

namespace plugin\Plugin\widgets\WidgetClass;

class WidgetClass extends DataGridStoreWidget
{
    public const IDENT = 'widget_ident';

    /**
     * @return IStore
     */
    protected function getStore(): IStore
    {
        return new Store();
    }
}

```

### 2. Chart Widgets

Chart widgets provide visualization capabilities using various chart types:

```php
<?php

class ChartWidget extends AbstractWidget implements IChartWidget
{
    protected function loadData(): void
    {
        // Load your data here
    }

    protected function getLabels(): array
    {
        return ['Label 1', 'Label 2'];
    }

    protected function getDatasets(): array
    {
        return [
            [
                'label' => 'Dataset 1',
                'data' => [10, 20]
            ]
        ];
    }
}

```

Supported chart types:
- Bar charts
- Line charts
- Pie charts
- Doughnut charts
- Radar charts
- Polar area charts
- Bubble charts
- Scatter charts

### 3. Filtered Widgets

Widgets can implement filters for data filtering:

```php
<?php

class FilteredWidget extends AbstractWidget implements IDashboardWidgetFilters
{
    public function getFilterFields(): array
    {
        return [
            new WidgetFilterValuesObject('filter_name', 'Filter Label', 'text')
        ];
    }
}

```

## Database Setup

To add a new widget to the system, you need to create a database entry:

```sql
INSERT INTO dashboard_widgets(title, name, ident, section_ident)
VALUES ('Widget', 'Plugin Widget', 'widget', 'dashboard_widget_widget');

```

Optional: add section to widget

```sql
INSERT INTO festi_sections (caption, ident, mask)
VALUES ('Dashboard Widget: Widget', 'dashboard_widget_widget', '6');

```

## Widget Implementation

### Basic Widget Structure

All widgets must implement the `IDashboardWidget` interface:

```php
interface IDashboardWidget
{
    public const IDENT = '';
    
    public function getDashboardValuesObject(): DashboardValuesObject;
    public function getDashboardWidgetValuesObject(): DashboardWidgetValuesObject;
    public function getBlock(): IStore|IDisplayStoreAction|string|callable;
    public function getIndex(): int;
    public function isRefresh(): bool;
    public function getBlockType(): string;
    public function getCSS(): array;
    public function getAttributes(): array;
}

```

### Widget Options

Common widget options:

- `OPTION_INDEX`: Widget position index
- `OPTION_REFRESH`: Enable/disable refresh functionality
- `OPTION_BLOCK_TYPE`: Type of content block
- `OPTION_PER_PAGE`: Items per page (for DGS widgets)
- `OPTION_CHART_TYPE`: Chart visualization type

## Usage Examples

### Creating a Dashboard

```php
$dashboardPlugin = Core::getInstance()->getPluginInstance('Dashboard');
$dashboard = new DashboardValuesObject([
    'id_user' => $userId,
    'title' => 'My Dashboard'
]);
$dashboardId = $dashboardPlugin->createDashboard($dashboard);

```

### Adding a Widget to Dashboard

```php
$widget = new DashboardWidgetValuesObject([
    'title' => 'My Widget',
    'className' => 'MyWidgetClass'
]);
$widgetId = $dashboardPlugin->createDashboardWidget($dashboardId, $widget);

```

### Removing a Widget

```php
$dashboardPlugin->removeWidget($dashboardId, $widgetId);

```

## Customizing the Dashboard Page

The dashboard page (`/dashboard/widget/`) shows no guide block by default. Before the plugin builds the page, it dispatches `plugin\Dashboard\events\DisplayDashboardPageEvent`. Use a listener of this event to change the page in your project.

The event gives these methods:

| Method | Use |
|---|---|
| `getStageBuilder()` | Returns the `DashboardBuilder` of the page. A block that you add with `addBlock()` shows above the dashboard selector and the widgets. |
| `getBreadcrumbs()` / `setBreadcrumbs()` | Read or replace the breadcrumbs: caption => URL, or `false` for the current page. |
| `getDashboard()` | Returns the dashboard that the page shows, or `null` when the user has no dashboard. |
| `getPlugin()` | Returns the `DashboardPlugin` instance. |

To add a guide block, do these steps:

1. Register the listener after the Core initialization, for example in the `init.php` of your plugin.
2. In the listener, fetch the block and add it to the stage builder.

```php
// init.php
$this->addEventListener(
    Core::EVENT_ON_AFTER_INIT,
    function () {
        $core = Core::getInstance();

        $plugin = $core->getPluginInstance('School');

        $listener = [
            $plugin,
            'onDisplayDashboardPageHandler',
        ];

        $core->addEventListener(DisplayDashboardPageEvent::EVENT_TYPE, $listener);
    }
);

// SchoolPlugin.php
public function onDisplayDashboardPageHandler(DisplayDashboardPageEvent $event): void
{
    $iconUrl = $this->getUrl('/static/images/guide-block/shield.png');

    $guideBlock = $this->ui->guideBlock()
        ->setTitle(__('Dashboards'))
        ->setDescription(__('Here you can manage your dashboards and widgets'))
        ->setIcon($iconUrl);

    $content = $guideBlock->fetch();

    $event->getStageBuilder()->addBlock($content);
}
```

The plugin dispatches the event only on `/dashboard/widget/`. The area dashboards (`onDisplayByArea()`) do not dispatch it.

## Using gridstack.js

The **Dashboard** plugin is based on the external component [gridstack.js](https://github.com/gridstack/gridstack.js), version **12.3.3**.  
This component provides a flexible mechanism for managing widget positioning and sizing within the workspace.

---

### Mobile Version Features

The mobile version of the Dashboard has the following limitations and behaviors:

- **Edit mode is disabled**  
  When the Dashboard is opened on a mobile device, all actions related to modifying the grid layout are restricted.

- **Responsive widget layout**
  - Each widget automatically occupies the full available width of the container.
  - The height is determined dynamically based on its content.

Thus, the mobile version is intended primarily for **viewing**, rather than modifying the Dashboard structure.
