Commit 303a140e by Damien Moulard

Merge branch '9206-update-external-data' into 'develop'

9206 update external data

See merge request !159
parents 5574b117 10fc99b5
...@@ -19,7 +19,17 @@ use Twig\Environment; ...@@ -19,7 +19,17 @@ use Twig\Environment;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
/** /**
* This command is used to import data to complete external adherents data * This command is used to import non dated external adherents data
*
* Expected format:
* - email adhérent
* - tranche d’âge (type de donnée = 1 [i.e. moins 30 ans] / 2 [i.e. entre 30 et 59 ans] / 3 [i.e. plus de 59 ans])
* - année de naissance (type de donnée : 1994)
* - groupe A/R (âge/revenu ; type de donnée : chiffre de 1 à 12)
* - Groupe F/R (foyer/revenu ; type de donnée : chiffre de 1 à 16)
* - ID externe (type de donnée : CC1-47 / Tir1VAG-176 / TirVag2-259 / PV1-32)
* - Cohorte (type de donnée : CC / PV / Tir1 / Tir2)
* - membre CC / ancien membre CC (type de données : 1 / 2)
*/ */
class ImportExternalAdherentData extends Command class ImportExternalAdherentData extends Command
{ {
...@@ -93,8 +103,8 @@ class ImportExternalAdherentData extends Command ...@@ -93,8 +103,8 @@ class ImportExternalAdherentData extends Command
]; ];
if (($handle = fopen($csvFilePath, "r")) !== FALSE) { if (($handle = fopen($csvFilePath, "r")) !== FALSE) {
while (($row = fgetcsv($handle, 1000, "\t")) !== FALSE) { while (($row = fgetcsv($handle, 1000, ";")) !== FALSE) {
if ($row[0] === 'mail') { if ($row[0] === 'mail' || $row[0] === 'email adhérent') {
// headers row // headers row
continue; continue;
} }
...@@ -120,37 +130,34 @@ class ImportExternalAdherentData extends Command ...@@ -120,37 +130,34 @@ class ImportExternalAdherentData extends Command
$data = $data[0]; $data = $data[0];
} }
#If a field is already stored in database, do not update it # If no data is provided in the file cell, do not fill (leave it empty / do not update)
#If no data is provided in the file cell, do not fill (let it empty) if ($row[1] !== "") {
if (!$data->getExternalDataAgeGroup() && $row[1] !== "") {
$data->setExternalDataAgeGroup($ageGroups[$row[1]]); $data->setExternalDataAgeGroup($ageGroups[$row[1]]);
$updated = true; $updated = true;
} }
if (!$data->getBirthYear() && $row[2] !== "") { if ($row[2] !== "") {
$data->setBirthYear(intval($row[2])); $data->setBirthYear(intval($row[2]));
$updated = true; $updated = true;
} }
if (!$data->getAgeIncomeRatioGroup() && $row[3] !== "") { if ($row[3] !== "") {
$data->setAgeIncomeRatioGroup(intval($row[3])); $data->setAgeIncomeRatioGroup(intval($row[3]));
$updated = true; $updated = true;
} }
if (!$data->getHouseholdIncomeRatioGroup() && $row[4] !== "") { if ($row[4] !== "") {
$data->setHouseholdIncomeRatioGroup(intval($row[4])); $data->setHouseholdIncomeRatioGroup(intval($row[4]));
$updated = true; $updated = true;
} }
if (!$data->getExternalId() && $row[5] !== "") { if ($row[5] !== "") {
$data->setExternalId($row[5]); $data->setExternalId($row[5]);
$updated = true; $updated = true;
} }
if (!$data->getCohort() && $row[6] !== "") { if ($row[6] !== "") {
$data->setCohort($row[6]); $data->setCohort($row[6]);
$updated = true; $updated = true;
} }
if(count($row) > 7) { if(count($row) > 7 && $row[7] !== "") {
if (!$data->getExternalDataCCMemberStatus() && $row[7] !== "") { $data->setExternalDataCCMemberStatus($ccStatus[$row[7]]);
$data->setExternalDataCCMemberStatus($ccStatus[$row[7]]); $updated = true;
$updated = true;
}
} }
if ($updated) { if ($updated) {
......
...@@ -17,7 +17,14 @@ use Twig\Environment; ...@@ -17,7 +17,14 @@ use Twig\Environment;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
/** /**
* This command is used to import data to complete external adherents data * This command is used to import adherents external dated data (data that depends on a specific year)
*
* Expected format:
* - email adhérent
* - part uc (nombre de part uc dans le foyer ; type de donnée : 1,8)
* - Année données revenus
* - Revenu annuel (type de donnée : 25000 (no space, no currency))
* - Revenu annuel (type de donnée : 2300 (no space, no currency))
*/ */
class ImportExternalAdherentDatedData extends Command class ImportExternalAdherentDatedData extends Command
{ {
...@@ -65,7 +72,7 @@ class ImportExternalAdherentDatedData extends Command ...@@ -65,7 +72,7 @@ class ImportExternalAdherentDatedData extends Command
if (($handle = fopen($csvFilePath, "r")) !== FALSE) { if (($handle = fopen($csvFilePath, "r")) !== FALSE) {
while (($row = fgetcsv($handle, 1000, ";")) !== FALSE) { while (($row = fgetcsv($handle, 1000, ";")) !== FALSE) {
if ($row[0] === 'mail') { if ($row[0] === 'mail' || $row[0] === 'email adhérent') {
// headers row // headers row
continue; continue;
} }
...@@ -100,17 +107,16 @@ class ImportExternalAdherentDatedData extends Command ...@@ -100,17 +107,16 @@ class ImportExternalAdherentDatedData extends Command
$datedData = $datedData[0]; $datedData = $datedData[0];
} }
#If a field is already stored in database, do not update it # If no data is provided in the file cell, do not fill (let it empty)
#If no data is provided in the file cell, do not fill (let it empty) if ($row[1] !== "") {
if (!$datedData->getHouseholdUnitShares() && $row[1] !== "") {
$datedData->setHouseholdUnitShares(floatval($row[1])); $datedData->setHouseholdUnitShares(floatval($row[1]));
$updated = true; $updated = true;
} }
if (!$datedData->getAnnualIncome() && $row[3] !== "") { if ($row[3] !== "") {
$datedData->setAnnualIncome(intval($row[3])); $datedData->setAnnualIncome(intval($row[3]));
$updated = true; $updated = true;
} }
if (!$datedData->getMonthlyIncome() && $row[4] !== "") { if ($row[4] !== "") {
$datedData->setMonthlyIncome(intval($row[4])); $datedData->setMonthlyIncome(intval($row[4]));
$updated = true; $updated = true;
} }
......
Markdown is supported
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