added inline disposition for PDF previews (#3486)
This commit is contained in:
18
src/Export/Base/DispositionInlineInterface.php
Normal file
18
src/Export/Base/DispositionInlineInterface.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Export\Base;
|
||||
|
||||
/**
|
||||
* @deprecated remove me in 2.0
|
||||
*/
|
||||
interface DispositionInlineInterface
|
||||
{
|
||||
public function setDispositionInline(bool $useInlineDisposition): void;
|
||||
}
|
||||
34
src/Export/Base/DispositionInlineTrait.php
Normal file
34
src/Export/Base/DispositionInlineTrait.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Export\Base;
|
||||
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
trait DispositionInlineTrait
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT;
|
||||
|
||||
public function getDisposition(): string
|
||||
{
|
||||
return $this->disposition;
|
||||
}
|
||||
|
||||
public function setDispositionInline(bool $useInlineDisposition): void
|
||||
{
|
||||
if ($useInlineDisposition) {
|
||||
$this->disposition = ResponseHeaderBag::DISPOSITION_INLINE;
|
||||
} else {
|
||||
$this->disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,12 @@ use App\Repository\Query\TimesheetQuery;
|
||||
use App\Utils\FileHelper;
|
||||
use App\Utils\HtmlToPdfConverter;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Twig\Environment;
|
||||
|
||||
class PDFRenderer
|
||||
class PDFRenderer implements DispositionInlineInterface
|
||||
{
|
||||
use RendererTrait;
|
||||
use DispositionInlineTrait;
|
||||
|
||||
/**
|
||||
* @var Environment
|
||||
@@ -125,7 +125,7 @@ class PDFRenderer
|
||||
|
||||
$filename = FileHelper::convertToAsciiFilename($filename);
|
||||
|
||||
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename . '.pdf');
|
||||
$disposition = $response->headers->makeDisposition($this->getDisposition(), $filename . '.pdf');
|
||||
|
||||
$response->headers->set('Content-Type', 'application/pdf');
|
||||
$response->headers->set('Content-Disposition', $disposition);
|
||||
|
||||
Reference in New Issue
Block a user