Jump to content


Photo

concatenated filters


  • Please log in to reply
1 reply to this topic

#1 diegonella

diegonella

    Jr. Member

  • Members
  • PipPip
  • 26 posts
  • 1

  • LocationBuenos Aires, Argentina

Posted 08 June 2012 - 04:25 PM





I want to make a filter with concatenated criteria for cars

for example
brand: Ford, Chevrolet, Fiat
models: Mustang, Corvette, Fiat 500
year: 1980, 2001, 2003
and clicking at Ford, in models should only be Mustang

Each car is loaded as a subpage of Cars and the search criteria are fields page

Similar to Refine search from
http://motors.shop.e...com/6001/i.html

thanks


#2 ryan

ryan

    Hero Member

  • Administrators
  • 5,985 posts
  • 3387

  • LocationAtlanta, GA

Posted 11 June 2012 - 01:27 PM

There are a number of ways to do this, but for the purposes of an example, lets look at your first one: Brand.

Lets say you've got your brands as pages here:

/brands/acura/
/brands/audi/
/brands/ford/
...etc.

Your search form might look like this:

$checkedBrands = $input->whitelist('brands'); 
if(!is_array($checkedBrands)) $checkedBrands = array();

foreach($pages->get('/brands/')->children as $brand) {
  if(in_array($brand->id, $checkedBrands)) $checked = " checked='checked'";
  echo "<label><input type='checkbox' name='brands[]' value='{$brand->id}' $checked> {$brand->title}</label>"; 
}

And your search processor might look like this:

$selector = ''; 

if(is_array($input->get->brands)) {
  $brands = array();
  foreach($input->get->brands as $brand) $brands[] = (int) $brand; 
  $input->whitelist('brands', $brands); 
  if(count($brands)) $selector .= "brands=" . implode('|', $brands) . ", ";
}

$vehicles = $pages->find("template=vehicle, $selector"); 

Now when it comes to showing something like models, you'd either want the models to have a page reference selecting a brand they relate to, or you'd want to make the models children of the brand. That should make it fairly easy to determine your models once you know the brands:

$models = new PageArray();
foreach($brands as $brand) {
  $models->import($pages->get((int) $brand)->children); 
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users