diff --git a/bridges/LeBonCoinBridge.php b/bridges/LeBonCoinBridge.php index 295a188c..b3204616 100644 --- a/bridges/LeBonCoinBridge.php +++ b/bridges/LeBonCoinBridge.php @@ -8,8 +8,8 @@ class LeBonCoinBridge extends BridgeAbstract { const PARAMETERS = array( array( - 'k' => array('name' => 'Mot Clé'), - 'r' => array( + 'keywords' => array('name' => 'Mots-Clés'), + 'region' => array( 'name' => 'Région', 'type' => 'list', 'values' => array( @@ -42,8 +42,114 @@ class LeBonCoinBridge extends BridgeAbstract { 'Réunion' => '26' ) ), - 'cities' => array('name' => 'Ville'), - 'c' => array( + 'department' => array( + 'name' => 'Département', + 'type' => 'list', + 'values' => array( + '' => '', + 'Ain' => '1', + 'Aisne' => '2', + 'Allier' => '3', + 'Alpes-de-Haute-Provence' => '4', + 'Hautes-Alpes' => '5', + 'Alpes-Maritimes' => '6', + 'Ardèche' => '7', + 'Ardennes' => '8', + 'Ariège' => '9', + 'Aube' => '10', + 'Aude' => '11', + 'Aveyron' => '12', + 'Bouches-du-Rhône' => '13', + 'Calvados' => '14', + 'Cantal' => '15', + 'Charente' => '16', + 'Charente-Maritime' => '17', + 'Cher' => '18', + 'Corrèze' => '19', + 'Corse-du-Sud' => '2A', + 'Haute-Corse' => '2B', + 'Côte-d\'Or' => '21', + 'Côtes-d\'Armor' => '22', + 'Creuse' => '23', + 'Dordogne' => '24', + 'Doubs' => '25', + 'Drôme' => '26', + 'Eure' => '27', + 'Eure-et-Loir' => '28', + 'Finistère' => '29', + 'Gard' => '30', + 'Haute-Garonne' => '31', + 'Gers' => '32', + 'Gironde' => '33', + 'Hérault' => '34', + 'Ille-et-Vilaine' => '35', + 'Indre' => '36', + 'Indre-et-Loire' => '37', + 'Isère' => '38', + 'Jura' => '39', + 'Landes' => '40', + 'Loir-et-Cher' => '41', + 'Loire' => '42', + 'Haute-Loire' => '43', + 'Loire-Atlantique' => '44', + 'Loiret' => '45', + 'Lot' => '46', + 'Lot-et-Garonne' => '47', + 'Lozère' => '48', + 'Maine-et-Loire' => '49', + 'Manche' => '50', + 'Marne' => '51', + 'Haute-Marne' => '52', + 'Mayenne' => '53', + 'Meurthe-et-Moselle' => '54', + 'Meuse' => '55', + 'Morbihan' => '56', + 'Moselle' => '57', + 'Nièvre' => '58', + 'Nord' => '59', + 'Oise' => '60', + 'Orne' => '61', + 'Pas-de-Calais' => '62', + 'Puy-de-Dôme' => '63', + 'Pyrénées-Atlantiques' => '64', + 'Hautes-Pyrénées' => '65', + 'Pyrénées-Orientales' => '66', + 'Bas-Rhin' => '67', + 'Haut-Rhin' => '68', + 'Rhône' => '69', + 'Haute-Saône' => '70', + 'Saône-et-Loire' => '71', + 'Sarthe' => '72', + 'Savoie' => '73', + 'Haute-Savoie' => '74', + 'Paris' => '75', + 'Seine-Maritime' => '76', + 'Seine-et-Marne' => '77', + 'Yvelines' => '78', + 'Deux-Sèvres' => '79', + 'Somme' => '80', + 'Tarn' => '81', + 'Tarn-et-Garonne' => '82', + 'Var' => '83', + 'Vaucluse' => '84', + 'Vendée' => '85', + 'Vienne' => '86', + 'Haute-Vienne' => '87', + 'Vosges' => '88', + 'Yonne' => '89', + 'Territoire de Belfort' => '90', + 'Essonne' => '91', + 'Hauts-de-Seine' => '92', + 'Seine-Saint-Denis' => '93', + 'Val-de-Marne' => '94', + 'Val-d\'Oise' => '95' + ) + ), + 'cities' => array( + 'name' => 'Villes', + 'title' => 'Codes postaux séparés par des virgules' + ), + 'category' => array( 'name' => 'Catégorie', 'type' => 'list', 'values' => array( @@ -52,7 +158,7 @@ class LeBonCoinBridge extends BridgeAbstract { 'Emploi et recrutement' => '71', 'Offres d\'emploi et jobs' => '33' ), - 'VEHICULES' => array( + 'VÉHICULES' => array( 'Tous' => '1', 'Voitures' => '2', 'Motos' => '3', @@ -79,7 +185,7 @@ class LeBonCoinBridge extends BridgeAbstract { 'Hôtels' => '69', 'Hébergements insolites' => '70' ), - 'MULTIMEDIA' => array( + 'MULTIMÉDIA' => array( 'Tous' => '14', 'Informatique' => '15', 'Consoles & Jeux vidéo' => '43', @@ -99,7 +205,7 @@ class LeBonCoinBridge extends BridgeAbstract { 'Jeux & Jouets' => '41', 'Vins & Gastronomie' => '48' ), - 'MATERIEL PROFESSIONNEL' => array( + 'MATÉRIEL PROFESSIONNEL' => array( 'Tous' => '56', 'Matériel Agricole' => '57', 'Transport - Manutention' => '58', @@ -115,14 +221,14 @@ class LeBonCoinBridge extends BridgeAbstract { 'Tous' => '31', 'Prestations de services' => '34', 'Billetterie' => '35', - 'Evénements' => '49', + 'Événements' => '49', 'Cours particuliers' => '36', 'Covoiturage' => '65' ), 'MAISON' => array( 'Tous' => '18', 'Ameublement' => '19', - 'Electroménager' => '20', + 'Électroménager' => '20', 'Arts de la table' => '45', 'Décoration' => '39', 'Linge de maison' => '46', @@ -132,19 +238,92 @@ class LeBonCoinBridge extends BridgeAbstract { 'Chaussures' => '53', 'Accessoires & Bagagerie' => '47', 'Montres & Bijoux' => '42', - 'Equipement bébé' => '23', + 'Équipement bébé' => '23', 'Vêtements bébé' => '54', ), 'AUTRES' => '37' ) ), - 'o' => array( + 'pricemin' => array( + 'name' => 'Prix min', + 'type' => 'number' + ), + 'pricemax' => array( + 'name' => 'Prix max', + 'type' => 'number' + ), + 'estate' => array( + 'name' => 'Type de bien', + 'type' => 'list', + 'values' => array( + '' => '', + 'Maison' => '1', + 'Appartement' => '2', + 'Terrain' => '3', + 'Parking' => '4', + 'Autre' => '5' + ) + ), + 'roomsmin' => array( + 'name' => 'Pièces min', + 'type' => 'number' + ), + 'roomsmax' => array( + 'name' => 'Pièces max', + 'type' => 'number' + ), + 'squaremin' => array( + 'name' => 'Surface min', + 'type' => 'number' + ), + 'squaremax' => array( + 'name' => 'Surface max', + 'type' => 'number' + ), + 'mileagemin' => array( + 'name' => 'Kilométrage min', + 'type' => 'number' + ), + 'mileagemax' => array( + 'name' => 'Kilométrage max', + 'type' => 'number' + ), + 'yearmin' => array( + 'name' => 'Année min', + 'type' => 'number' + ), + 'yearmax' => array( + 'name' => 'Année max', + 'type' => 'number' + ), + 'cubiccapacitymin' => array( + 'name' => 'Cylindrée min', + 'type' => 'number' + ), + 'cubiccapacitymax' => array( + 'name' => 'Cylindrée max', + 'type' => 'number' + ), + 'fuel' => array( + 'name' => 'Énergie', + 'type' => 'list', + 'values' => array( + '' => '', + 'Essence' => '1', + 'Diesel' => '2', + 'GPL' => '3', + 'Électrique' => '4', + 'Hybride' => '6', + 'Autre' => '5' + ) + ), + 'owner' => array( 'name' => 'Vendeur', 'type' => 'list', 'values' => array( 'Tous' => '', 'Particuliers' => 'private', - 'Professionnels' => 'pro', + 'Professionnels' => 'pro' ) ) ) @@ -152,6 +331,25 @@ class LeBonCoinBridge extends BridgeAbstract { public static $LBC_API_KEY = 'ba0c2dad52b3ec'; + private function getRange($field, $range_min, $range_max){ + + if(!is_null($range_min) + && !is_null($range_max) + && $range_min > $range_max) { + returnClientError('Min-' . $field . ' must be lower than max-' . $field . '.'); + } + + if(!is_null($range_min) + && is_null($range_max)) { + returnClientError('Max-' . $field . ' is needed when min-' . $field . ' is setted (range).'); + } + + return array( + 'min' => $range_min, + 'max' => $range_max + ); + } + public function collectData(){ $url = 'https://api.leboncoin.fr/finder/search/'; @@ -225,11 +423,21 @@ class LeBonCoinBridge extends BridgeAbstract { private function buildRequestJson() { $requestJson = new StdClass(); - $requestJson->owner_type = $this->getInput('o'); + $requestJson->owner_type = $this->getInput('owner'); $requestJson->filters->location = array(); - if($this->getInput('r') != '') { - $requestJson->filters->location['regions'] = [$this->getInput('r')]; + + $requestJson->filters->keywords = array( + 'text' => $this->getInput('keywords') + ); + + if($this->getInput('region') != '') { + $requestJson->filters->location['regions'] = [$this->getInput('region')]; } + + if($this->getInput('department') != '') { + $requestJson->filters->location['departments'] = [$this->getInput('department')]; + } + if($this->getInput('cities') != '') { $requestJson->filters->location['city_zipcodes'] = array(); @@ -244,12 +452,82 @@ class LeBonCoinBridge extends BridgeAbstract { } $requestJson->filters->category = array( - 'id' => $this->getInput('c') + 'id' => $this->getInput('category') ); - $requestJson->filters->keywords = array( - 'text' => $this->getInput('k') - ); + if($this->getInput('pricemin') != '' + || $this->getInput('pricemax') != '') { + + $requestJson->filters->ranges->price = $this->getRange( + 'price', + $this->getInput('pricemin'), + $this->getInput('pricemax') + ); + + } + + if($this->getInput('estate') != '') { + $requestJson->filters->enums['real_estate_type'] = [$this->getInput('estate')]; + } + + if($this->getInput('roomsmin') != '' + || $this->getInput('roomsmax') != '') { + + $requestJson->filters->ranges->rooms = $this->getRange( + 'rooms', + $this->getInput('roomsmin'), + $this->getInput('roomsmax') + ); + + } + + if($this->getInput('squaremin') != '' + || $this->getInput('squaremax') != '') { + + $requestJson->filters->ranges->square = $this->getRange( + 'square', + $this->getInput('squaremin'), + $this->getInput('squaremax') + ); + + } + + if($this->getInput('mileagemin') != '' + || $this->getInput('mileagemax') != '') { + + $requestJson->filters->ranges->mileage = $this->getRange( + 'mileage', + $this->getInput('mileagemin'), + $this->getInput('mileagemax') + ); + + } + + if($this->getInput('yearmin') != '' + || $this->getInput('yearmax') != '') { + + $requestJson->filters->ranges->regdate = $this->getRange( + 'year', + $this->getInput('yearmin'), + $this->getInput('yearmax') + ); + + } + + if($this->getInput('cubiccapacitymin') != '' + || $this->getInput('cubiccapacitymax') != '') { + + $requestJson->filters->ranges->cubic_capacity = $this->getRange( + 'cubic_capacity', + $this->getInput('cubiccapacitymin'), + $this->getInput('cubiccapacitymax') + ); + + } + + if($this->getInput('fuel') != '') { + $requestJson->filters->enums['fuel'] = [$this->getInput('fuel')]; + } $requestJson->limit = 30; @@ -257,6 +535,4 @@ class LeBonCoinBridge extends BridgeAbstract { } - - }