velvel / report-bundle
Online database report generator for Symfony2
Installs: 582
Dependents: 0
Suggesters: 0
Security: 0
Stars: 17
Watchers: 4
Forks: 11
Open Issues: 5
Type:symfony-bundle
Requires
- php: >=5.3.3
- doctrine/orm: >=2.2.0
- symfony/framework-bundle: >=2.1.0
- twig/twig: dev-master
This package is not auto-updated.
Last update: 2024-11-23 14:40:55 UTC
README
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