Feature: [saved export] First list of saved exports

This commit is contained in:
2022-11-08 16:57:49 +01:00
parent ccb2cd0295
commit aec4c52567
5 changed files with 262 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Controller;
use Chill\MainBundle\Entity\SavedExport;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\MainBundle\Repository\SavedExportRepositoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class SavedExportController
{
private ExportManager $exportManager;
private SavedExportRepositoryInterface $savedExportRepository;
private Security $security;
private EngineInterface $templating;
private TranslatorInterface $translator;
public function __construct(
EngineInterface $templating,
ExportManager $exportManager,
SavedExportRepositoryInterface $savedExportRepository,
Security $security,
TranslatorInterface $translator
) {
$this->exportManager = $exportManager;
$this->savedExportRepository = $savedExportRepository;
$this->security = $security;
$this->templating = $templating;
$this->translator = $translator;
}
/**
* @Route("/{_locale}/exports/saved/my", name="chill_main_export_saved_list_my")
*/
public function list(): Response
{
$user = $this->security->getUser();
if (!$this->security->isGranted('ROLE_USER') || !$user instanceof User) {
throw new AccessDeniedHttpException();
}
$exports = $this->savedExportRepository->findByUser($user, ['title' => 'ASC']);
// group by center
/** @var array<string, array{saved: SavedExport, export: ExportInterface}> $exportsGrouped */
$exportsGrouped = [];
foreach ($exports as $savedExport) {
$export = $this->exportManager->getExport($savedExport->getExportAlias());
$exportsGrouped[
$export instanceof GroupedExportInterface
? $this->translator->trans($export->getGroup()) : '_'
][] = ['saved' => $savedExport, 'export' => $export];
}
ksort($exportsGrouped);
return new Response(
$this->templating->render(
'@ChillMain/SavedExport/index.html.twig',
[
'grouped_exports' => $exportsGrouped,
]
)
);
}
}