PHP code example of javer / influxdb-admin-bundle

1. Go to this page and download the library: Download javer/influxdb-admin-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

javer / influxdb-admin-bundle example snippets


// config/bundles.php

return [
    // ...
    Javer\InfluxDB\AdminBundle\JaverInfluxDBAdminBundle::class => ['all' => true],
];

// src/Measurement/CpuLoad.php
namespace App\Measurement;

use Javer\InfluxDB\ODM\Mapping\Annotations as InfluxDB;

/**
 * @InfluxDB\Measurement(name="cpu_load")
 */
class CpuLoad
{
    /**
     * @InfluxDB\Timestamp(precision="u")
     */
    private ?\DateTime $time = null;

    /**
     * @InfluxDB\Tag(name="server_id", type="integer")
     */
    private ?int $serverId = null;

    /**
     * @InfluxDB\Tag(name="core_number", type="integer")
     */
    private ?int $coreNumber = null;

    /**
     * @InfluxDB\Field(name="load", type="float")
     */
    private ?float $load = null;

    // ...getters and setters
}

namespace App\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;

class CpuLoadAdmin extends AbstractAdmin
{
    protected function generateBaseRouteName(bool $isChildAdmin = false): string
    {
        return 'cpu_load';
    }

    protected function generateBaseRoutePattern(bool $isChildAdmin = false): string
    {
        return 'cpu_load';
    }

    protected function configureListFields(ListMapper $list): void
    {
        // ...
    }

    protected function configureDatagridFilters(DatagridMapper $filter): void
    {
        // ...
    }

    protected function configureShowFields(ShowMapper $show): void
    {
        // ...
    }

    protected function configureFormFields(FormMapper $form): void
    {
        // ...
    }
}

namespace App\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface;

class CpuLoadAdmin extends AbstractAdmin
{
    protected function configureListFields(ListMapper $list): void
    {
        $list
            ->addIdentifier('time', FieldDescriptionInterface::TYPE_DATETIME, [
                'format' => 'Y-m-d H:i:s.u',
            ])
            ->add('serverId')
            ->add('load')
            ->add(ListMapper::NAME_ACTIONS, ListMapper::TYPE_ACTIONS, [
                'actions' => [
                    'show' => [],
                    'edit' => [],
                    'delete' => [],
                ],
            ]);
    }
}

namespace App\Admin;

use Javer\InfluxDB\AdminBundle\Filter\DateTimeRangeFilter;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;

class CpuLoadAdmin extends AbstractAdmin
{
    protected function configureDatagridFilters(DatagridMapper $filter): void
    {
        $filter
            ->add('time', DateTimeRangeFilter::class)
            ->add('serverId');
    }
}

namespace App\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;

class CpuLoadAdmin extends AbstractAdmin
{
    protected function configureFormFields(FormMapper $form): void
    {
        $form
            ->add('serverId')
            ->add('load');
    }
}

use Javer\InfluxDB\AdminBundle\Datagrid\ProxyQuery;

$query = $this->measurementManager->createQuery();

$proxyQuery = new ProxyQuery($query);
$proxyQuery->setSortBy('time');
$proxyQuery->setMaxResults(10);

$results = $proxyQuery->execute();
yaml
javer_influx_db_admin:
    templates:
        form:
            - '@SonataAdmin/Form/form_admin_fields.html.twig'
        filter:
            - '@SonataAdmin/Form/filter_admin_fields.html.twig'
        types:
            list:
                array:      "@SonataAdmin/CRUD/list_array.html.twig"
                boolean:    "@SonataAdmin/CRUD/list_boolean.html.twig"
                date:       "@SonataAdmin/CRUD/list_date.html.twig"
                time:       "@SonataAdmin/CRUD/list_time.html.twig"
                datetime:   "@SonataAdmin/CRUD/list_datetime.html.twig"
                text:       "@SonataAdmin/CRUD/base_list_field.html.twig"
                trans:      "@SonataAdmin/CRUD/list_trans.html.twig"
                string:     "@SonataAdmin/CRUD/base_list_field.html.twig"
                smallint:   "@SonataAdmin/CRUD/base_list_field.html.twig"
                bigint:     "@SonataAdmin/CRUD/base_list_field.html.twig"
                integer:    "@SonataAdmin/CRUD/base_list_field.html.twig"
                decimal:    "@SonataAdmin/CRUD/base_list_field.html.twig"
                identifier: "@SonataAdmin/CRUD/base_list_field.html.twig"
            show:
                array:      "@SonataAdmin/CRUD/show_array.html.twig"
                boolean:    "@SonataAdmin/CRUD/show_boolean.html.twig"
                date:       "@SonataAdmin/CRUD/show_date.html.twig"
                time:       "@SonataAdmin/CRUD/show_time.html.twig"
                datetime:   "@SonataAdmin/CRUD/show_datetime.html.twig"
                text:       "@SonataAdmin/CRUD/base_show_field.html.twig"
                trans:      "@SonataAdmin/CRUD/show_trans.html.twig"
                string:     "@SonataAdmin/CRUD/base_show_field.html.twig"
                smallint:   "@SonataAdmin/CRUD/base_show_field.html.twig"
                bigint:     "@SonataAdmin/CRUD/base_show_field.html.twig"
                integer:    "@SonataAdmin/CRUD/base_show_field.html.twig"
                decimal:    "@SonataAdmin/CRUD/base_show_field.html.twig"