Index: openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl 25 Jul 2003 02:39:38 -0000 1.9 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl 29 Jul 2003 09:10:42 -0000 1.10 @@ -121,33 +121,38 @@ ad_proc -public classified-ads::ads::get_assigned_ads_by_category { - {-category_id_list ""} + {-category_id ""} } { - Gets all the ads assigned to categories + Gets all the ads assigned to a category (or all categories in a package.) - @param category_id_list A list of category ids. - The system returns all ads mapped to these categories, or - all ads if no category is passed. + @param category_id The system returns all ads mapped to these categories, or + all ads if no category is passed. + + @author Roberto Mello } { - # DEDS: FIXME - this uses a subselect. this will get inefficient - # when faced with a large db. optimize this. + set parent_id [classified-ads::get_folder_id -package_id [ad_conn package_id]] + # - # RBM: I think Deds was referring to the IN clause. It will get - # slow if there are lots of items in the list, but that - # doesn't seem to be the case. I made a small optimization - # to use 'and keyword_id = x' when opnly one category is - # passed. + # If no category passed, use the package category + # - set condition_stub "" - set n_categories [llength $category_id_list] + if {[empty_string_p $category_id]} { + set category_id [classified-ads::categories::package_category_exists_p] + } - if { $n_categories == 1 } { - set condition_stub "and keyword_id = [lindex $category_id_list 0]" - } elseif { $n_categories > 1 } { - set condition_stub "and keyword_id in ([join $category_id_list ", "])" + # + # Get custom fields for this category. + # + + set custom_fields_list [util_memoize "classified-ads::categories::get_custom_fields -keyword_id $category_id"] + set custom_fields "" + + if {[llength $custom_fields_list] > 0} { + foreach field $custom_fields_list { + append custom_fields ", ads.$field" + } } - set parent_id [classified-ads::get_folder_id -package_id [ad_conn package_id]] return [db_list_of_ns_sets select_ads {}] }