Skip to content
Snippets Groups Projects
Commit 08a6ef0a authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Gestion du header dans l'importation depuis un CSV

parent 068add9e
No related branches found
No related tags found
No related merge requests found
......@@ -138,12 +138,14 @@ class ValidateurController extends AbstractActionController
$fichier_path = $file['fichier']['tmp_name'];
$mode = $data['mode'];
$header = isset($data['header'])?$data['header'] === '1':false;
//reading
$array = [];
$warning = [];
$chaines = [];
$agents = [];
$info = [];
if ($fichier_path === null or $fichier_path === '') {
$error[] = "Aucun fichier !";
......@@ -154,6 +156,10 @@ class ValidateurController extends AbstractActionController
$array[] = $content;
}
if ($header) {
$array = array_splice($array,1);
$info[] = "Retrait de la première ligne";
}
foreach ($array as $line) {
$agent_id = $line[0]??null;
$agent = $this->getAgentService()->getAgent($agent_id);
......@@ -169,9 +175,11 @@ class ValidateurController extends AbstractActionController
if ($date_fin_st !== '' and $dateFin === false) $warning[] = "Impossibilité de calculé la date de fin à partir de [".$date_fin_st."]";
$chaines[] = [$agent, $responsable, $dateDebut, $dateFin];
if ($agent !== null) {
$agents[$agent->getId()] = $agent;
}
}
}
if ($mode === 'import' and empty($error)) {
foreach ($agents as $agent) {
......@@ -204,6 +212,7 @@ class ValidateurController extends AbstractActionController
'error' => $error,
'warning' => $warning,
'chaines' => $chaines,
'info' => $info,
]);
}
......
......@@ -7,6 +7,7 @@
* @var string $type
* @var string[] $error
* @var string[] $warning
* @var string[] $info
* @var Agent[] $chaines
*/
......@@ -21,6 +22,12 @@ use Application\Form\CsvImportation\CsvImportationForm;
<?php echo $this->form($form); ?>
<?php if (!empty($info)) : ?>
<div class="alert alert-info">
<span class="icon icon-information"></span>
<?php echo implode('<br>', $info); ?>
</div>
<?php endif; ?>
<?php if (!empty($error)) : ?>
<div class="alert alert-danger">
<span class="icon icon-attention"></span>
......@@ -51,8 +58,8 @@ use Application\Form\CsvImportation\CsvImportationForm;
<tbody>
<?php foreach ($chaines as [$agent, $responsable, $dateDebut, $dateFin]) : ?>
<tr>
<td> <?php echo $agent->getDenomination(); ?> </td>
<td> <?php echo $responsable->getDenomination(); ?> </td>
<td> <?php echo $agent?->getDenomination(); ?> </td>
<td> <?php echo $responsable?->getDenomination(); ?> </td>
<td> <?php echo ($dateDebut)?$dateDebut->format('d/m/Y'):"---"; ?> </td>
<td> <?php echo ($dateFin)?$dateFin->format('d/m/Y'):"---"; ?> </td>
</tr>
......
......@@ -3,6 +3,7 @@
namespace Application\Form\CsvImportation;
use Laminas\Form\Element\Button;
use Laminas\Form\Element\Checkbox;
use Laminas\Form\Element\File;
use Laminas\Form\Element\Select;
use Laminas\Form\Form;
......@@ -37,6 +38,19 @@ class CsvImportationForm extends Form {
'id' => 'mode',
],
]);
//header
$this->add([
'type' => Checkbox::class,
'name' => 'header',
'options' => [
'label' => 'Retirer la première ligne (header)',
'label_options' => [ 'disable_html_escape' => true, ],
],
'attributes' => [
'id' => 'header',
],
]);
//Submit
$this->add([
'type' => Button::class,
......@@ -54,6 +68,7 @@ class CsvImportationForm extends Form {
$this->setInputFilter((new Factory())->createInputFilter([
'fichier' => [ 'required' => true, ],
'mode' => ['required' => true, ],
'header' => ['required' => false, ],
]));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment