osclass / Osclass

With Osclass, get your own classifieds site for free. Build your own Osclass installation and start advertising real estate, jobs or whatever you want- in minutes!
http://osclass.org/
647 stars 343 forks source link

Test if a city, region or country have items in one specific category #1218

Closed groomain closed 10 years ago

groomain commented 10 years ago

Hi,

I haven't find any function to do this.

Actually I'm using listCities and listRegions to find a city or region with item but I can't test easily if my region or city have at least one item in a specific category.

Maybe somebody have an hack.

Thanks

conejoninja commented 10 years ago

It depends on what do you want to achieve, but there's no specific function for that, you could create a SQL query that retrieve said information. Which will be the best (and fastest) solution.

You could also use "osc_query_item" for example

$items = osc_query_item(array(
'category_name' => 'cars',
'region' => 'Madrid',
'results_per_page' => 1
))

osc_query_item return item data, results_per_page is there to limit the number to 1, if it's not set, it will return 10 (default, or whatever you have configured in your admin as default number of items per search).

Later, you should check if $items is empty (no results) or it has some results in it

groomain commented 10 years ago

Thanks. It's a shame that this function doesn't use Search parameters (sCategory, sCity, sRegion...) :)

For other users : osc_query_item don't return anything but export an array to the view named customItem.

To use it, you need to do this.

$items = osc_query_item(array(
    'category_name' => 'cars',
    'city_name' => 'New York',
    'results_per_page' => 1
));
$result = View::newInstance()->_get('customItems');
if (empty($result)) {
        // DO SOMETHING
}