Skip to content

Commit

Permalink
update for json data source
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Oct 13, 2016
1 parent fbb709c commit 21ce9be
Show file tree
Hide file tree
Showing 298 changed files with 5,362 additions and 3,099 deletions.
Empty file modified CONTRIBUTING.md
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
52 changes: 50 additions & 2 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Route::get('/reports', function () {
In this example we generate reports pdf, rtf and xml.


###Additional Information - Reports from a xml in Laravel 5.*
###Additional Information - Reports from a xml in PHP/Laravel 5.*

See how easy it is to generate a report with a source an xml file:

Expand Down Expand Up @@ -308,6 +308,54 @@ to folder:
**\public\report**


###Reports from a JSON File in PHP/Laravel 5.*

See how easy it is to generate a report with a source an json file:

```php

use JasperPHP\JasperPHP;

public function jsonToPdf()
{
$output = public_path() . '/report/'.time().'_Contacts';
$ext = "pdf";
$driver = 'json';
$json_query= "contacts.person";
$data_file = public_path() . '/report/contacts.json';

\JasperPHP::process(
public_path() . '/report/json.jrxml',
$output,
array($ext),
array(),
array('data_file' => $data_file, 'driver' => $driver, 'json_query' => $json_query
)->execute();

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.time().'_Contacts.'.$ext);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Length: ' . filesize($output.'.'.$ext));
flush();
readfile($output.'.'.$ext);
unlink($output.'.'.$ext);

}
```
**Note:**

To use the example above you must copy the sample files located at:

**\vendor\lavela\phpjasper\src\JasperStarter\examples\json.jrxml**
and
**\vendor\lavela\phpjasper\src\JasperStarter\examples\contacts.json**
to folder:
**\public\report**


###MySQL

We ship the [MySQL connector](http://dev.mysql.com/downloads/connector/j/) (v5.1.39) in the `/src/JasperStarter/jdbc/` directory.
Expand Down Expand Up @@ -336,4 +384,4 @@ MIT

##Contribute

Contribute to the community PHP and Laravel, feel free to contribute, make a fork!!
Contribute to the community PHP and Laravel, feel free to contribute, make a fork!!
3 changes: 2 additions & 1 deletion composer.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"pdf",
"xml",
"PHP",
"java"
"java",
"json"
],
"homepage": "https://github.com/lavela/phpjasper",
"authors": [
Expand Down
Empty file modified examples/.gitignore
100644 → 100755
Empty file.
24 changes: 24 additions & 0 deletions examples/contacts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"contacts": {
"person": [
{
"name": "ETHAN",
"street": "Street 1",
"city": "Fairfax",
"phone": "+1 (415) 111-1111"
},
{
"name": "CALEB",
"street": "Street 2",
"city": "San Francisco",
"phone": "+1 (415) 222-2222"
},
{
"name": "WILLIAM",
"street": "Street 2",
"city": "Paradise City",
"phone": "+1 (415) 333-3333"
}
]
}
}
Empty file modified examples/hello_world.jrxml
100644 → 100755
Empty file.
Empty file modified examples/hello_world_params.jrxml
100644 → 100755
Empty file.
129 changes: 129 additions & 0 deletions examples/json.jrxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 -->
<!-- 2015-06-08T13:56:57 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="json" language="groovy" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="8334f12e-a866-41de-8672-61a43ba44bab">
<property name="ireport.zoom" value="1.5"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JsonAdapter"/>
<queryString language="json">
<![CDATA[contacts.person]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="street" class="java.lang.String">
<fieldDescription><![CDATA[street]]></fieldDescription>
</field>
<field name="city" class="java.lang.String">
<fieldDescription><![CDATA[city]]></fieldDescription>
</field>
<field name="phone" class="java.lang.String">
<fieldDescription><![CDATA[phone]]></fieldDescription>
</field>
<background>
<band/>
</background>
<title>
<band height="72">
<frame>
<reportElement mode="Opaque" x="-20" y="-20" width="595" height="92" backcolor="#006699" uuid="d6b7d5aa-5c6b-4106-9569-b0014b63e753"/>
<staticText>
<reportElement x="20" y="20" width="267" height="43" forecolor="#FFFFFF" uuid="2932e85f-a2d7-40d5-9dad-0b5ea669ad15"/>
<textElement>
<font size="34" isBold="true"/>
</textElement>
<text><![CDATA[JasperStarter]]></text>
</staticText>
<staticText>
<reportElement x="298" y="43" width="277" height="20" forecolor="#FFFFFF" uuid="04e1a0ed-0b0f-41d4-93e9-792d4fd37d28"/>
<textElement textAlignment="Right">
<font size="14" isBold="false"/>
</textElement>
<text><![CDATA[Report with JSON Datasource]]></text>
</staticText>
</frame>
</band>
</title>
<pageHeader>
<band height="13"/>
</pageHeader>
<columnHeader>
<band height="30">
<line>
<reportElement x="-20" y="21" width="595" height="1" forecolor="#666666" uuid="94019af3-607f-4b88-8274-5967c629b025"/>
</line>
<staticText>
<reportElement x="320" y="0" width="133" height="20" uuid="22f4dad5-dda1-4d8d-ba31-7122e51b0905"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[City]]></text>
</staticText>
<staticText>
<reportElement x="3" y="0" width="97" height="20" uuid="eaac8896-667b-4a63-adae-592cef191d8b"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="100" y="0" width="200" height="20" uuid="38ad2a59-8306-4869-af2d-619322df6d74"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Street]]></text>
</staticText>
<staticText>
<reportElement x="450" y="0" width="140" height="20" uuid="4fb0818d-4c85-4afb-b62c-4554822ea2b3"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Phone]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="24">
<textField>
<reportElement x="320" y="0" width="133" height="20" uuid="70a0f25d-aa46-4a62-8a96-e0d7955ebe5e"/>
<textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="3" y="0" width="97" height="20" uuid="ec4a8c9a-a5a6-49d8-945b-ef39b5a78e9c"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="200" height="20" uuid="8b120a86-15bc-453e-a672-b22d2178ce31"/>
<textFieldExpression><![CDATA[$F{street}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="450" y="0" width="140" height="20" uuid="37e3ac7f-7abf-4415-9014-98a4eab36f59"/>
<textFieldExpression><![CDATA[$F{phone}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band height="17">
<textField>
<reportElement mode="Opaque" x="0" y="4" width="515" height="13" backcolor="#E6E6E6" uuid="9d494e45-7fa2-4a24-9861-eee79cced51a"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement mode="Opaque" x="515" y="4" width="40" height="13" backcolor="#E6E6E6" uuid="63ea56af-97fd-481f-8faa-e2bcd65f6c15"/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="0" y="4" width="100" height="13" uuid="1822668b-e69e-4104-ba0b-0af0db204142"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band/>
</summary>
</jasperReport>
Empty file modified phpunit.xml.dist
100644 → 100755
Empty file.
Empty file modified src/JasperPHP/Facades/JasperPHP.php
100644 → 100755
Empty file.
Loading

0 comments on commit 21ce9be

Please sign in to comment.