Giter VIP home page Giter VIP logo

velvelreportbundle's Introduction

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

velvelreportbundle's People

Contributors

attilabukor avatar tamasfarkas avatar

Stargazers

Navid Nikpour avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.