Index: openacs-4/packages/contacts/lib/contacts-aggregated.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/contacts-aggregated.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/contacts/lib/contacts-aggregated.tcl 14 Nov 2005 22:55:45 -0000 1.5 +++ openacs-4/packages/contacts/lib/contacts-aggregated.tcl 15 Nov 2005 15:56:46 -0000 1.6 @@ -23,27 +23,33 @@ # Get the search message set message [contact::search_pretty -search_id $search_id] +# You can aggregate for attributes that have multiple choices +# or by relationship or country. Each one of this situations +# has it's own queries to make the multirow and to get the results switch '$attr_id' { '-1' { # Search for the country in home_address # or company_addres set attr_name "[_ contacts.Country]" set query_name get_countries_options set result_query get_countries_results + set extend_result_query get_countries_extend_results set attribute_p 0 } '-2' { # Search for Relationship's set attr_name "[_ contacts.Relationship]" set query_name get_relationship_options set result_query get_relationship_results + set extend_result_query get_relationship_extend_results set attribute_p 0 } default { # Get the attribute name and the options for that attribute set attr_name [attribute::pretty_name -attribute_id $attr_id] set query_name get_attribute_options set result_query get_results + set extend_result_query get_extend_results set attribute_p 1 } } @@ -56,6 +62,9 @@ -party_id "parties.party_id" \ -revision_id "revision_id"] + +# If we are extending the result list then +# we add the element dynamically to the list set extend_pretty_name "" if { [exists_and_not_null extend_id] } { set extend_info [db_list_of_lists get_extend_name { }] @@ -72,8 +81,17 @@ $extend_var_name [list \ label "$extend_pretty_name" \ display_template { - "Query Result TODO" + + @contacts.$extend_var_name@ + + + 0.00 + }]] + + # For the db_multirow extend variables + set extend_list [list result $extend_var_name] + } else { set elements [list \ option [list \ @@ -83,9 +101,13 @@ @contacts.result@ } ]] -} + # For the db_multirow extend variables + set extend_list [list result] +} + +# We create the list template::list::create \ -name "contacts" \ -multirow contacts \ @@ -94,22 +116,43 @@ -bulk_actions "" \ -elements $elements -db_multirow -extend { result } contacts $query_name " " { + +db_multirow -extend $extend_list contacts $query_name " " { # We get the value_id here and not in the options query since # the value_id is only present when one attribute is associated # to one option, and we want to see every option. set option_string [lang::util::localize $option] if { [string equal "Contact Rel " [string range $option_string 0 11]] } { + # This is for relationships aggregation set option [string range $option_string 12 [string length $option_string]] } if { $attribute_p } { + # No country or relationship we need the value of the attribute + # To get the result set value_id [db_string get_value_id { } -default 0] } - set result "[db_string $result_query " " -default 0]" + + # Get the result for each specific situation + set result [db_string $result_query " " -default 0] + + # Get the extend_var_name value for the extend attribute + if {[exists_and_not_null extend_var_name] } { + if { [catch { set $extend_var_name [db_string $extend_result_query " " -default 0] } errMsg] } { + # We got an error so we are going to return to the user + set title "[_ contacts.extend_error_msg]" + set error_pos [string first "ERROR: " $errMsg] + set sql_pos [string first "SQL: " $errMsg] + set error [string range $errMsg [expr $error_pos + 7] [expr $sql_pos - 1]] + set sql [string range $errMsg [expr $sql_pos + 5] [string length $errMsg]] + ad_return_error $title "[_ contacts.Error]:
$error

SQL:
$sql
" + ad_script_abort + } + } } - +# This is for the display of the forms +# for the aggregate and extend options set select_options [list] foreach option [contacts::attribute::options_attribute] { @@ -131,6 +174,8 @@ } } +# We get only the options that are mapped to the search_id +# and that have the aggregate_p filed set to "t" set extend_options [db_list_of_lists get_extend_options { }] if { [string equal [llength $extend_options] 0] } {