mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-22 18:24:23 +00:00
enlarge the loadpostalcode command to more fields
This commit is contained in:
parent
24320cb702
commit
3770318e6a
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Command;
|
namespace Chill\MainBundle\Command;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Doctrine\Model\Point;
|
||||||
|
use Chill\MainBundle\Entity\Country;
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
@ -69,6 +71,9 @@ class LoadPostalCodesCommand extends Command
|
|||||||
. "using the postal code and name. \n"
|
. "using the postal code and name. \n"
|
||||||
. "The CSV file must have the following columns: "
|
. "The CSV file must have the following columns: "
|
||||||
. "postal code, label, country code."
|
. "postal code, label, country code."
|
||||||
|
. "Optionally, the csv file can have the following "
|
||||||
|
. "columns after the country code: reference code, latitude, longitude, source. "
|
||||||
|
. "The latitude and longitude columns are supposed to be in WGS84 and expressed in decimal degrees. "
|
||||||
. "The CSV file should not have any header row.")
|
. "The CSV file should not have any header row.")
|
||||||
->addArgument('csv_file', InputArgument::REQUIRED, "the path to "
|
->addArgument('csv_file', InputArgument::REQUIRED, "the path to "
|
||||||
. "the csv file. See the help for specifications.")
|
. "the csv file. See the help for specifications.")
|
||||||
@ -137,7 +142,7 @@ class LoadPostalCodesCommand extends Command
|
|||||||
$output->writeln('<info>'.$num.' were added !</info>');
|
$output->writeln('<info>'.$num.' were added !</info>');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCSVResource(InputInterface $input)
|
public function getCSVResource(InputInterface $input)
|
||||||
{
|
{
|
||||||
$fs = new Filesystem();
|
$fs = new Filesystem();
|
||||||
$filename = $input->getArgument('csv_file');
|
$filename = $input->getArgument('csv_file');
|
||||||
@ -163,7 +168,7 @@ class LoadPostalCodesCommand extends Command
|
|||||||
}
|
}
|
||||||
$em = $this->entityManager;
|
$em = $this->entityManager;
|
||||||
$country = $em
|
$country = $em
|
||||||
->getRepository('ChillMainBundle:Country')
|
->getRepository(Country::class)
|
||||||
->findOneBy(array('countryCode' => $row[2]));
|
->findOneBy(array('countryCode' => $row[2]));
|
||||||
|
|
||||||
if ($country === NULL) {
|
if ($country === NULL) {
|
||||||
@ -173,7 +178,7 @@ class LoadPostalCodesCommand extends Command
|
|||||||
|
|
||||||
// try to find an existing postal code
|
// try to find an existing postal code
|
||||||
$existingPC = $em
|
$existingPC = $em
|
||||||
->getRepository('ChillMainBundle:PostalCode')
|
->getRepository(PostalCode::class)
|
||||||
->findBy(array('code' => $row[0], 'name' => $row[1]));
|
->findBy(array('code' => $row[0], 'name' => $row[1]));
|
||||||
|
|
||||||
if (count($existingPC) > 0) {
|
if (count($existingPC) > 0) {
|
||||||
@ -187,6 +192,18 @@ class LoadPostalCodesCommand extends Command
|
|||||||
->setCountry($country)
|
->setCountry($country)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
if (NULL != $row[3]){
|
||||||
|
$postalCode->setRefId($row[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL != $row[4] & NULL != $row[5]){
|
||||||
|
$postalCode->setCenter(Point::fromLonLat((float) $row[5], (float) $row[4]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL != $row[6]){
|
||||||
|
$postalCode->setSource($row[6]);
|
||||||
|
}
|
||||||
|
|
||||||
$errors = $this->validator->validate($postalCode);
|
$errors = $this->validator->validate($postalCode);
|
||||||
|
|
||||||
if ($errors->count() == 0) {
|
if ($errors->count() == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user