Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
9.09% |
1 / 11 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| UsersList | |
9.09% |
1 / 11 |
|
50.00% |
1 / 2 |
5.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| pdfList | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Controller\Download; |
| 6 | |
| 7 | use App\Controller\BaseController; |
| 8 | use App\Repository\UserRepository; |
| 9 | use App\Service\PdfHelper; |
| 10 | use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse; |
| 11 | use Symfony\Component\Clock\ClockInterface; |
| 12 | use Symfony\Component\Routing\Attribute\Route; |
| 13 | use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 14 | |
| 15 | class UsersList extends BaseController |
| 16 | { |
| 17 | public function __construct( |
| 18 | private readonly UserRepository $userRepository, |
| 19 | private readonly PdfHelper $PdfHelper, |
| 20 | private readonly ClockInterface $clock, |
| 21 | ) {} |
| 22 | |
| 23 | #[IsGranted('ROLE_ADMIN')] |
| 24 | #[Route(path: '/download/users-list', name: 'download_users_list', methods: ['GET'])] |
| 25 | public function pdfList(): PdfResponse |
| 26 | { |
| 27 | $html = $this->renderView( |
| 28 | '_pdf/user-pdf-list.html.twig', |
| 29 | [ |
| 30 | 'users' => $this->userRepository->getSortedByStore(), |
| 31 | ] |
| 32 | ); |
| 33 | return new PdfResponse( |
| 34 | $this->PdfHelper->getOutputFromHtml($html), |
| 35 | sprintf('user-list-%s.pdf', $this->clock->now()->format('Y-m-d')) |
| 36 | ); |
| 37 | } |
| 38 | } |