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 -N -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 {}] } Index: openacs-4/contrib/packages/classified-ads/tcl/ads-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/ads-procs.xql,v diff -u -N -r1.5 -r1.6 --- openacs-4/contrib/packages/classified-ads/tcl/ads-procs.xql 24 Jul 2003 01:14:44 -0000 1.5 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs.xql 29 Jul 2003 09:10:42 -0000 1.6 @@ -9,14 +9,17 @@ ci.item_id, cr.title, to_char(cr.publish_date, 'Mon FMDD, YYYY') as pretty_publish_date + $custom_fields from cr_item_keyword_map cm, cr_revisions cr, - cr_items ci + cr_items ci, + cr_ca_ads ads where cm.item_id = cr.item_id and ci.latest_revision = cr.revision_id and ci.parent_id = :parent_id and - ci.content_type = 'ca_ad' - $condition_stub + ci.content_type = 'ca_ad' and + cm.keyword_id = :category_id and + ci.item_id = ads.ad_id order by cm.keyword_id asc, cr.title asc Index: openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql 16 Jul 2003 04:52:32 -0000 1.1 +++ openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql 29 Jul 2003 09:10:42 -0000 1.2 @@ -97,5 +97,27 @@ + + + + SELECT + attribute_name + FROM + acs_attributes att, + ca_attribute_widget_values cawv, + ( + select + subtree.keyword_id + from cr_keywords parent, cr_keywords subtree + where parent.keyword_id = :keyword_id + and parent.tree_sortkey between subtree.tree_sortkey and tree_right(subtree.tree_sortkey) + ) keywords + WHERE + att.attribute_id = cawv.attribute_id + AND + cawv.keyword_id = keywords.keyword_id + + + Index: openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl 21 Jul 2003 05:23:56 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl 29 Jul 2003 09:10:42 -0000 1.3 @@ -191,7 +191,20 @@ return [db_exec_plsql get_path {}] } + ad_proc -public get_custom_fields { + {-keyword_id:required} + } { + Returns a list of column names of custom fields available for + this category. Either the field was assigned directly to this + category or to one of its parents. + @author Roberto Mello + @creation-date 2003-07-29 + @see classified-ads::ads::get_assigned_ads_by_category + } { + return [db_list get_fields {}] + } + ad_proc -public generate_trail { {-keyword_id:required} {-append_element} Index: openacs-4/contrib/packages/classified-ads/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/index.tcl,v diff -u -N -r1.3 -r1.4 --- openacs-4/contrib/packages/classified-ads/www/index.tcl 25 Jul 2003 23:53:20 -0000 1.3 +++ openacs-4/contrib/packages/classified-ads/www/index.tcl 29 Jul 2003 09:10:42 -0000 1.4 @@ -35,7 +35,7 @@ -var_name unassigned_ads template::util::list_of_ns_sets_to_multirow \ - -rows [classified-ads::ads::get_assigned_ads_by_category -category_id_list [list $keyword_id]] \ + -rows [classified-ads::ads::get_assigned_ads_by_category -category_id $keyword_id] \ -var_name assigned_ads set return_url "[ad_conn url]?[ad_conn query]" Index: openacs-4/contrib/packages/classified-ads/www/one-category.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/one-category.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/classified-ads/www/one-category.tcl 16 Jul 2003 04:52:32 -0000 1.1 +++ openacs-4/contrib/packages/classified-ads/www/one-category.tcl 29 Jul 2003 09:10:42 -0000 1.2 @@ -19,7 +19,7 @@ db_multirow categories select_categories {} template::util::list_of_ns_sets_to_multirow \ - -rows [classified-ads::ads::get_assigned_ads_by_category -category_id_list [list $keyword_id]] \ + -rows [classified-ads::ads::get_assigned_ads_by_category -category_id $keyword_id] \ -var_name assigned_ads #set return_url "[ad_conn url]?[ad_conn query]" Index: openacs-4/contrib/packages/classified-ads/www/admin/categories.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/categories.tcl,v diff -u -N -r1.4 -r1.5 --- openacs-4/contrib/packages/classified-ads/www/admin/categories.tcl 25 Jul 2003 23:53:20 -0000 1.4 +++ openacs-4/contrib/packages/classified-ads/www/admin/categories.tcl 29 Jul 2003 09:10:42 -0000 1.5 @@ -36,7 +36,7 @@ -var_name unassigned_ads template::util::list_of_ns_sets_to_multirow \ - -rows [classified-ads::ads::get_assigned_ads_by_category -category_id_list [list $keyword_id]] \ + -rows [classified-ads::ads::get_assigned_ads_by_category -category_id $keyword_id] \ -var_name assigned_ads set return_url "[ad_conn url]?[ad_conn query]" Index: openacs-4/contrib/packages/classified-ads/www/admin/field-addedit-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/field-addedit-postgresql.xql,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/classified-ads/www/admin/field-addedit-postgresql.xql 21 Jul 2003 16:08:07 -0000 1.1 +++ openacs-4/contrib/packages/classified-ads/www/admin/field-addedit-postgresql.xql 29 Jul 2003 09:10:42 -0000 1.2 @@ -3,14 +3,73 @@ - select ca_attributes__create_attribute (:content_type::varchar, :attribute_name::varchar, :datatype::varchar, :pretty_name::varchar, :pretty_plural::varchar, :sort_order::int4, :default_value::varchar, 'type_specific'::varchar, 'cr_ca_ads'::varchar, :column_spec::varchar, :package_id::int4) as attribute_id + + select ca_attributes__create_attribute ( + :content_type::varchar, + :attribute_name::varchar, + :datatype::varchar, + :pretty_name::varchar, + :pretty_plural::varchar, + :sort_order::int4, + :default_value::varchar, + 'type_specific'::varchar, + 'cr_ca_ads'::varchar, + :column_spec::varchar, + :package_id::int4 + ) as attribute_id + - select ca_attributes__register_widget (:attribute_id, :widget, :label, :html_options, :select_options, :validate, :optional_p) + + select ca_attributes__register_widget ( + :attribute_id, + :widget, + :label, + :keyword_id, + :html_options, + :extra_options, + :select_options, + :validate, + :optional_p, + :enabled_p + ) + + + + + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) + FROM pg_catalog.pg_attribute a, + ( + SELECT c.oid + FROM pg_catalog.pg_class c + LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace + WHERE pg_catalog.pg_table_is_visible(c.oid) + AND c.relname ~ '^cr_ca_ads$' + ) b + WHERE a.attrelid = b.oid + AND a.attname = :attribute_name + AND NOT a.attisdropped + + + + + + + + select + repeat(:indent_pattern, (tree_level(subtree.tree_sortkey) - 2) * :indent_factor::integer) || subtree.heading AS heading, + subtree.keyword_id + from cr_keywords parent, cr_keywords subtree + where subtree.tree_sortkey between parent.tree_sortkey and tree_right(parent.tree_sortkey) + and parent.parent_id = :main_category_id + + + + Index: openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.tcl 29 Jul 2003 02:03:09 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.tcl 29 Jul 2003 09:10:42 -0000 1.3 @@ -14,7 +14,7 @@ {default_value:nohtml ""} {widget:nohtml text} {label:nohtml ""} - {keyword_id:integer ""} + {keyword_id:integer 0} {html_options:nohtml ""} {select_options:nohtml ""} {validate:nohtml ""} @@ -30,6 +30,9 @@ set content_type "ca_ad" set package_id [ad_conn package_id] +set indent_pattern "-" +set indent_factor 2 +set main_category_id [classified-ads::main_keyword_exists_p] template::form create new_field @@ -44,7 +47,7 @@ set title "Edit Field" set context [list [list "fields" "Fields"] "Edit Field"] set cant_edit_html "onfocus \"blur();\" style \"background: #d3d3d3\"" - set column_spec "unknown" + set column_spec [db_string get_column_spec {}] ## Widget values db_0or1row widget_vars { } @@ -75,6 +78,20 @@ -html "size 30" \ -value $pretty_plural +# +# RBM: FIXME: We should allow adding of site-wide fields here. In order to +# realize that we need to give the main root category as argument to the user. +# Figure out how. +# + +template::element create new_field keyword_id \ + -widget select \ + -datatype integer \ + -label "Category" \ + -help_text "The category to which this new field will belong to. A category of name \"classified-ads-package-xxx\" means the main category for this package instance, and the field will be available to all its subcategories." \ + -options [db_list_of_lists categories { }] \ + -value $keyword_id + template::element create new_field datatype \ -widget select \ -datatype text \ @@ -211,7 +228,7 @@ if {![empty_string_p $extra_help_text]} { append extra_options " -help_text \"" - append extra_options $help_text + append extra_options $extra_help_text append extra_options "\"" } @@ -225,6 +242,7 @@ db_1row attribute_new { } db_1row widget_new { } } + util_memoize_flush "classified-ads::categories::get_custom_fields -keyword_id $keyword_id" } ad_returnredirect "fields" } Index: openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.xql,v diff -u -N -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.xql 21 Jul 2003 16:08:07 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.xql 29 Jul 2003 09:10:42 -0000 1.3 @@ -15,15 +15,25 @@ - select widget, label, html_options, select_options, validate, optional_p, enabled_p - from ca_attribute_widget_values - where attribute_id=:attribute_id + + select + widget, label, html_options, select_options, + validate, optional_p, enabled_p + from + ca_attribute_widget_values + where + attribute_id=:attribute_id + - select distinct datatype, datatype from acs_attributes order by datatype + + select distinct datatype, datatype + from acs_attributes + order by datatype + @@ -35,21 +45,44 @@ - select widget, widget from ca_attribute_widgets order by widget + + select widget, widget + from ca_attribute_widgets + order by widget + - update acs_attributes set pretty_name=:pretty_name, pretty_plural=:pretty_plural, sort_order=:sort_order, default_value=:default_value where attribute_id=:attribute_id + + update acs_attributes + set pretty_name = :pretty_name, + pretty_plural = :pretty_plural, + sort_order = :sort_order, + default_value = :default_value + where + attribute_id = :attribute_id + - update ca_attribute_widget_values set label=:label, html_options=:html_options, select_options=:select_options, validate=:validate, optional_p=:optional_p, enabled_p=:enabled_p where attribute_id=:attribute_id - + ` + update ca_attribute_widget_values + set label = :label, + html_options = :html_options, + select_options = :select_options, + keyword_id = :keyword_id, + extra_options = :extra_options, + validate = :validate, + optional_p = :optional_p, + enabled_p = :enabled_p + where + attribute_id = :attribute_id + + -