1. Go to this page and download the library: Download mesd/jasper-report-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/ */
mesd / jasper-report-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Mesd\Jasper\ReportBundle\MesdJasperReportBundle()
)
}
namespace My\Bundle\Somewhere;
use Mesd\Jasper\ReportBundle\Interfaces\AbstractOptionsHandler;
use Mesd\Jasper\ReportBundle\InputControl\Option;
class MyOptionsHandler extends AbstractOptionsHandler
{
public function registerFunctions() {
return array(
'someInputControlId' => 'foo'
);
}
public function foo() {
return array(
new Option('1', 'I want door number 1'),
new Option('2', 'I really want door number 2'),
new Option('3', 'Just give me what ever is behind door number 3')
);
}
}
//Get a list of resources in the default directory
$resources = $this->container->get('mesd.jasper.report.client')->getResourceList();
//Get a list of resources from a particular directory
$resources = $this->container->get('mesd.jasper.report.client')->getResourceList('reports/super-secret-reports/');
//Get all the resources below a particular directory (note that this can be a slow process)
$resources = $this->container->get('mesd.jasper.report.client')->getResourceList('reports/', true);
//Display the report form
public function formAction()
{
$form = $this->container->get('mesd.jasper.report.client')
->buildReportInputForm(
'report/sales/quarterly_report',
'route_to_next_action',
array('routeParameters' => array('key' => 'value')
)
);
//Display and such
...
}
//Run the report and get the output
public function processAction(Request $request, $key) {
//Note that key will be 'value' here (just in case you need something like this)
//Rebuild the form
$form = $this->container->get('mesd.jasper.report.client')->buildReportInputForm('report/sales/quarterly_report');
//Handle the request
$form->handleRequest($request);
//Check if the form is valid
if ($form->isValid()) {
//Create the report builder
$rb = $this->container->get('mesd.jasper.report.client')->createReportBuilder('report/sales/quarterly_report');
$rb->setInputParametersArray($form->getData());
//Run the report and get the request id (NOTE: this instance of the report will now be saved to the report store and a record will be saved to the db)
$requestId = $rb->runReport();
}
}
//Get page 1 of the report
//Call the loader service to setup the client library's report loader
$reportLoader = $this->container->get('mesd.jasper.report.loader')->getReportLoader();
$report = $reportLoader->getCachedReport($requestId, 'html', array('page' => 1));
//Display
$report->getOutput();
namespace My\Bundle\Somewhere;
use Mesd\Jasper\ReportBundle\Interfaces\AbstractOptionsHandler;
use Mesd\Jasper\ReportBundle\InputControl\Option;
class MyOptionsHandler extends AbstractOptionsHandler
{
//The Symfony SecurityContext object
private $securityContext;
//Override the constructor to allow the injection of the security context
public function __construct($securityContext) {
$this->securityContext = $securityContext;
//Call the parent constructor (this is important)
parent::__construct();
}
//Register the functions
protected function registerFunctions(){
return array(
'Deptmartment' => 'getOptionsForDept'
);
}
//Get the options for the department selector
public function getOptionsForDept() {
$options = array();
foreach($this->securityContext->getUser()->getDepartments() as $dept) {
$options[] = new Option($dept->getId(), $dept->getName());
}
return $options;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.