Commit f7553c14 authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

travail intermédiaire

parent 91e9b74d
......@@ -8,12 +8,16 @@
* @var $viewFile string
*/
/** @var \Application\Provider\Chargens\ChargensProvider $cp */
$cp = \Application::$container->get(\Application\Provider\Chargens\ChargensProvider::class);
/** @var \Application\Service\IntervenantService $si */
$si = $container->get(\Application\Service\IntervenantService::class);
$intervenant = $container->get(\Application\Service\IntervenantService::class)->get(195999);
$filename = getcwd() . '/data/charges.csv';
$filename2 = getcwd() . '/data/charges2.csv';
$avant = $cp->getExport()->fromCsv($filename);
$apres = $cp->getExport()->fromCsv($filename2);
$data = $si->isImportable($intervenant);
var_dump($data);
\ No newline at end of file
$d = $cp->getExport()->diff($data, $data2);
var_dump($d);
\ No newline at end of file
......@@ -354,19 +354,31 @@ class ChargensController extends AbstractController
{
$form = $this->getFormChargensDifferentiel();
if ($this->getRequest()->isPost()) {
$post = array_merge_recursive(
$this->getRequest()->getPost()->toArray(),
$this->getRequest()->getFiles()->toArray()
);
$form->setData($post);
if ($form->isValid()) {
$data = $form->getData();
}
}
/*
$diff = [];
if ($this->getRequest()->isPost()) {
$post = array_merge_recursive(
$this->getRequest()->getPost()->toArray(),
$this->getRequest()->getFiles()->toArray()
);
$form->setData($post);
if ($form->isValid()) {
$data = $form->getData();
$pce = $this->getProviderChargens()->getExport();
$avant = $pce->fromCsv($data['avant']['tmp_name']);
$apres = $pce->fromCsv($data['apres']['tmp_name']);
$diff = $pce->diff($avant, $apres);
}
}
*/
$pce = $this->getProviderChargens()->getExport();
$avant = $pce->fromCsv(getcwd() . '/data/charges.csv');
$apres = $pce->fromCsv(getcwd() . '/data/charges2.csv');
$diff = $pce->diff($avant, $apres);
return compact('form');
return compact('form', 'diff');
}
......
......@@ -84,9 +84,50 @@ class ExportProvider
public function dataFromFile(string $filename): array
public function fromCsv(string $filename): array
{
$data = [];
$row = 1;
if (($handle = fopen($filename, "r")) !== false) {
fgetcsv($handle, 9999, ";");
while (($d = fgetcsv($handle, 9999, ";")) !== false) {
$l = [
'annee' => $d[0],
'structure-porteuse-code' => $d[1],
'structure-porteuse-libelle' => $d[2],
'etape-porteuse-code' => $d[3],
'etape-porteuse-libelle' => $d[4],
'structure-ins-code' => $d[5],
'structure-ins-libelle' => $d[6],
'etape-ins-code' => $d[7],
'etape-ins-libelle' => $d[8],
'element-code' => $d[9],
'element-libelle' => $d[10],
'periode' => $d[11],
'discipline-code' => $d[12],
'discipline-libelle' => $d[13],
'type-heures' => $d[14],
'type-intervention' => $d[15],
'seuil-ouverture' => (int)$d[16],
'seuil-dedoublement' => (int)$d[17],
'assiduite' => (float)$d[18],
'effectif-etape' => (int)$d[19],
'effectif-element' => (int)$d[20],
'heures-ens' => (float)$d[21],
'groupes' => (float)$d[22],
'heures' => (float)$d[23],
'hetd' => (float)$d[24],
];
$data[] = $l;
}
fclose($handle);
}
return $data;
}
......@@ -135,6 +176,96 @@ class ExportProvider
public function diff(array $avant, array $apres): array
{
$diff = [];
// structure porteuse
// etape porteuse
// element
// structure ins
// etape ins
foreach ($avant as $a) {
$spc = $a['structure-porteuse-code'];
$epc = $a['etape-porteuse-code'];
$ec = $a['element-code'];
if (!array_key_exists($spc, $diff)) {
$diff[$spc] = [
'libelle' => $a['structure-porteuse-libelle'],
'etapes' => [],
];
}
if (!array_key_exists($epc, $diff[$spc]['etapes'])) {
$diff[$spc]['etapes'][$epc] = [
'libelle' => $a['etape-porteuse-libelle'],
'elements' => [],
];
}
if (!isset($diff[$spc]['etapes'][$epc]['elements'][$ec])) {
$diff[$spc]['etapes'][$epc]['elements'][$ec] = [
'code' => $ec,
'libelle' => $a['element-libelle'],
'periode' => $a['periode'],
'discipline-code' => $a['discipline-code'],
'discipline-libelle' => $a['discipline-libelle'],
];
}
if (!isset($diff[$spc]['etapes'][$epc]['elements'][$ec]['avant'])) {
$diff[$spc]['etapes'][$epc]['elements'][$ec]['avant'] = [
'seuil-ouverture' => $a['seuil-ouverture'],
'seuil-dedoublement' => $a['seuil-dedoublement'],
'assiduite' => $a['assiduite'],
'effectifs-fi' => 0,
'effectifs-fa' => 0,
'effectifs-fc' => 0,
];
}
}
foreach ($apres as $a) {
$spc = $a['structure-porteuse-code'];
$epc = $a['etape-porteuse-code'];
$ec = $a['element-code'];
if (!array_key_exists($spc, $diff)) {
$diff[$spc] = [
'libelle' => $a['structure-porteuse-libelle'],
'etapes' => [],
];
}
if (!array_key_exists($epc, $diff[$spc]['etapes'])) {
$diff[$spc]['etapes'][$epc] = [
'libelle' => $a['etape-porteuse-libelle'],
'elements' => [],
];
}
if (!isset($diff[$spc]['etapes'][$epc]['elements'][$ec])) {
$diff[$spc]['etapes'][$epc]['elements'][$ec] = [
'code' => $ec,
'libelle' => $a['element-libelle'],
'periode' => $a['periode'],
'discipline-code' => $a['discipline-code'],
'discipline-libelle' => $a['discipline-libelle'],
];
}
if (!isset($diff[$spc]['etapes'][$epc]['elements'][$ec]['apres'])) {
$diff[$spc]['etapes'][$epc]['elements'][$ec]['apres'] = [
'seuil-ouverture' => $a['seuil-ouverture'],
'seuil-dedoublement' => $a['seuil-dedoublement'],
'assiduite' => $a['assiduite'],
'effectifs-fi' => 0,
'effectifs-fa' => 0,
'effectifs-fc' => 0,
];
}
}
// var_dump($avant, $apres);
return $diff;
}
/**
* This method is called by var_dump() when dumping an object to get the properties that should be shown.
* If the method isn't defined on an object, then all public, protected and private properties will be shown.
......
......@@ -3,6 +3,7 @@
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $form \Application\Form\Chargens\DifferentielForm
* @var $diff array
*/
$title = "Différentiel entre deux exports des charges d'enseignement";
......@@ -31,6 +32,20 @@ echo '</div>';
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
if (!empty($diff)) {
foreach ($diff as $dc) {
echo '<h2>' . $dc['libelle'] . '</h2>';
foreach ($dc['etapes'] as $de) {
echo '<h3>' . $de['libelle'] . '</h3>';
foreach ($de['elements'] as $ep) {
echo '<h4>' . $ep['libelle'] . ' (' . $ep['code'] . ')</h4>';
var_dump($ep);
}
}
}
}
?>
<a class="btn btn-default" href="<?= $this->url('chargens'); ?>">
<i class="fa fa-undo" aria-hidden="true"></i>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment