Initialise un deal depuis son URL

This commit is contained in:
Shikiryu 2016-08-22 23:26:49 +02:00
parent 885c5c7871
commit 50281c76f7

View File

@ -7,6 +7,70 @@ class Deal
const TYPE_OFFER = 's'; const TYPE_OFFER = 's';
const TYPE_ASK = 'k'; const TYPE_ASK = 'k';
public static $categories = [
'33' => 'Offres d\'emploi',
'2' => 'Voitures',
'3' => 'Motos',
'4' => 'Caravaning',
'5' => 'Utilitaires',
'6' => 'Equipement Auto',
'44' => 'Equipement Moto',
'50' => 'Equipement Caravaning',
'7' => 'Nautisme',
'51' => 'Equipement Nautisme',
'9' => 'Ventes immobilières',
'10' => 'Locations',
'11' => 'Colocations',
'13' => 'Bureaux & Commerces',
'12' => 'Locations & Gîtes',
'67' => 'Chambres d\'hôtes',
'68' => 'Campings',
'69' => 'Hôtels',
'70' => 'Hébergements insolites',
'15' => 'Informatique',
'43' => 'Consoles & Jeux vidéo',
'16' => 'Image & Son',
'17' => 'Téléphonie',
'19' => 'Ameublement',
'20' => 'Electroménager',
'45' => 'Arts de la table',
'39' => 'Décoration',
'46' => 'Linge de maison',
'21' => 'Bricolage',
'52' => 'Jardinage',
'22' => 'Vêtements',
'53' => 'Chaussures',
'47' => 'Accessoires & Bagagerie',
'42' => 'Montres & Bijoux',
'23' => 'Equipement bébé',
'54' => 'Vêtements bébé',
'25' => 'DVD / Films',
'26' => 'CD / Musique',
'27' => 'Livres',
'28' => 'Animaux',
'55' => 'Vélos',
'29' => 'Sports & Hobbies',
'30' => 'Instruments de musique',
'40' => 'Collection',
'41' => 'Jeux & Jouets',
'48' => 'Vins & Gastronomie',
'57' => 'Matériel Agricole',
'58' => 'Transport - Manutention',
'59' => 'BTP - Chantier Gros-oeuvre',
'60' => 'Outillage - Matériaux 2nd-oeuvre',
'32' => 'Équipements Industriels',
'61' => 'Restauration - Hôtellerie',
'62' => 'Fournitures de Bureau',
'63' => 'Commerces & Marchés',
'64' => 'Matériel Médical',
'34' => 'Prestations de services',
'35' => 'Billetterie',
'49' => 'Evénements',
'36' => 'Cours particuliers',
'65' => 'Covoiturage',
'38' => 'Autres',
];
/** @var Account */ /** @var Account */
protected $account; protected $account;
/** @var int */ /** @var int */
@ -39,8 +103,24 @@ class Deal
{ {
$client = $account->getClient(); $client = $account->getClient();
$crawler = $client->request('GET', $url); $crawler = $client->request('GET', $url);
$deal = new self(); $deal = new self($crawler->filter('[data-savead-id]')->attr('data-savead-id'));
$deal->setAccount($account);
$deal->setSubject($crawler->filter('.item_imageCaption')->first()->text());
$deal->setCategory(array_search($crawler->filter('.breadcrumbsNav >ul >li')->eq(2)->text(), self::$categories));
$deal->setType(self::TYPE_OFFER);
$deal->setBody($crawler->filter('.properties_description')->first()->filter('p')->eq(1)->text());
$deal->setPrice($crawler->filter('[itemprop=price]')->first()->attr('content'));
$images = $crawler->filter('[data-popin-content]')->each(
function ($node, $i) {
return [ sprintf('setImage%s', $i) => $node->attr('data-popin-content')];
}
);
foreach ($images as $image) {
foreach ($image as $method => $uri) {
$deal->$method(sprintf('http:%s', $uri));
}
}
return $deal;
} }
/** /**
@ -205,6 +285,21 @@ class Deal
return $this; return $this;
} }
/**
* @return Account
*/
public function getAccount()
{
return $this->account;
}
/**
* @param Account $account
* @return Deal
*/
public function setAccount($account)
{
$this->account = $account;
return $this;
}
} }