Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Added locale support and fixed formatting #77

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "cossou/jasperphp",
"name": "fazo96/jasperphp",
"description": "Create Reports in PHP with JasperReports",
"license": "MIT",
"keywords": [
Expand All @@ -10,11 +10,15 @@
"pdf",
"java"
],
"homepage": "https://github.com/cossou/JasperPHP",
"homepage": "https://github.com/fazo96/JasperPHP",
"authors": [
{
"name": "Hélder Duarte",
"email": "[email protected]"
},
{
"name": "Enrico Fasoli",
"email": "[email protected]"
}
],
"autoload": {
Expand Down
19 changes: 11 additions & 8 deletions src/JasperPHP/JasperPHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JasperPHP
function __construct($resource_dir = false)
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
$this->windows = true;
$this->windows = true;

if (!$resource_dir) {
$this->resource_directory = __DIR__ . "/../../../../../";
Expand Down Expand Up @@ -56,7 +56,7 @@ public function compile($input_file, $output_file = false, $background = true, $
return $this;
}

public function process($input_file, $output_file = false, $format = array("pdf"), $parameters = array(), $db_connection = array(), $background = true, $redirect_output = true)
public function process($input_file, $output_file = false, $format = array("pdf"), $parameters = array(), $db_connection = array(), $locale = false, $resourceDir = false, $background = true, $redirect_output = true)
{
if(is_null($input_file) || empty($input_file))
throw new \Exception("No input file", 1);
Expand All @@ -70,11 +70,13 @@ public function process($input_file, $output_file = false, $format = array("pdf"
}
} else {
if( !in_array($format, $this->formats))
throw new \Exception("Invalid format!", 1);
throw new \Exception("Invalid format!", 1);
}

$command = __DIR__ . $this->executable;

if(!empty($locale)) $command .= ' --locale ' . $locale . ' ';

$command .= " process ";

$command .= $input_file;
Expand All @@ -88,7 +90,8 @@ public function process($input_file, $output_file = false, $format = array("pdf"
$command .= " -f " . $format;

// Resources dir
$command .= " -r " . $this->resource_directory;
if (empty($resourceDir)) $resourceDir = $this->resource_directory;
$command .= " -r " . $resourceDir;

if( count($parameters) > 0 )
{
Expand Down Expand Up @@ -122,7 +125,7 @@ public function process($input_file, $output_file = false, $format = array("pdf"
if( isset($db_connection['jdbc_url']) && !empty($db_connection['jdbc_url']) )
$command .= " --db-url " . $db_connection['jdbc_url'];

if ( isset($db_connection['jdbc_dir']) && !empty($db_connection['jdbc_dir']) )
if ( isset($db_connection['jdbc_dir']) && !empty($db_connection['jdbc_dir']) )
$command .= ' --jdbc-dir ' . $db_connection['jdbc_dir'];

if ( isset($db_connection['db_sid']) && !empty($db_connection['db_sid']) )
Expand Down Expand Up @@ -176,10 +179,10 @@ public function execute($run_as_user = false)

if( $return_var != 0 && isset($output[0]) )
throw new \Exception($output[0], 1);
elseif( $return_var != 0 )

elseif( $return_var != 0 )
throw new \Exception("Your report has an error and couldn't be processed! Try to output the command using the function `output();` and run it manually in the console.", 1);

return $output;
}
}