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/
649 stars 342 forks source link

Category filtered listings #862

Closed lamas525 closed 11 years ago

lamas525 commented 11 years ago

Hi guys.. its me agains.. i am sorry for my issues.. but i dont know how do it.. so i am trying to find some help here.. I am trying to do feature to my classfield.. on main page i have 6 listings.. this listings using same code as Latest ads on default main page.. it isnt problem.. its work great.. but i need listings filtered by 2 main categories.. on right side it will be 6 listing from category "DVD" and their subcategories.. and on left side will be another category with their subcategories...

What is best way to do it easy and right? New function to hItems.php? I tried to use osc_query_item('category_name=cars,houses') but in while it doesnt worked.. Thanks if you will help me

lamas525 commented 11 years ago

with osc_has_custom_items() it works .. thanks for your work guys.. sorry guys for another issue..

EDIT: I need help with another function..when i am using:

<?php popular_ads_start(); osc_query_item(array( 'category_name' => 'dvd', 'results_per_page' => '8' )); while ( osc_has_custom_items() ) { bender_draw_item_main_page(); } popular_ads_end(); ?>

its doesnt work.. its publish listing.. its all great.. but popular_ads_start should sort listing from Highest views to lowest.. with while ( osc_has_items() ) { it works... but i need filter listing by category... :( problem is in function popular_ads_start() but i dont know where... I tryied so much .. but still it doesnt work... i will love you if you will help me.. popular_ads_start() is from plugin popular_ads.. its expirated plugin and i moved this 2 functions from this plugin to function.php i theme..

function popular_ads_start() {

    $num_ads = 8; // SETS HOW MANY POPULAR ADS TO DISPLAY
    $view_count = null;
    $index = null;

    $conn = getConnection();
    $results=$conn->osc_dbFetchResults("SELECT fk_i_item_id, i_num_views FROM %st_item_stats ORDER BY fk_i_item_id ASC", DB_TABLE_PREFIX);

    if(count($results)>0){
    foreach($results as $result){
      if(!isset($result['fk_i_item_id']) ) {
         $result['fk_i_item_id'] = null;
     }
        $view_count[$result['fk_i_item_id']] += ($result['i_num_views']); // Add-up all item views stored in database
  }

    arsort($view_count); // sorts array by highest number of item views first

    foreach($view_count as $item_id=>$views)
    {
        $result=$conn->osc_dbFetchResult("SELECT fk_i_user_id, fk_i_category_id, dt_pub_date, dt_mod_date, f_price, b_active, i_price, fk_c_currency_code, b_premium, s_secret FROM %st_item WHERE pk_i_id = %d", DB_TABLE_PREFIX, $item_id); //Get active status of item

        if($result['b_active']==1){ //if active...
            //echo 'Item ID: '.$item_id.' Views: '.$views.'<br>'; // display only if item is active
        $index++;

        // get description
            $desc=$conn->osc_dbFetchResult("SELECT fk_c_locale_code, s_title, s_description FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id); //Get active status of item
            $location=$conn->osc_dbFetchResult("SELECT fk_c_country_code, s_country, fk_i_region_id, s_region, fk_i_city_id, s_city FROM %st_item_location WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id); //Get active status of item

        // store the data in an array...
        $item_array[] =   array('fk_i_user_id'=>$result['fk_i_user_id'],
                    'fk_i_category_id'=>$result['fk_i_category_id'],
                    'dt_pub_date'=>$result['dt_pub_date'],
                    'dt_mod_date'=>$result['dt_mod_date'],
                    'f_price'=>$result['f_price'],
                    'fk_i_item_id'=>$item_id,
                    'pk_i_id'=>$item_id,
                    'b_active'=>$result['b_active'],
                    'i_price'=>$result['i_price'],
                    'fk_c_currency_code'=>$result['fk_c_currency_code'],
                    'b_premium'=>$result['b_premium'],
                    'fk_c_locale_code'=>$desc['fk_c_locale_code'],
                    's_title'=>$desc['s_title'],
                    's_description'=>$desc['s_description'],
                    'fk_c_country_code'=>$location['fk_c_country_code'],
                    's_country'=>$location['s_country'],
                    'fk_i_region_id'=>$location['fk_i_region_id'],
                    's_region'=>$location['s_region'],
                    'fk_i_city_id'=>$location['fk_i_city_id'],
                    's_city'=>$location['s_city'],
                    's_secret'=>$result['s_secret'],
                    'locale'=>array('en_US'=>array('fk_i_item_id'=>$item_id,
                                    'fk_c_locale_code'=>$desc['fk_c_locale_code'],
                                    's_title'=>$desc['s_title'],
                                    's_description'=>$desc['s_description']
                                    )
                            )               
                    );
            }
        if($index>=$num_ads) break; // limit number of ads to display
    }

    GLOBAL $stored_items;
    $stored_items = View::newInstance()->_get('item') ; //save existing item array
    View::newInstance()->_exportVariableToView('items', $item_array);

    } else echo 'No Results.';
}
}

if( !function_exists('popular_ads_end') ) {
function popular_ads_end(){
GLOBAL $stored_items;
   View::newInstance()->_exportVariableToView('items', $stored_items); //restore original item array
}
}

Maybe is that bad way.. i dont know.. maybe is easier to sort data from osc_query_item??

conejoninja commented 11 years ago

with osc_query_item you're overwritten the search made at popular_ads_start

Maybe you should try with something like this

$mySearch = new Search(); $mySearch->addFiels("SUM(".DB_TABLE_PREFIX."t_item_stats.i_num_views) as total_views"); $mySearch->addCategory('dvd'); //category $mySearch->set_rpp(8); //results per page $mySearch->addTable(DB_TABLE_PREFIX."t_item_stats") $mySearch->addConditions(DB_TABLE_PREFIX."t_item_stats.fk_i_item_id = ".DB_TABLE_PREFIX."t_item.pk_i_id"); $mySearch->order("i_num_views", "DESC", DB_TABLE_PREFIX."t_item_stats"); $mySearch->groupBy(DB_TABLE_PREFIX."t_item_stats.fk_i_item_id"); View::newInstance()->_exportVariableToView("customItems", $mySearch->doSearch());

while ( osc_has_custom_items() ) { bender_draw_item_main_page(); }

WARNING: this need to be done nesting two or more SQL, so it probably don't work and you'll have to make the query by hand, but try that first

lamas525 commented 11 years ago

i will try this.. ty.. ye i know i overwritten it.. but i didnt know to make it right so i tryied to ask for help here.. i will try it.. thanks

EDIT: ye.. you had here some errors... $mySearch->addTable(DB_TABLE_PREFIX."t_item_stats") missed ; addFiels doesnt exist.. so i changed to addField (cuz i think you meaned this) and groupBy is only in this $this->groupBy .. so i thought you wanted addGroupBy so i fixed this .. but finaly.. its unsorted (but filtered by category etc.) items.. but unsorted and sometimes is item with 3 views first.. sometimes last.. so order is random... but thanks you for your work what you doing for me.. its nice..

I really dont see some errors.. and nothing in debug log (logging PHP and SQL as well) any idea?