src/Infra/Services/FilterApiService.php line 204

Open in your IDE?
  1. <?php
  2. namespace App\Infra\Services;
  3. use Symfony\Component\HttpFoundation\JsonResponse;
  4. use Symfony\Contracts\HttpClient\HttpClientInterface;
  5. class FilterApiService
  6. {
  7.     private $apiService;
  8.     public function __construct(
  9.         ApiService $apiService
  10.     )
  11.     {
  12.         $this->apiService $apiService;
  13.     }
  14.     public function getReferences()
  15.     {
  16.         $references = [];
  17.         $properties $this->apiService->getAllProperties()['properties'];
  18.         foreach ($properties as $reference) {
  19.             if ($reference['construction']['construction_step'] === '3') {
  20.                 $references[] = $reference;
  21.             }
  22.         }
  23.         usort($references,function($first,$second){
  24.             return $first['id'] < $second['id'];
  25.         });
  26.         
  27.         return $references;
  28.     }
  29.     public function getReferencesWithoutParking()
  30.     {
  31.         $references = [];
  32.         $properties $this->apiService->getAllProperties()['properties'];
  33.         foreach ($properties as $reference) {
  34.             if ($reference['type'] !== && $reference['type'] !== && $reference['category'] !== 4) {
  35.                 $references[] = $reference;
  36.             }
  37.         }
  38.         return $references;
  39.     }
  40.     public function getResidenceReferences()
  41.     {
  42.         $references = [];
  43.         $properties $this->apiService->getAllProperties()['properties'];
  44.         foreach ($properties as $reference) {
  45.             if ($reference['construction']['construction_step'] === '3' && ($reference['type'] === || $reference['type'] === 6)) {
  46.                 $references[] = $reference;
  47.             }
  48.         }
  49.         return $references;
  50.     }
  51.     public function getHouseReferences()
  52.     {
  53.         $references = [];
  54.         $properties $this->apiService->getAllProperties()['properties'];
  55.         foreach ($properties as $reference) {
  56.             if ($reference['construction']['construction_step'] === '3' && $reference['type'] === 2) {
  57.                 $references[] = $reference;
  58.             }
  59.         }
  60.         return $references;
  61.     }
  62.     public function getCommerceReferences()
  63.     {
  64.         $references = [];
  65.         $properties $this->apiService->getAllProperties()['properties'];
  66.         foreach ($properties as $reference) {
  67.             if ($reference['construction']['construction_step'] === '3' && $reference['type'] === 4) {
  68.                 $references[] = [$properties];
  69.             }
  70.         }
  71.         return $references;
  72.     }
  73.     public function getBureauxReferences()
  74.     {
  75.         $references = [];
  76.         $properties $this->apiService->getAllProperties()['properties'];
  77.         foreach ($properties as $reference) {
  78.             if ($reference['construction']['construction_step'] === '3' && $reference['type'] === 7) {
  79.                 $references[] = $reference;
  80.             }
  81.         }
  82.         return $references;
  83.     }
  84.     public function getAllProperties()
  85.     {
  86.         return $this->apiService->getAllProperties()['properties'];
  87.     }
  88.     public function getAllPropertiesForSearch()
  89.     {
  90.         $propertiesFilter = [];
  91.         $properties $this->apiService->getAllProperties()['properties'];
  92.         foreach ($properties as $property) {
  93.             if ($property['construction']['construction_step'] !== '3' ) {
  94.                 $propertiesFilter[] = $property;
  95.             }
  96.         }
  97.         return $propertiesFilter;
  98.     }
  99.     /**
  100.      * @param int $id
  101.      * @return array
  102.      *
  103.      * Julien V2
  104.      */
  105.     public function getPropertiesByCategory(?int $id)
  106.     {
  107.         $propertiesFilter = [];
  108.         $properties $this->apiService->getAllProperties()['properties'];
  109.         if (!$id) {
  110.             return $properties;
  111.         }
  112.         
  113.         foreach ($properties as $property) {
  114.             if ($property['category'] === $id && $property['type'] !== && $property['type'] !== 6) {
  115.                 $propertiesFilter[] = $property;
  116.             }
  117.         }
  118.         return $propertiesFilter;
  119.     }
  120.     public function getPropertiesForCities()
  121.     {
  122.         $projects = [];
  123.         $properties =  $this->apiService->getAllProperties()['properties'];
  124.         foreach ($properties as $saleProperty) {
  125.             if ($saleProperty['category'] === || $saleProperty['category'] === || $saleProperty['construction']['construction_step'] === '2' || $saleProperty['construction']['construction_step'] === '1') {
  126.                 $projects[] = $saleProperty;
  127.             }
  128.         }
  129.         return $projects;
  130.     }
  131.     public function getSaleProperties()
  132.     {
  133.         $projects = [];
  134.         $properties =  $this->apiService->getAllProperties()['properties'];
  135.         foreach ($properties as $saleProperty) {
  136.             if ($saleProperty['category'] === 1) {
  137.                 $projects[] = $saleProperty;
  138.             }
  139.         }
  140.         return $projects;
  141.     }
  142.     public function getChildrensOfProject($id)
  143.     {
  144.         $childprojects = [];
  145.         $properties =  $this->apiService->getAllProperties()['properties'];
  146.         foreach ($properties as $childProperty) {
  147.             if ($childProperty['parent'] === (int)$id) {
  148.                 $childprojects[] = $childProperty;
  149.             }
  150.         }
  151.         return $childprojects;
  152.     }
  153.     public function getRentalProperties()
  154.     {
  155.         $projects = [];
  156.         $properties =  $this->apiService->getAllProperties()['properties'];
  157.         foreach ($properties as $rentalProperty) {
  158.             if ($rentalProperty['category'] === 2) {
  159.                 $projects[] = $rentalProperty;
  160.             }
  161.         }
  162.         return $projects;
  163.     }
  164.     public function getAllProjects()
  165.     {
  166.         $properties $this->apiService->getAllProperties()['properties'];
  167.         $projects = [];
  168.         foreach ($properties as $projectConstruction) {
  169.             if ($projectConstruction['construction']['construction_step'] === '2' || $projectConstruction['construction']['construction_step'] === '1') {
  170.                 $projects[] = $projectConstruction;
  171.             }
  172.         }
  173.         return $projects;
  174.     }
  175.     public function getConstructionProjects()
  176.     {
  177.         $projectConstructions = [];
  178.         $properties $this->apiService->getAllProperties()['properties'];
  179.         foreach ($properties as $projectConstruction) {
  180.             if ($projectConstruction['construction']['construction_step'] === '2') {
  181.                 $projectConstructions[] = $projectConstruction;
  182.             }
  183.         }
  184.         return $projectConstructions;
  185.     }
  186.     public function getFuturProjects()
  187.     {
  188.         $projectFuturs = [];
  189.         $properties $this->apiService->getAllProperties()['properties'];
  190.         foreach ($properties as $projectFutur) {
  191.             if ($projectFutur['construction']['construction_step'] == '1') {
  192.                 $projectFuturs[] = $projectFutur;
  193.             }
  194.         }
  195.         return $projectFuturs;
  196.     }
  197.     public function getFinishProjects()
  198.     {
  199.         $projectFinishes = [];
  200.         $properties $this->apiService->getAllProperties()['properties'];
  201.         foreach ($properties as $projectFinish) {
  202.             if ($projectFinish['construction']['construction_step'] === '3') {
  203.                 $projectFinishes[] = $projectFinish;
  204.             }
  205.         }
  206.         return $projectFinishes;
  207.     }
  208.     public function getTypeProperty(string $id)
  209.     {
  210.         //dd($id);
  211.         $arrayConverter = [
  212.             => 'Immeuble',
  213.             => 'Résidence',
  214.             => 'Lotissement',
  215.             => 'Hameau',
  216.             => 'Domaine',
  217.             => 'Propriété',
  218.             => 'Rue / Avenue / Chemin …',
  219.             => 'Hôtel',
  220.         ];
  221.         return $arrayConverter[$id] ?? null;
  222.     }
  223.     public function getAreaConversion($unitId)
  224.     {
  225.         $arrayConverter = [
  226.             => 'm²',
  227.             => 'ft²',
  228.             => 'kanal',
  229.             => 'marla',
  230.             => 'yd²',
  231.             => 'acre',
  232.             => 'ha',
  233.             => 'ares',
  234.             => 'toises',
  235.             10 => 'perches',
  236.             11 => 'arpents'
  237.         ];
  238.         return $arrayConverter[$unitId] ?? null;
  239.     }
  240.     public function getPropertyCategory($categoryId)
  241.     {
  242.         $arrayConverter = [
  243.             => 'Vente',
  244.             => 'Location',
  245.             => 'Location saisonnière',
  246.             => 'Programme',
  247.             => 'Viager',
  248.             => 'Enchère'
  249.         ];
  250.         return $arrayConverter[$categoryId] ?? null;
  251.     }
  252.     public function getInversePropertyCategory($categoryId)
  253.     {
  254.         $arrayConverter = [
  255.             'Vente' => 1,
  256.             'Location' => 2,
  257.             'Location saisonnière' => 3,
  258.             'Programme' => 4,
  259.             'Viager' => 5,
  260.             'Enchère' => 6
  261.         ];
  262.         return $arrayConverter[$categoryId] ?? null;
  263.     }
  264.     public function getRegulationById($categoryId)
  265.     {
  266.         $arrayConverter = [
  267.             50 => 'DPE',
  268.             51 => 'Classe d’isolation thermique',
  269.             52 => 'GES',
  270.         ];
  271.         return $arrayConverter[$categoryId] ?? null;
  272.     }
  273.     public function getSubTypeProject($id)
  274.     {
  275.         $arrayConverter = [
  276.             => 'Appartement',
  277.             => 'Maison',
  278.             => 'Terrain',
  279.             => 'Commerce',
  280.             => 'Garage / Parking',
  281.             => 'Immeuble',
  282.             => 'Bureaux',
  283.             => 'Studio',
  284.             => 'Duplex',
  285.             10 => 'Cave / Box',
  286.             11 => 'Penthouse'
  287.         ];
  288.         return $arrayConverter[$id] ?? null;
  289.     }
  290.     public function getInverseSubTypeProject(?string $id)
  291.     {
  292.         $arrayConverter = [
  293.             'Appartement' => 1,
  294.             'Maison' => 2,
  295.             'Terrain' => 3,
  296.             'Commerce' => 4,
  297.             'Garage / Parking' => 5,
  298.             'Immeuble' => 6,
  299.             'Bureaux' => 7,
  300.             'Studio' => 8,
  301.             'Duplex' => 9,
  302.             'Cave / Box' => 10,
  303.             'Penthouse' => 11
  304.         ];
  305.         return $arrayConverter[$id] ?? null;
  306.     }
  307.     public function getInverseRealSubTypeProject(?string $id$all false)
  308.     {
  309.         $arrayConverter = [
  310.             'Appartement' => [
  311.                 'id' => 1,
  312.                 'status' => 'type'
  313.             ],
  314.             'Maison' => [
  315.                 'id' => 2,
  316.                 'status' => 'type'
  317.             ],
  318.             'Terrain' => [
  319.                 'id' => 3,
  320.                 'status' => 'type'
  321.             ],
  322.             'Commerce' => [
  323.                 'id' => 4,
  324.                 'status' => 'type'
  325.             ],
  326.             'Garage / Parking' => [
  327.                 'id' => 5,
  328.                 'status' => 'type'
  329.             ],
  330.             'Immeuble' => [
  331.                 'id' => 6,
  332.                 'status' => 'type'
  333.             ],
  334.             'Bureaux' => [
  335.                 'id' => 7,
  336.                 'status' => 'type'
  337.             ],
  338.             'Studio' => [
  339.                 'id' => 6,
  340.                 'status' => 'subtype'
  341.             ],
  342.             "Locaux d'activité / Entrepôts" => [
  343.                 'id' => 9,
  344.                 'status' => 'type'
  345.             ],
  346.             'Cave / Box' => [
  347.                 'id' => 10,
  348.                 'status' => 'type'
  349.             ],
  350.             'Penthouse' => [
  351.                 'id' => 4,
  352.                 'status' => 'subtype'
  353.             ],
  354.             'Ferme' => [
  355.                 'id' => 11,
  356.                 'status' => 'subtype'
  357.             ],
  358.             'Loft' => [
  359.                 'id' => 12,
  360.                 'status' => 'subtype'
  361.             ],
  362.             'Villa' => [
  363.                 'id' => 14,
  364.                 'status' => 'subtype'
  365.             ],
  366.             'Grange' => [
  367.                 'id' => 16,
  368.                 'status' => 'subtype'
  369.             ],
  370.             'Propriété' => [
  371.                 'id' => 19,
  372.                 'status' => 'subtype'
  373.             ],
  374.             'Ensemble immobilier' => [
  375.                 'id' => 20,
  376.                 'status' => 'subtype'
  377.             ],
  378.             'Fermette' => [
  379.                 'id' => 23,
  380.                 'status' => 'subtype'
  381.             ],
  382.             'Chambre' => [
  383.                 'id' => 28,
  384.                 'status' => 'subtype'
  385.             ],
  386.             'Hangar' => [
  387.                 'id' => 29,
  388.                 'status' => 'subtype'
  389.             ],
  390.             'Chalet' => [
  391.                 'id' => 32,
  392.                 'status' => 'subtype'
  393.             ],
  394.             'Local commercial' => [
  395.                 'id' => 33,
  396.                 'status' => 'subtype'
  397.             ],
  398.             'Fonds de commerce' => [
  399.                 'id' => 34,
  400.                 'status' => 'subtype'
  401.             ],
  402.             'Entrepôt' => [
  403.                 'id' => 41,
  404.                 'status' => 'subtype'
  405.             ],
  406.             'Parking' => [
  407.                 'id' => 43,
  408.                 'status' => 'subtype'
  409.             ],
  410.             'Hôtel' => [
  411.                 'id' => 44,
  412.                 'status' => 'subtype'
  413.             ],
  414.             'Maison jumelée' => [
  415.                 'id' => 71,
  416.                 'status' => 'subtype'
  417.             ],
  418.             'Bungalow' => [
  419.                 'id' => 72,
  420.                 'status' => 'subtype'
  421.             ],
  422.             'Lotissement' => [
  423.                 'id' => 80,
  424.                 'status' => 'subtype'
  425.             ],
  426.             'Terrain agricole' => [
  427.                 'id' => 103,
  428.                 'status' => 'subtype'
  429.             ],
  430.             'Bâtiment historique' => [
  431.                 'id' => 105,
  432.                 'status' => 'subtype'
  433.             ]
  434.         ];
  435.         if($all) return $arrayConverter;
  436.         return $arrayConverter[$id] ?? null;
  437.     }
  438.     public function arrayAllTypes()
  439.     {
  440.         return [
  441.             'Appartement' => [
  442.                 'id' => 1,
  443.                 'status' => 'type'
  444.             ],
  445.             'Maison' => [
  446.                 'id' => 2,
  447.                 'status' => 'type'
  448.             ],
  449.             'Terrain' => [
  450.                 'id' => 3,
  451.                 'status' => 'type'
  452.             ],
  453.             'Commerce' => [
  454.                 'id' => 4,
  455.                 'status' => 'type'
  456.             ],
  457.             'Garage / Parking' => [
  458.                 'id' => 5,
  459.                 'status' => 'type'
  460.             ],
  461.             'Immeuble' => [
  462.                 'id' => 6,
  463.                 'status' => 'type'
  464.             ],
  465.             'Bureaux' => [
  466.                 'id' => 7,
  467.                 'status' => 'type'
  468.             ],
  469.             'Studio' => [
  470.                 'id' => 6,
  471.                 'status' => 'subtype'
  472.             ],
  473.             "Locaux d'activité / Entrepôts" => [
  474.                 'id' => 9,
  475.                 'status' => 'type'
  476.             ],
  477.             'Cave / Box' => [
  478.                 'id' => 10,
  479.                 'status' => 'type'
  480.             ],
  481.             'Penthouse' => [
  482.                 'id' => 4,
  483.                 'status' => 'subtype'
  484.             ],
  485.             'Ferme' => [
  486.                 'id' => 11,
  487.                 'status' => 'subtype'
  488.             ],
  489.             'Loft' => [
  490.                 'id' => 12,
  491.                 'status' => 'subtype'
  492.             ],
  493.             'Villa' => [
  494.                 'id' => 14,
  495.                 'status' => 'subtype'
  496.             ],
  497.             'Grange' => [
  498.                 'id' => 16,
  499.                 'status' => 'subtype'
  500.             ],
  501.             'Propriété' => [
  502.                 'id' => 19,
  503.                 'status' => 'subtype'
  504.             ],
  505.             'Ensemble immobilier' => [
  506.                 'id' => 20,
  507.                 'status' => 'subtype'
  508.             ]
  509.         ];
  510.     }
  511.     public function getAllProjectsParams($params null)
  512.     {
  513.         $params str_replace('['''$params);
  514.         $params str_replace(']'''$params);
  515.         $params explode(','$params);
  516.         $properties $this->apiService->getAllProperties()['properties'];
  517.         $projects = [];
  518.         foreach ($properties as $projectConstruction) {
  519.             if ($projectConstruction['construction']['construction_step'] === '2' || $projectConstruction['construction']['construction_step'] === '1') {
  520.                 foreach ($params as $param) {
  521.                     if ($projectConstruction['type'] === (int)$param)
  522.                     $projects[] = $projectConstruction;
  523.                 }
  524.             }
  525.         }
  526.         if ($params[0] === '') {
  527.             return $this->getAllProjects();
  528.         }
  529.         return $projects;
  530.     }
  531.     public function getAllConstructionsProjectsParams($params null)
  532.     {
  533.         $params str_replace('['''$params);
  534.         $params str_replace(']'''$params);
  535.         $params explode(','$params);
  536.         $properties $this->apiService->getAllProperties()['properties'];
  537.         $projects = [];
  538.         foreach ($properties as $projectConstruction) {
  539.             if ($projectConstruction['construction']['construction_step'] === '2') {
  540.                 foreach ($params as $param) {
  541.                     if ($projectConstruction['type'] === (int)$param)
  542.                         $projects[] = $projectConstruction;
  543.                 }
  544.             }
  545.         }
  546.         if ($params[0] === '') {
  547.             return $this->getConstructionProjects();
  548.         }
  549.         return $projects;
  550.     }
  551.     public function getAllFuturProjectsParams($params null)
  552.     {
  553.         $params str_replace('['''$params);
  554.         $params str_replace(']'''$params);
  555.         $params explode(','$params);
  556.         $properties $this->apiService->getAllProperties()['properties'];
  557.         $projects = [];
  558.         foreach ($properties as $projectConstruction) {
  559.             if ($projectConstruction['construction']['construction_step'] === '1') {
  560.                 foreach ($params as $param) {
  561.                     if ($projectConstruction['type'] === (int)$param)
  562.                         $projects[] = $projectConstruction;
  563.                 }
  564.             }
  565.         }
  566.         if ($params[0] === '') {
  567.             return $this->getFuturProjects();
  568.         }
  569.         return $projects;
  570.     }
  571.     public function getAllPropertiesParams($params null)
  572.     {
  573.         $params str_replace('['''$params);
  574.         $params str_replace(']'''$params);
  575.         $params explode(','$params);
  576.         $properties $this->apiService->getAllProperties()['properties'];
  577.         $projects = [];
  578.         foreach ($properties as $projectConstruction) {
  579.                 foreach ($params as $param) {
  580.                     if ($projectConstruction['type'] === (int)$param)
  581.                         $projects[] = $projectConstruction;
  582.                 }
  583.         }
  584.         if ($params[0] === '') {
  585.            return $properties;
  586.         }
  587.         return $projects;
  588.     }
  589.     public function getSalePropertiesParams($params null)
  590.     {
  591.        $params str_replace('['''$params);
  592.        $params str_replace(']'''$params);
  593.        $params explode(','$params);
  594.         $properties =  $this->apiService->getAllProperties()['properties'];
  595.         $projects = [];
  596.         foreach ($properties as $saleProperty) {
  597.             if ($saleProperty['category'] === 1) {
  598.                 foreach ($params as $param) {
  599.                     if ($saleProperty['type'] === (int)$param)
  600.                         $projects[] = $saleProperty;
  601.                 }
  602.             }
  603.         }
  604.         if ($params[0] === '') {
  605.             return $this->getSaleProperties();
  606.         }
  607.         return $projects;
  608.     }
  609.     public function getRentalPropertiesParams($params null)
  610.     {
  611.         $params str_replace('['''$params);
  612.         $params str_replace(']'''$params);
  613.         $params explode(','$params);
  614.         $projects = [];
  615.         $properties =  $this->apiService->getAllProperties()['properties'];
  616.         foreach ($properties as $rentalProperty) {
  617.             if ($rentalProperty['category'] === 2) {
  618.                 foreach ($params as $param) {
  619.                     if ($rentalProperty['type'] === (int)$param)
  620.                         $projects[] = $rentalProperty;
  621.                 }
  622.             }
  623.         }
  624.         if ($params[0] === '') {
  625.             return $this->getRentalProperties();
  626.         }
  627.         return $projects;
  628.     }
  629. }