Developed with love by KnpLabs Hire us for your project!
33

VelvelReportBundle

by Velvel

Online database report generator for Symfony2

VelvelReportBundle

The VelvelReportBundle adds support to create custom report pages for administrators about the database, also
lets the administrators write their own DQL and SQL queries to fetch data they need.

Installation

Add "velvel/report-bundle": "dev-master" to your composer.json

Register the bundle

<?php

// app/AppKernel.php

public function registerBundles {
    return array(
        // ...
        new Velvel\ReportBundle\VelvelReportBundle(),
        // ...
    );
}

Add the routing


# app/config/routing.yml

velvel_report:
    resource: "@VelvelReportBundle/Resources/config/routing.xml"
    prefix: /reports

Usage

Create a report file which extends the Velvel\ReportBuilder\Builder\BaseReportBuilder:

<?php

namespace Acme\DemoBundle\Report;

use Velvel\ReportBundle\Builder\BaseReportBuilder;
use Doctrine\ORM\QueryBuilder;

class OrdersReport extends BaseReportBuilder
{
    /**
     * Configures builder
     * 
     * This method configures the ReportBuilder. It has to return
     * a configured Doctrine QueryBuilder.
     *
     * @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder
     * 
     * @return \Doctrine\ORM\QueryBuilder
     */
    public function configureBuilder(QueryBuilder $queryBuilder)
    {
        $queryBuilder
            ->select('p.name, p.price, c.checkoutDate')
            ->from('Cart', 'c')
            ->join('c.items', 'i')
            ->join('i.product', 'p')
            ->add('where', 'c.checkoutDate > :from AND c.checkoutDate < :to');
        return $queryBuilder;
    }

    /**
     * Configures parameters
     *
     * This method configures parameters, which will be passed to
     * the QueryBuilder and the Form too, so the users (admins) can
     * change them.
     *
     * @return array
     */
    public function configureParameters()
    {
        $parameters = array(
            'from' => array(
                'value'   => new \DateTime('yesterday'), // default value
                'type'    => 'date', // form type
                'options' => array('label' => 'From'), // form options
            ),
            'to'   => array(
                'value'   => new \DateTime('now'),
                'type'    => 'date',
                'options' => array('label' => 'To'),
            ),
        );
        return $parameters;
    }

    /**
     * Configures modifiers
     *
     * If an element in the select statement returns an object without
     * a __toString() method implemented, it needs a modifier to be set.
     *
     * @return array
     */
    public function configureModifiers()
    {
        $modifiers = array(
            'checkoutDate' => array(
                'method' => 'format', // method to be called on the object
                'params' => array('Y/m/d H:i:s'), // method parameters in an array
            ),
        );

        return $modifiers;
    }
}

Add your new ReportBuilder to your config.yml:

velvel_report:
    reports:
        - { id: 'orders', name: 'Orders', class: 'Acme\DemoBundle\Report\OrdersReport' }

The id must be unique, it will be used in the routing. The name will be rendered in the reports list and the class is your report class.

Configuration

You can override the show and list templates.

velvel_report:
    templates:
        show: 'VelvelReportBundle::show.html.twig' # this is the default show template
        list: 'VelvelReportBundle::list.html.twig' # this is the default list template
velvel_report:
reports:

# Prototype
id:
name: ~
class: ~
templates:
show: VelvelReportBundle::show.html.twig
list: VelvelReportBundle::list.html.twig
  • Injecting SecurityContext into BaseReportBuilder
    By LordBaine2000, 7 years ago
  • Merge pull request #2 from mpoplin/master
    By , 7 years ago
  • Fixed issue with adding validation constraints to form builder.
    By Michael Poplin, 7 years ago
  • Screwing with requirements.
    By Michael Poplin, 8 years ago
  • Screwing with requirements.
    By Michael Poplin, 8 years ago
  • [Controller] Secured modifier handling - if the modifier has no value, it is skipped
    By attilabukor, 8 years ago
  • Updated dependencies
    By attilabukor, 8 years ago
  • [Doc] added routing config to documentation
    By attilabukor, 8 years ago
  • [Controller] added current report to templating
    By attilabukor, 8 years ago
  • added documentation
    By attilabukor, 8 years ago
  • [DIC]added support for template overriding
    By attilabukor, 8 years ago
  • [Generator][Builder][Controller] added controller, fixed generator and builder
    By attilabukor, 8 years ago
  • [DIC][Generator] added generator, added config parser to DIC
    By attilabukor, 8 years ago
  • [DIC] added FormBuilder to DIC
    By attilabukor, 8 years ago
  • [Form] fixed construct params, added support for validation
    By attilabukor, 8 years ago
  • [Form] added FormBuilder
    By attilabukor, 8 years ago
  • [ReportBuilder] added interface, base abstract class and InvalidReportQueryException
    By attilabukor, 8 years ago
  • fixed composer
    By attilabukor, 8 years ago
  • added bundle file
    By attilabukor, 8 years ago
  • added composer
    By attilabukor, 8 years ago
  • changed README
    By attilabukor, 8 years ago
  • added IDEs to gitignore
    By attilabukor, 8 years ago
  • added LGPL license
    By attilabukor, 8 years ago
  • initial commit
    By tamasfarkas, 8 years ago