src/EventSubscriber/Import/ImmowebEstimationFrance.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Import;
  3. use App\Entity\ImmowebEstimationFrance as EntityImmowebEstimationFrance;
  4. use App\Service\Import\CustomRowEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class ImmowebEstimationFrance implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @return array<string, mixed>
  10.      */
  11.     public static function getSubscribedEvents(): array
  12.     {
  13.         return [
  14.             CustomRowEvent::NAME => ['customRow'],
  15.         ];
  16.     }
  17.     /**
  18.      * @return void
  19.      */
  20.     public function customRow(CustomRowEvent $event)
  21.     {
  22.         if ($event->getEntity() != EntityImmowebEstimationFrance::class) {
  23.             return;
  24.         }
  25.         $row $event->getData();
  26.         $this->cast('int'$row'number_of_batches');
  27.         $this->cast('int'$row'mutation_id');
  28.         $this->cast('int'$row'number_of_levels');
  29.         $this->cast('int'$row'floor_number');
  30.         $this->cast('int'$row'number_of_rooms');
  31.         $this->cast('int'$row'number_of_pieces');
  32.         $this->cast('int'$row'fields_surface');
  33.         $this->cast('int'$row'living_area');
  34.         $this->cast('float'$row'average_price');
  35.         $this->cast('float'$row'sale_price_2016');
  36.         $this->cast('float'$row'sale_price_2017');
  37.         $this->cast('float'$row'sale_price_2018');
  38.         $this->cast('float'$row'sale_price_2019');
  39.         $this->cast('float'$row'sale_price_2020');
  40.         $this->cast('float'$row'sale_price_2021');
  41.         $this->cast('float'$row'sale_price_2022');
  42.         $this->cast('float'$row'sale_price_2023');
  43.         $this->cast('float'$row'rent_price_2016');
  44.         $this->cast('float'$row'rent_price_2017');
  45.         $this->cast('float'$row'rent_price_2018');
  46.         $this->cast('float'$row'rent_price_2019');
  47.         $this->cast('float'$row'rent_price_2020');
  48.         $this->cast('float'$row'rent_price_2021');
  49.         $this->cast('float'$row'rent_price_2022');
  50.         $this->cast('float'$row'rent_price_2023');
  51.         $this->cast('float'$row'global_sale_price');
  52.         $this->cast('float'$row'global_rent_price');
  53.         $this->cast('float'$row'price');
  54.         $this->cast('float'$row'honorary_award');
  55.         $this->cast('float'$row'charge');
  56.         $this->cast('float'$row'energy_consumption');
  57.         $this->cast('float'$row'property_tax');
  58.         $this->cast('float'$row'lot2_square_are');
  59.         $event->setData($row);
  60.     }
  61.     public function cast(string $type, array &$rowstring $index)
  62.     {
  63.         if (isset($row[$index])) {
  64.             if ($type == 'int') {
  65.                 $row[$index] = (int) $row[$index];
  66.             } elseif ($type == 'float') {
  67.                 $row[$index] = (float) $row[$index];
  68.             }
  69.         }
  70.     }
  71. }