From 68cc197066ab6125eb9b29361be6c0bf4ffd5c82 Mon Sep 17 00:00:00 2001 From: Albin Date: Sun, 17 Mar 2024 21:59:56 +0100 Subject: [PATCH] afup#1461 General Meeting reports --- .../members/general_meeting/list.html.twig | 6 + .../members/general_meeting/reports.html.twig | 69 ++++++++++ app/config/config.yml | 1 + app/config/routing/admin.yml | 4 + .../Members/GeneralMeeting/ReportsAction.php | 118 ++++++++++++++++++ 5 files changed, 198 insertions(+) create mode 100644 app/Resources/views/admin/members/general_meeting/reports.html.twig create mode 100644 sources/AppBundle/Controller/Admin/Members/GeneralMeeting/ReportsAction.php diff --git a/app/Resources/views/admin/members/general_meeting/list.html.twig b/app/Resources/views/admin/members/general_meeting/list.html.twig index 785c83878..b2faa53ae 100644 --- a/app/Resources/views/admin/members/general_meeting/list.html.twig +++ b/app/Resources/views/admin/members/general_meeting/list.html.twig @@ -10,6 +10,12 @@ Préparer une assemblée générale + +
+ + Liste des comptes rendus +
+
{% if latestDate %} diff --git a/app/Resources/views/admin/members/general_meeting/reports.html.twig b/app/Resources/views/admin/members/general_meeting/reports.html.twig new file mode 100644 index 000000000..d7e5a0538 --- /dev/null +++ b/app/Resources/views/admin/members/general_meeting/reports.html.twig @@ -0,0 +1,69 @@ +{% extends 'admin/base_with_header.html.twig' %} + +{% block content %} +

Assemblée générale - Comptes rendus

+
+

Ajouter un compte rendu

+
+
+ {{ form_start(form) }} +
+
+ {{ form_row(form.file) }} +
+
+ {{ form_row(form.submit, {attr: {class: "ui primary button"}}) }} +
+
+ {{ form_end(form) }} +
+
+
    +
  • Fichiers PDF uniquement
  • +
  • Format de nommage : YYYY-MM-JJ_CR AG AFUP YYYY-YYYY.pdf
    + Exemple : 2014-02-15_CR AG AFUP 2013-2014.pdf
  • +
+
+
+
+ + +

Liste des comptes rendus

+ + + + + + + + + + + + {% for report in reports %} + + + + + + + + {% endfor %} + +
NomTypePoidsDate
{{ report.filename }} + {{ report.extension }} + + {{ report.size }} + + {{ report.mtime|date('d/m/y H:i') }} + + + + +
+{% endblock %} diff --git a/app/config/config.yml b/app/config/config.yml index 4841e5c87..5d2572e69 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -60,6 +60,7 @@ parameters: - admin_members_general_meeting - admin_members_general_meeting_prepare - admin_members_general_meeting_edit + - admin_members_general_meeting_reports assemblee_generale_votes: nom: 'Assemblée générale - votes' niveau: 'ROLE_ADMIN' diff --git a/app/config/routing/admin.yml b/app/config/routing/admin.yml index 4ed7243fa..19c0baed8 100644 --- a/app/config/routing/admin.yml +++ b/app/config/routing/admin.yml @@ -97,6 +97,10 @@ admin_members_general_vote_close: path: /members/general_meeting_vote/close defaults: {_controller: AppBundle\Controller\Admin\Members\GeneralMeetingVote\CloseAction} +admin_members_general_meeting_reports: + path: /members/general_meeting/reports + defaults: {_controller: AppBundle\Controller\Admin\Members\GeneralMeeting\ReportsAction} + admin_techletter: resource: "techletter_admin.yml" prefix: /techletter diff --git a/sources/AppBundle/Controller/Admin/Members/GeneralMeeting/ReportsAction.php b/sources/AppBundle/Controller/Admin/Members/GeneralMeeting/ReportsAction.php new file mode 100644 index 000000000..08bf7a1fc --- /dev/null +++ b/sources/AppBundle/Controller/Admin/Members/GeneralMeeting/ReportsAction.php @@ -0,0 +1,118 @@ +twig = $twig; + $this->flashBag = $flashBag; + $this->urlGenerator = $urlGenerator; + $this->formFactory = $formFactory; + } + + public function __invoke(Request $request): Response + { + $basePath = 'uploads/general_meetings_reports/'; + + // delete + if ($fileToDelete = $request->query->get('file')) { + $fileToDelete = $basePath . basename($fileToDelete); + if (is_file($fileToDelete) && unlink($fileToDelete)) { + $this->flashBag->add('notice', 'Le compte rendu a correctement été supprimé.'); + } else { + $this->flashBag->add('error', 'Le compte rendu n\'a pas été supprimé.'); + + } + return new RedirectResponse($this->urlGenerator->generate($request->attributes->get('_route'))); + } + + // add + $form = $this->buildForm(); + if ($form->handleRequest($request) && $form->isValid()) { + /** @var UploadedFile $uploadedFile */ + $reportFile = $form->get('file')->getData(); + if ($reportFile->move($basePath, $reportFile->getClientOriginalName())) { + $this->flashBag->add('notice', 'Le compte rendu a correctement été ajouté.'); + } else { + $this->flashBag->add('error', 'Le compte rendu n\'a pas été ajouté.'); + } + return new RedirectResponse($this->urlGenerator->generate($request->attributes->get('_route'))); + } + + $files = glob($basePath . '*.pdf'); + rsort($files); + + $reports = []; + foreach ($files as $file) { + $report = pathinfo($file); + + $report['size'] = self::humanFilesize(filesize($file)); + $report['mtime'] = filemtime($file); + $reports[] = $report; + } + + return new Response($this->twig->render('admin/members/general_meeting/reports.html.twig', [ + 'form' => $form->createView(), + 'reports' => $reports + ])); + } + + private static function humanFilesize($bytes): string + { + $sz = 'BKMGTP'; + $factor = floor((strlen($bytes) - 1) / 3); + + return sprintf("%.2f", $bytes / (1024 ** $factor)) . $sz[$factor]; + } + + private function buildForm(): FormInterface + { + return $this->formFactory->createNamed('report') + ->add('file', FileType::class, [ + 'label' => 'Fichier', + 'required' => true, + 'constraints' => [ + new NotBlank(), + new File([ + 'maxSize' => '2M', + 'mimeTypes' => [ + 'application/pdf', + 'application/x-pdf', + ], + 'mimeTypesMessage' => 'Uniquement des fichiers PDF.', + ]) + ] + ]) + ->add('submit', SubmitType::class, [ + 'label' => 'Envoyer', + ]); + } +}