-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
228 additions
and
0 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
69 changes: 69 additions & 0 deletions
69
app/Resources/views/admin/members/general_meeting/reports.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,69 @@ | ||
{% extends 'admin/base_with_header.html.twig' %} | ||
|
||
{% block content %} | ||
<h2>Assemblée générale - Comptes rendus</h2> | ||
<div class="ui segment"> | ||
<h3 class="ui header">Ajouter un compte rendu</h3> | ||
<div class="ui grid"> | ||
<div class="six wide column"> | ||
{{ form_start(form) }} | ||
<div class="ui form"> | ||
<div class="field"> | ||
{{ form_row(form.file) }} | ||
</div> | ||
<div class="field"> | ||
{{ form_row(form.submit, {attr: {class: "ui primary button"}}) }} | ||
</div> | ||
</div> | ||
{{ form_end(form) }} | ||
</div> | ||
<div class="ten wide column"> | ||
<ul> | ||
<li>Fichiers PDF uniquement</li> | ||
<li>Format de nommage : <code>YYYY-MM-JJ_CR AG AFUP YYYY-YYYY.pdf</code><br /> | ||
Exemple : <code>2014-02-15_CR AG AFUP 2013-2014.pdf</code></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<h3 class="ui header">Liste des comptes rendus</h3> | ||
<table class="ui table striped compact celled"> | ||
<thead> | ||
<tr> | ||
<th>Nom</th> | ||
<th>Type</th> | ||
<th>Poids</th> | ||
<th>Date</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for report in reports %} | ||
<tr> | ||
<td>{{ report.filename }}</td> | ||
<td> | ||
{{ report.extension }} | ||
</td> | ||
<td> | ||
{{ report.size }} | ||
</td> | ||
<td> | ||
{{ report.mtime|date('d/m/y H:i') }} | ||
</td> | ||
<td> | ||
<a href="{{ path('admin_members_general_meeting_reports', {file: report.basename}) }}" | ||
data-position="left center" | ||
data-tooltip="Supprimer le CR {{ report.filename }}" | ||
class="compact ui red icon button confirmable" | ||
data-confirmable-label="Êtes-vous sûr de vouloir supprimer le CR {{ report.basename }} ?" | ||
> | ||
<i class="trash icon"></i> | ||
</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endblock %} |
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
117 changes: 117 additions & 0 deletions
117
sources/AppBundle/Controller/Admin/Members/GeneralMeeting/ReportsAction.php
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,117 @@ | ||
<?php | ||
|
||
namespace AppBundle\Controller\Admin\Members\GeneralMeeting; | ||
|
||
use Symfony\Component\Form\Extension\Core\Type\FileType; | ||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\Validator\Constraints\File; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
use Twig\Environment; | ||
|
||
class ReportsAction | ||
{ | ||
/** @var Environment */ | ||
private $twig; | ||
/** @var FlashBagInterface */ | ||
private $flashBag; | ||
/** @var UrlGeneratorInterface */ | ||
private $urlGenerator; | ||
/** @var FormFactoryInterface */ | ||
private $formFactory; | ||
|
||
public function __construct(Environment $twig, | ||
FlashBagInterface $flashBag, | ||
UrlGeneratorInterface $urlGenerator, | ||
FormFactoryInterface $formFactory) | ||
{ | ||
$this->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[(int) $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', | ||
]); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/behat/features/Admin/Members/GeneralMeeting/GeneralMeetingReports.feature
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,22 @@ | ||
Feature: Administration - Partie Assemblée Générale CR | ||
|
||
@reloadDbWithTestData | ||
Scenario: Accède à la liste des CR | ||
Given I am logged in as admin and on the Administration | ||
And I follow "Assemblée générale" | ||
Then the ".content h2" element should contain "Assemblée générale" | ||
When I follow "Liste des comptes rendus" | ||
|
||
# Liste | ||
Then the ".content h2" element should contain "Assemblée générale - Comptes rendus" | ||
And I should see "2014-02-15_CR AG AFUP 2013-2014" | ||
|
||
# Suppression | ||
And I follow the button of tooltip "Supprimer le CR 2014-02-15_CR AG AFUP 2013-2014" | ||
Then the ".content .message" element should contain "Le compte rendu a correctement été supprimé." | ||
|
||
# Ajout | ||
And I attach the file "test_file1.pdf" to "report_file" | ||
And I press "report[submit]" | ||
Then the ".content .message" element should contain "Le compte rendu a correctement été ajouté." | ||
And I should see "test_file1" |