Skip to content

Commit

Permalink
Added featured items in the result list.
Browse files Browse the repository at this point in the history
  • Loading branch information
b4oshany committed Nov 4, 2015
1 parent 0233222 commit 716bb9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
15 changes: 8 additions & 7 deletions demo/demo4.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
use Dubizzle\Search;

$params = array(
"country" => 'all',
"country" => 'uae',
"city" => 'all',
"section" => 'motors',
"category" => 'cars',
"make" => 'audi',
"model" => '1187', //A4
"body_type"=>'348', //Sedan
"min_year" => '2005',
"max_year" => '2005',
"num_results" => 'all');
"make" => 'chevrolet',
"model" => '1239', //Corvette
"body_type"=>'347', //Coupe
"min_year" => '2011',
"max_year" => '2011',
"num_results" => '100',
"added_days"=>'');

$uae = new Search($params, 50);
echo $uae->query_url();
Expand Down
15 changes: 13 additions & 2 deletions src/Dubizzle/Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ private static function parse_items($items){
$results = [];
foreach($items as $item){
$title = $item->find('.title a')[0];
if(empty($title)){
$title = $item->find('.featured-ad-title a')[0];
}
try{
$item_data = [
"title" => $title->text,
Expand Down Expand Up @@ -128,10 +131,18 @@ public function fetch(){

# Get all the cars on a single result page.
$items = $this->dom->find(".listing-item");
if(empty($items)){
if(!empty($items)){
$this->results = static::parse_items($items);
}
$featured_items = $this->dom->find(".featured-item");
if(!empty($featured_items)){
$this->results = array_merge($this->results,
static::parse_items($featured_items));
}
if(empty($this->results)){
return [];
}
$this->results = static::parse_items($items);

$num_results_on_page = count($items);

# Get the total number of pages.
Expand Down

0 comments on commit 716bb9a

Please sign in to comment.