<?php
namespace App\Infra\Services;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class FilterApiService
{
private $apiService;
public function __construct(
ApiService $apiService
)
{
$this->apiService = $apiService;
}
public function getReferences()
{
$references = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $reference) {
if ($reference['construction']['construction_step'] === '3') {
$references[] = $reference;
}
}
usort($references,function($first,$second){
return $first['id'] < $second['id'];
});
return $references;
}
public function getReferencesWithoutParking()
{
$references = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $reference) {
if ($reference['type'] !== 5 && $reference['type'] !== 6 && $reference['category'] !== 4) {
$references[] = $reference;
}
}
return $references;
}
public function getResidenceReferences()
{
$references = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $reference) {
if ($reference['construction']['construction_step'] === '3' && ($reference['type'] === 1 || $reference['type'] === 6)) {
$references[] = $reference;
}
}
return $references;
}
public function getHouseReferences()
{
$references = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $reference) {
if ($reference['construction']['construction_step'] === '3' && $reference['type'] === 2) {
$references[] = $reference;
}
}
return $references;
}
public function getCommerceReferences()
{
$references = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $reference) {
if ($reference['construction']['construction_step'] === '3' && $reference['type'] === 4) {
$references[] = [$properties];
}
}
return $references;
}
public function getBureauxReferences()
{
$references = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $reference) {
if ($reference['construction']['construction_step'] === '3' && $reference['type'] === 7) {
$references[] = $reference;
}
}
return $references;
}
public function getAllProperties()
{
return $this->apiService->getAllProperties()['properties'];
}
public function getAllPropertiesForSearch()
{
$propertiesFilter = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $property) {
if ($property['construction']['construction_step'] !== '3' ) {
$propertiesFilter[] = $property;
}
}
return $propertiesFilter;
}
/**
* @param int $id
* @return array
*
* Julien V2
*/
public function getPropertiesByCategory(?int $id)
{
$propertiesFilter = [];
$properties = $this->apiService->getAllProperties()['properties'];
if (!$id) {
return $properties;
}
foreach ($properties as $property) {
if ($property['category'] === $id && $property['type'] !== 1 && $property['type'] !== 6) {
$propertiesFilter[] = $property;
}
}
return $propertiesFilter;
}
public function getPropertiesForCities()
{
$projects = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $saleProperty) {
if ($saleProperty['category'] === 1 || $saleProperty['category'] === 2 || $saleProperty['construction']['construction_step'] === '2' || $saleProperty['construction']['construction_step'] === '1') {
$projects[] = $saleProperty;
}
}
return $projects;
}
public function getSaleProperties()
{
$projects = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $saleProperty) {
if ($saleProperty['category'] === 1) {
$projects[] = $saleProperty;
}
}
return $projects;
}
public function getChildrensOfProject($id)
{
$childprojects = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $childProperty) {
if ($childProperty['parent'] === (int)$id) {
$childprojects[] = $childProperty;
}
}
return $childprojects;
}
public function getRentalProperties()
{
$projects = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $rentalProperty) {
if ($rentalProperty['category'] === 2) {
$projects[] = $rentalProperty;
}
}
return $projects;
}
public function getAllProjects()
{
$properties = $this->apiService->getAllProperties()['properties'];
$projects = [];
foreach ($properties as $projectConstruction) {
if ($projectConstruction['construction']['construction_step'] === '2' || $projectConstruction['construction']['construction_step'] === '1') {
$projects[] = $projectConstruction;
}
}
return $projects;
}
public function getConstructionProjects()
{
$projectConstructions = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $projectConstruction) {
if ($projectConstruction['construction']['construction_step'] === '2') {
$projectConstructions[] = $projectConstruction;
}
}
return $projectConstructions;
}
public function getFuturProjects()
{
$projectFuturs = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $projectFutur) {
if ($projectFutur['construction']['construction_step'] == '1') {
$projectFuturs[] = $projectFutur;
}
}
return $projectFuturs;
}
public function getFinishProjects()
{
$projectFinishes = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $projectFinish) {
if ($projectFinish['construction']['construction_step'] === '3') {
$projectFinishes[] = $projectFinish;
}
}
return $projectFinishes;
}
public function getTypeProperty(string $id)
{
//dd($id);
$arrayConverter = [
1 => 'Immeuble',
2 => 'Résidence',
3 => 'Lotissement',
4 => 'Hameau',
5 => 'Domaine',
6 => 'Propriété',
7 => 'Rue / Avenue / Chemin …',
8 => 'Hôtel',
];
return $arrayConverter[$id] ?? null;
}
public function getAreaConversion($unitId)
{
$arrayConverter = [
1 => 'm²',
2 => 'ft²',
3 => 'kanal',
4 => 'marla',
5 => 'yd²',
6 => 'acre',
7 => 'ha',
8 => 'ares',
9 => 'toises',
10 => 'perches',
11 => 'arpents'
];
return $arrayConverter[$unitId] ?? null;
}
public function getPropertyCategory($categoryId)
{
$arrayConverter = [
1 => 'Vente',
2 => 'Location',
3 => 'Location saisonnière',
4 => 'Programme',
5 => 'Viager',
6 => 'Enchère'
];
return $arrayConverter[$categoryId] ?? null;
}
public function getInversePropertyCategory($categoryId)
{
$arrayConverter = [
'Vente' => 1,
'Location' => 2,
'Location saisonnière' => 3,
'Programme' => 4,
'Viager' => 5,
'Enchère' => 6
];
return $arrayConverter[$categoryId] ?? null;
}
public function getRegulationById($categoryId)
{
$arrayConverter = [
50 => 'DPE',
51 => 'Classe d’isolation thermique',
52 => 'GES',
];
return $arrayConverter[$categoryId] ?? null;
}
public function getSubTypeProject($id)
{
$arrayConverter = [
1 => 'Appartement',
2 => 'Maison',
3 => 'Terrain',
4 => 'Commerce',
5 => 'Garage / Parking',
6 => 'Immeuble',
7 => 'Bureaux',
8 => 'Studio',
9 => 'Duplex',
10 => 'Cave / Box',
11 => 'Penthouse'
];
return $arrayConverter[$id] ?? null;
}
public function getInverseSubTypeProject(?string $id)
{
$arrayConverter = [
'Appartement' => 1,
'Maison' => 2,
'Terrain' => 3,
'Commerce' => 4,
'Garage / Parking' => 5,
'Immeuble' => 6,
'Bureaux' => 7,
'Studio' => 8,
'Duplex' => 9,
'Cave / Box' => 10,
'Penthouse' => 11
];
return $arrayConverter[$id] ?? null;
}
public function getInverseRealSubTypeProject(?string $id, $all = false)
{
$arrayConverter = [
'Appartement' => [
'id' => 1,
'status' => 'type'
],
'Maison' => [
'id' => 2,
'status' => 'type'
],
'Terrain' => [
'id' => 3,
'status' => 'type'
],
'Commerce' => [
'id' => 4,
'status' => 'type'
],
'Garage / Parking' => [
'id' => 5,
'status' => 'type'
],
'Immeuble' => [
'id' => 6,
'status' => 'type'
],
'Bureaux' => [
'id' => 7,
'status' => 'type'
],
'Studio' => [
'id' => 6,
'status' => 'subtype'
],
"Locaux d'activité / Entrepôts" => [
'id' => 9,
'status' => 'type'
],
'Cave / Box' => [
'id' => 10,
'status' => 'type'
],
'Penthouse' => [
'id' => 4,
'status' => 'subtype'
],
'Ferme' => [
'id' => 11,
'status' => 'subtype'
],
'Loft' => [
'id' => 12,
'status' => 'subtype'
],
'Villa' => [
'id' => 14,
'status' => 'subtype'
],
'Grange' => [
'id' => 16,
'status' => 'subtype'
],
'Propriété' => [
'id' => 19,
'status' => 'subtype'
],
'Ensemble immobilier' => [
'id' => 20,
'status' => 'subtype'
],
'Fermette' => [
'id' => 23,
'status' => 'subtype'
],
'Chambre' => [
'id' => 28,
'status' => 'subtype'
],
'Hangar' => [
'id' => 29,
'status' => 'subtype'
],
'Chalet' => [
'id' => 32,
'status' => 'subtype'
],
'Local commercial' => [
'id' => 33,
'status' => 'subtype'
],
'Fonds de commerce' => [
'id' => 34,
'status' => 'subtype'
],
'Entrepôt' => [
'id' => 41,
'status' => 'subtype'
],
'Parking' => [
'id' => 43,
'status' => 'subtype'
],
'Hôtel' => [
'id' => 44,
'status' => 'subtype'
],
'Maison jumelée' => [
'id' => 71,
'status' => 'subtype'
],
'Bungalow' => [
'id' => 72,
'status' => 'subtype'
],
'Lotissement' => [
'id' => 80,
'status' => 'subtype'
],
'Terrain agricole' => [
'id' => 103,
'status' => 'subtype'
],
'Bâtiment historique' => [
'id' => 105,
'status' => 'subtype'
]
];
if($all) return $arrayConverter;
return $arrayConverter[$id] ?? null;
}
public function arrayAllTypes()
{
return [
'Appartement' => [
'id' => 1,
'status' => 'type'
],
'Maison' => [
'id' => 2,
'status' => 'type'
],
'Terrain' => [
'id' => 3,
'status' => 'type'
],
'Commerce' => [
'id' => 4,
'status' => 'type'
],
'Garage / Parking' => [
'id' => 5,
'status' => 'type'
],
'Immeuble' => [
'id' => 6,
'status' => 'type'
],
'Bureaux' => [
'id' => 7,
'status' => 'type'
],
'Studio' => [
'id' => 6,
'status' => 'subtype'
],
"Locaux d'activité / Entrepôts" => [
'id' => 9,
'status' => 'type'
],
'Cave / Box' => [
'id' => 10,
'status' => 'type'
],
'Penthouse' => [
'id' => 4,
'status' => 'subtype'
],
'Ferme' => [
'id' => 11,
'status' => 'subtype'
],
'Loft' => [
'id' => 12,
'status' => 'subtype'
],
'Villa' => [
'id' => 14,
'status' => 'subtype'
],
'Grange' => [
'id' => 16,
'status' => 'subtype'
],
'Propriété' => [
'id' => 19,
'status' => 'subtype'
],
'Ensemble immobilier' => [
'id' => 20,
'status' => 'subtype'
]
];
}
public function getAllProjectsParams($params = null)
{
$params = str_replace('[', '', $params);
$params = str_replace(']', '', $params);
$params = explode(',', $params);
$properties = $this->apiService->getAllProperties()['properties'];
$projects = [];
foreach ($properties as $projectConstruction) {
if ($projectConstruction['construction']['construction_step'] === '2' || $projectConstruction['construction']['construction_step'] === '1') {
foreach ($params as $param) {
if ($projectConstruction['type'] === (int)$param)
$projects[] = $projectConstruction;
}
}
}
if ($params[0] === '') {
return $this->getAllProjects();
}
return $projects;
}
public function getAllConstructionsProjectsParams($params = null)
{
$params = str_replace('[', '', $params);
$params = str_replace(']', '', $params);
$params = explode(',', $params);
$properties = $this->apiService->getAllProperties()['properties'];
$projects = [];
foreach ($properties as $projectConstruction) {
if ($projectConstruction['construction']['construction_step'] === '2') {
foreach ($params as $param) {
if ($projectConstruction['type'] === (int)$param)
$projects[] = $projectConstruction;
}
}
}
if ($params[0] === '') {
return $this->getConstructionProjects();
}
return $projects;
}
public function getAllFuturProjectsParams($params = null)
{
$params = str_replace('[', '', $params);
$params = str_replace(']', '', $params);
$params = explode(',', $params);
$properties = $this->apiService->getAllProperties()['properties'];
$projects = [];
foreach ($properties as $projectConstruction) {
if ($projectConstruction['construction']['construction_step'] === '1') {
foreach ($params as $param) {
if ($projectConstruction['type'] === (int)$param)
$projects[] = $projectConstruction;
}
}
}
if ($params[0] === '') {
return $this->getFuturProjects();
}
return $projects;
}
public function getAllPropertiesParams($params = null)
{
$params = str_replace('[', '', $params);
$params = str_replace(']', '', $params);
$params = explode(',', $params);
$properties = $this->apiService->getAllProperties()['properties'];
$projects = [];
foreach ($properties as $projectConstruction) {
foreach ($params as $param) {
if ($projectConstruction['type'] === (int)$param)
$projects[] = $projectConstruction;
}
}
if ($params[0] === '') {
return $properties;
}
return $projects;
}
public function getSalePropertiesParams($params = null)
{
$params = str_replace('[', '', $params);
$params = str_replace(']', '', $params);
$params = explode(',', $params);
$properties = $this->apiService->getAllProperties()['properties'];
$projects = [];
foreach ($properties as $saleProperty) {
if ($saleProperty['category'] === 1) {
foreach ($params as $param) {
if ($saleProperty['type'] === (int)$param)
$projects[] = $saleProperty;
}
}
}
if ($params[0] === '') {
return $this->getSaleProperties();
}
return $projects;
}
public function getRentalPropertiesParams($params = null)
{
$params = str_replace('[', '', $params);
$params = str_replace(']', '', $params);
$params = explode(',', $params);
$projects = [];
$properties = $this->apiService->getAllProperties()['properties'];
foreach ($properties as $rentalProperty) {
if ($rentalProperty['category'] === 2) {
foreach ($params as $param) {
if ($rentalProperty['type'] === (int)$param)
$projects[] = $rentalProperty;
}
}
}
if ($params[0] === '') {
return $this->getRentalProperties();
}
return $projects;
}
}