Skip to content

Commit 21ce9be

Browse files
author
root
committed
update for json data source
1 parent fbb709c commit 21ce9be

File tree

298 files changed

+5362
-3099
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

298 files changed

+5362
-3099
lines changed

CONTRIBUTING.md

100644100755
File mode changed.

LICENSE

100644100755
File mode changed.

README.md

100644100755
+50-2
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ Route::get('/reports', function () {
257257
In this example we generate reports pdf, rtf and xml.
258258

259259

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

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

@@ -308,6 +308,54 @@ to folder:
308308
**\public\report**
309309

310310

311+
###Reports from a JSON File in PHP/Laravel 5.*
312+
313+
See how easy it is to generate a report with a source an json file:
314+
315+
```php
316+
317+
use JasperPHP\JasperPHP;
318+
319+
public function jsonToPdf()
320+
{
321+
$output = public_path() . '/report/'.time().'_Contacts';
322+
$ext = "pdf";
323+
$driver = 'json';
324+
$json_query= "contacts.person";
325+
$data_file = public_path() . '/report/contacts.json';
326+
327+
\JasperPHP::process(
328+
public_path() . '/report/json.jrxml',
329+
$output,
330+
array($ext),
331+
array(),
332+
array('data_file' => $data_file, 'driver' => $driver, 'json_query' => $json_query
333+
)->execute();
334+
335+
header('Content-Description: File Transfer');
336+
header('Content-Type: application/octet-stream');
337+
header('Content-Disposition: attachment; filename='.time().'_Contacts.'.$ext);
338+
header('Content-Transfer-Encoding: binary');
339+
header('Expires: 0');
340+
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
341+
header('Content-Length: ' . filesize($output.'.'.$ext));
342+
flush();
343+
readfile($output.'.'.$ext);
344+
unlink($output.'.'.$ext);
345+
346+
}
347+
```
348+
**Note:**
349+
350+
To use the example above you must copy the sample files located at:
351+
352+
**\vendor\lavela\phpjasper\src\JasperStarter\examples\json.jrxml**
353+
and
354+
**\vendor\lavela\phpjasper\src\JasperStarter\examples\contacts.json**
355+
to folder:
356+
**\public\report**
357+
358+
311359
###MySQL
312360

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

337385
##Contribute
338386

339-
Contribute to the community PHP and Laravel, feel free to contribute, make a fork!!
387+
Contribute to the community PHP and Laravel, feel free to contribute, make a fork!!

composer.json

100644100755
+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"pdf",
1010
"xml",
1111
"PHP",
12-
"java"
12+
"java",
13+
"json"
1314
],
1415
"homepage": "https://github.com/lavela/phpjasper",
1516
"authors": [

examples/.gitignore

100644100755
File mode changed.

examples/contacts.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"contacts": {
3+
"person": [
4+
{
5+
"name": "ETHAN",
6+
"street": "Street 1",
7+
"city": "Fairfax",
8+
"phone": "+1 (415) 111-1111"
9+
},
10+
{
11+
"name": "CALEB",
12+
"street": "Street 2",
13+
"city": "San Francisco",
14+
"phone": "+1 (415) 222-2222"
15+
},
16+
{
17+
"name": "WILLIAM",
18+
"street": "Street 2",
19+
"city": "Paradise City",
20+
"phone": "+1 (415) 333-3333"
21+
}
22+
]
23+
}
24+
}

examples/hello_world.jrxml

100644100755
File mode changed.

examples/hello_world_params.jrxml

100644100755
File mode changed.

examples/json.jrxml

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 -->
3+
<!-- 2015-06-08T13:56:57 -->
4+
<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">
5+
<property name="ireport.zoom" value="1.5"/>
6+
<property name="ireport.x" value="0"/>
7+
<property name="ireport.y" value="0"/>
8+
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JsonAdapter"/>
9+
<queryString language="json">
10+
<![CDATA[contacts.person]]>
11+
</queryString>
12+
<field name="name" class="java.lang.String">
13+
<fieldDescription><![CDATA[name]]></fieldDescription>
14+
</field>
15+
<field name="street" class="java.lang.String">
16+
<fieldDescription><![CDATA[street]]></fieldDescription>
17+
</field>
18+
<field name="city" class="java.lang.String">
19+
<fieldDescription><![CDATA[city]]></fieldDescription>
20+
</field>
21+
<field name="phone" class="java.lang.String">
22+
<fieldDescription><![CDATA[phone]]></fieldDescription>
23+
</field>
24+
<background>
25+
<band/>
26+
</background>
27+
<title>
28+
<band height="72">
29+
<frame>
30+
<reportElement mode="Opaque" x="-20" y="-20" width="595" height="92" backcolor="#006699" uuid="d6b7d5aa-5c6b-4106-9569-b0014b63e753"/>
31+
<staticText>
32+
<reportElement x="20" y="20" width="267" height="43" forecolor="#FFFFFF" uuid="2932e85f-a2d7-40d5-9dad-0b5ea669ad15"/>
33+
<textElement>
34+
<font size="34" isBold="true"/>
35+
</textElement>
36+
<text><![CDATA[JasperStarter]]></text>
37+
</staticText>
38+
<staticText>
39+
<reportElement x="298" y="43" width="277" height="20" forecolor="#FFFFFF" uuid="04e1a0ed-0b0f-41d4-93e9-792d4fd37d28"/>
40+
<textElement textAlignment="Right">
41+
<font size="14" isBold="false"/>
42+
</textElement>
43+
<text><![CDATA[Report with JSON Datasource]]></text>
44+
</staticText>
45+
</frame>
46+
</band>
47+
</title>
48+
<pageHeader>
49+
<band height="13"/>
50+
</pageHeader>
51+
<columnHeader>
52+
<band height="30">
53+
<line>
54+
<reportElement x="-20" y="21" width="595" height="1" forecolor="#666666" uuid="94019af3-607f-4b88-8274-5967c629b025"/>
55+
</line>
56+
<staticText>
57+
<reportElement x="320" y="0" width="133" height="20" uuid="22f4dad5-dda1-4d8d-ba31-7122e51b0905"/>
58+
<textElement>
59+
<font isBold="true"/>
60+
</textElement>
61+
<text><![CDATA[City]]></text>
62+
</staticText>
63+
<staticText>
64+
<reportElement x="3" y="0" width="97" height="20" uuid="eaac8896-667b-4a63-adae-592cef191d8b"/>
65+
<textElement>
66+
<font isBold="true"/>
67+
</textElement>
68+
<text><![CDATA[Name]]></text>
69+
</staticText>
70+
<staticText>
71+
<reportElement x="100" y="0" width="200" height="20" uuid="38ad2a59-8306-4869-af2d-619322df6d74"/>
72+
<textElement>
73+
<font isBold="true"/>
74+
</textElement>
75+
<text><![CDATA[Street]]></text>
76+
</staticText>
77+
<staticText>
78+
<reportElement x="450" y="0" width="140" height="20" uuid="4fb0818d-4c85-4afb-b62c-4554822ea2b3"/>
79+
<textElement>
80+
<font isBold="true"/>
81+
</textElement>
82+
<text><![CDATA[Phone]]></text>
83+
</staticText>
84+
</band>
85+
</columnHeader>
86+
<detail>
87+
<band height="24">
88+
<textField>
89+
<reportElement x="320" y="0" width="133" height="20" uuid="70a0f25d-aa46-4a62-8a96-e0d7955ebe5e"/>
90+
<textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
91+
</textField>
92+
<textField>
93+
<reportElement x="3" y="0" width="97" height="20" uuid="ec4a8c9a-a5a6-49d8-945b-ef39b5a78e9c"/>
94+
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
95+
</textField>
96+
<textField>
97+
<reportElement x="100" y="0" width="200" height="20" uuid="8b120a86-15bc-453e-a672-b22d2178ce31"/>
98+
<textFieldExpression><![CDATA[$F{street}]]></textFieldExpression>
99+
</textField>
100+
<textField>
101+
<reportElement x="450" y="0" width="140" height="20" uuid="37e3ac7f-7abf-4415-9014-98a4eab36f59"/>
102+
<textFieldExpression><![CDATA[$F{phone}]]></textFieldExpression>
103+
</textField>
104+
</band>
105+
</detail>
106+
<columnFooter>
107+
<band/>
108+
</columnFooter>
109+
<pageFooter>
110+
<band height="17">
111+
<textField>
112+
<reportElement mode="Opaque" x="0" y="4" width="515" height="13" backcolor="#E6E6E6" uuid="9d494e45-7fa2-4a24-9861-eee79cced51a"/>
113+
<textElement textAlignment="Right"/>
114+
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
115+
</textField>
116+
<textField evaluationTime="Report">
117+
<reportElement mode="Opaque" x="515" y="4" width="40" height="13" backcolor="#E6E6E6" uuid="63ea56af-97fd-481f-8faa-e2bcd65f6c15"/>
118+
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
119+
</textField>
120+
<textField pattern="EEEEE dd MMMMM yyyy">
121+
<reportElement x="0" y="4" width="100" height="13" uuid="1822668b-e69e-4104-ba0b-0af0db204142"/>
122+
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
123+
</textField>
124+
</band>
125+
</pageFooter>
126+
<summary>
127+
<band/>
128+
</summary>
129+
</jasperReport>

phpunit.xml.dist

100644100755
File mode changed.

src/JasperPHP/Facades/JasperPHP.php

100644100755
File mode changed.

0 commit comments

Comments
 (0)