-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
228 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusGiftCardPlugin\Controller\Action; | ||
|
||
use Setono\SyliusGiftCardPlugin\Factory\GiftCardFactoryInterface; | ||
use Setono\SyliusGiftCardPlugin\Form\Type\GiftCardConfigurationType; | ||
use Setono\SyliusGiftCardPlugin\Generator\GiftCardPdfGeneratorInterface; | ||
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class AdminGeneratePdfAction | ||
{ | ||
private GiftCardFactoryInterface $giftCardFactory; | ||
|
||
private RepositoryInterface $giftCardConfigurationRepository; | ||
|
||
private GiftCardPdfGeneratorInterface $pdfGenerator; | ||
|
||
private FormFactoryInterface $formFactory; | ||
|
||
public function __construct( | ||
GiftCardFactoryInterface $giftCardFactory, | ||
RepositoryInterface $giftCardConfigurationRepository, | ||
GiftCardPdfGeneratorInterface $pdfGenerator, | ||
FormFactoryInterface $formFactory | ||
) { | ||
$this->giftCardFactory = $giftCardFactory; | ||
$this->giftCardConfigurationRepository = $giftCardConfigurationRepository; | ||
$this->pdfGenerator = $pdfGenerator; | ||
$this->formFactory = $formFactory; | ||
} | ||
|
||
public function __invoke(Request $request, int $id): Response | ||
{ | ||
$giftCard = $this->giftCardFactory->createDummy(); | ||
/** @var GiftCardConfigurationInterface|null $giftCardConfiguration */ | ||
$giftCardConfiguration = $this->giftCardConfigurationRepository->find($id); | ||
|
||
$form = $this->formFactory->create(GiftCardConfigurationType::class, $giftCardConfiguration); | ||
$form->handleRequest($request); | ||
|
||
$this->pdfGenerator->generateAndSavePdf($giftCard, $giftCardConfiguration); | ||
|
||
return new Response(null, Response::HTTP_NO_CONTENT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusGiftCardPlugin\Controller\Action; | ||
|
||
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse; | ||
use Knp\Snappy\GeneratorInterface; | ||
use Symfony\Component\HttpFoundation\HeaderUtils; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class AdminRenderPdfAction | ||
{ | ||
private GeneratorInterface $snappy; | ||
|
||
private string $publicDir; | ||
|
||
public function __construct( | ||
GeneratorInterface $snappy, | ||
string $publicDir | ||
) { | ||
$this->snappy = $snappy; | ||
$this->publicDir = $publicDir; | ||
} | ||
|
||
public function __invoke(Request $request, int $id): PdfResponse | ||
{ | ||
$filePath = \sprintf( | ||
'%s/gift_card_configuration_pdf_%d.pdf', | ||
$this->publicDir, | ||
$id | ||
); | ||
$response = new PdfResponse(\file_get_contents($filePath), 'gift_card.pdf'); | ||
|
||
$response->headers->add([ | ||
'Content-Disposition' => $response->headers->makeDisposition(HeaderUtils::DISPOSITION_INLINE, 'gift_card.pdf') | ||
]); | ||
$response->setPublic(); | ||
$response->setMaxAge(0); | ||
$response->headers->addCacheControlDirective('must-revalidate', true); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
setono_sylius_gift_card_admin_partial_render_pdf: | ||
path: /gift-card-configurations/{id}/render-pdf | ||
controller: setono_sylius_gift_card.controller.action.admin_render | ||
methods: [GET, POST, PUT] | ||
requirements: | ||
id: \d+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Resources/public/setono-sylius-gift-card-live-pdf-rendering.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(function ($) { | ||
'use strict'; | ||
|
||
$.fn.extend({ | ||
applyPdfChanges: function () { | ||
const $element = $(this); | ||
const url = $element.data('url'); | ||
|
||
$element.on('click', function (event) { | ||
event.preventDefault(); | ||
|
||
$.ajax(url, { | ||
method: 'POST', | ||
data: $('form[name="setono_sylius_gift_card_gift_card_configuration"]').serialize(), | ||
success() { | ||
const src = document.getElementById('js-ssgc-live-render-box').src; | ||
$('.js-ssgc-live-render-container').html(`<embed id="js-ssgc-live-render-box" src="${src}" style="width: 100%;height: 100%;"/>`); | ||
}, | ||
}); | ||
}); | ||
}, | ||
}); | ||
})(jQuery); |
6 changes: 6 additions & 0 deletions
6
src/Resources/views/Admin/GiftCardConfiguration/Update/_javascripts.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<script src="{{ asset('bundles/setonosyliusgiftcardplugin/setono-sylius-gift-card-live-pdf-rendering.js') }}"></script> | ||
<script> | ||
$().ready(() => { | ||
$('.js-ssgc-apply-pdf-changes').applyPdfChanges(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters