Adicionando novas funções inline e download

laravel-11
jtfnetoo 3 years ago
parent e961e19025
commit bf76c500c0

@ -0,0 +1,20 @@
<?php
namespace Ae3\JasperServer\Laravel\Integrator\app\Enums;
class ContentDispositionEnum
{
const INLINE = "inline";
const ATTACHMENT = "attachment";
/**
* @return array
*/
public static function all(): array
{
return [
self::INLINE,
self::ATTACHMENT
];
}
}

@ -73,10 +73,25 @@ interface JasperServerRequestServiceContract
*/ */
public function setContentDisposition(string $contentDisposition): JasperServerRequestService; public function setContentDisposition(string $contentDisposition): JasperServerRequestService;
/**
* @return string
*/
public function getReport(): string;
/** /**
* @param string $uri * @param string $uri
* @return $this
*/
public function call(string $uri): JasperServerRequestService;
/**
* @return string
*/
public function inline(): string;
/**
* @param string|null $filename * @param string|null $filename
* @return string * @return string
*/ */
public function call(string $uri, ?string $filename = null): string; public function download(?string $filename): string;
} }

@ -2,6 +2,7 @@
namespace Ae3\JasperServer\Laravel\Integrator\app\Services; namespace Ae3\JasperServer\Laravel\Integrator\app\Services;
use Ae3\JasperServer\Laravel\Integrator\app\Enums\ContentDispositionEnum;
use Ae3\JasperServer\Laravel\Integrator\app\Enums\ReportFormatEnum; use Ae3\JasperServer\Laravel\Integrator\app\Enums\ReportFormatEnum;
use Ae3\JasperServer\Laravel\Integrator\app\Services\Contracts\JasperServerRequestServiceContract; use Ae3\JasperServer\Laravel\Integrator\app\Services\Contracts\JasperServerRequestServiceContract;
use Jaspersoft\Client\Client; use Jaspersoft\Client\Client;
@ -66,7 +67,12 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
/** /**
* @var string * @var string
*/ */
protected $contentDisposition = 'inline'; protected $contentDisposition;
/**
* @var string
*/
protected $report;
/** /**
* @param Client $client * @param Client $client
@ -75,7 +81,8 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
Client $client Client $client
) { ) {
$this->client = $client; $this->client = $client;
$this->format = ReportFormatEnum::HTML; $this->setFormat(ReportFormatEnum::HTML);
$this->setContentDisposition(ContentDispositionEnum::INLINE);
} }
/** /**
@ -193,13 +200,20 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
} }
/** /**
* @param string $uri
* @param string|null $filename
* @return string * @return string
*/ */
public function call(string $uri, ?string $filename = null): string public function getReport(): string
{
return $this->report;
}
/**
* @param string $uri
* @return $this
*/
public function call(string $uri): self
{ {
$report = $this->client->reportService()->runReport( $this->report = $this->client->reportService()->runReport(
$uri, $uri,
$this->format, $this->format,
$this->pages, $this->pages,
@ -212,11 +226,30 @@ class JasperServerRequestService implements JasperServerRequestServiceContract
$this->transformerKey $this->transformerKey
); );
return $this;
}
/**
* @return string
*/
public function inline(): string
{
$this->setContentDisposition(ContentDispositionEnum::INLINE);
return $this->getReport();
}
/**
* @param string|null $filename
* @return string
*/
public function download(?string $filename): string
{
if (in_array($this->format, ReportFormatEnum::downloadable())) { if (in_array($this->format, ReportFormatEnum::downloadable())) {
$this->setHeader($report, $filename); $this->setContentDisposition(ContentDispositionEnum::ATTACHMENT);
$this->setHeader($this->report, $filename);
} }
return $report; return $this->getReport();
} }
/** /**

Loading…
Cancel
Save