<?php
namespace App\EventSubscriber\Import;
use App\Entity\ImmowebEstimationFrance as EntityImmowebEstimationFrance;
use App\Service\Import\CustomRowEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ImmowebEstimationFrance implements EventSubscriberInterface
{
/**
* @return array<string, mixed>
*/
public static function getSubscribedEvents(): array
{
return [
CustomRowEvent::NAME => ['customRow'],
];
}
/**
* @return void
*/
public function customRow(CustomRowEvent $event)
{
if ($event->getEntity() != EntityImmowebEstimationFrance::class) {
return;
}
$row = $event->getData();
$this->cast('int', $row, 'number_of_batches');
$this->cast('int', $row, 'mutation_id');
$this->cast('int', $row, 'number_of_levels');
$this->cast('int', $row, 'floor_number');
$this->cast('int', $row, 'number_of_rooms');
$this->cast('int', $row, 'number_of_pieces');
$this->cast('int', $row, 'fields_surface');
$this->cast('int', $row, 'living_area');
$this->cast('float', $row, 'average_price');
$this->cast('float', $row, 'sale_price_2016');
$this->cast('float', $row, 'sale_price_2017');
$this->cast('float', $row, 'sale_price_2018');
$this->cast('float', $row, 'sale_price_2019');
$this->cast('float', $row, 'sale_price_2020');
$this->cast('float', $row, 'sale_price_2021');
$this->cast('float', $row, 'sale_price_2022');
$this->cast('float', $row, 'sale_price_2023');
$this->cast('float', $row, 'rent_price_2016');
$this->cast('float', $row, 'rent_price_2017');
$this->cast('float', $row, 'rent_price_2018');
$this->cast('float', $row, 'rent_price_2019');
$this->cast('float', $row, 'rent_price_2020');
$this->cast('float', $row, 'rent_price_2021');
$this->cast('float', $row, 'rent_price_2022');
$this->cast('float', $row, 'rent_price_2023');
$this->cast('float', $row, 'global_sale_price');
$this->cast('float', $row, 'global_rent_price');
$this->cast('float', $row, 'price');
$this->cast('float', $row, 'honorary_award');
$this->cast('float', $row, 'charge');
$this->cast('float', $row, 'energy_consumption');
$this->cast('float', $row, 'property_tax');
$this->cast('float', $row, 'lot2_square_are');
$event->setData($row);
}
public function cast(string $type, array &$row, string $index)
{
if (isset($row[$index])) {
if ($type == 'int') {
$row[$index] = (int) $row[$index];
} elseif ($type == 'float') {
$row[$index] = (float) $row[$index];
}
}
}
}