Index: openacs-4/packages/contacts/contacts.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/contacts.info,v diff -u -r1.49 -r1.50 --- openacs-4/packages/contacts/contacts.info 14 Nov 2005 22:55:44 -0000 1.49 +++ openacs-4/packages/contacts/contacts.info 15 Nov 2005 15:56:45 -0000 1.50 @@ -7,14 +7,14 @@ f f - + Matthew Geddert This application lets you collaboratively view, edit and categorize contacts. - 2005-11-14 + 2005-11-15 Contacts is an application for managing all those people and or organization you need to keep track of. It has a complete UI for storing and categorizing contacts. Each contact can have an arbitrary number of custom attributes associated with it, including other contacts (i.e. a certain contact "belongs" to a certain organization). It also functions as a service contract provider for attributes related to users in your system 0 - + Index: openacs-4/packages/contacts/catalog/contacts.en_US.ISO-8859-1.xml =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/catalog/contacts.en_US.ISO-8859-1.xml,v diff -u -r1.49 -r1.50 --- openacs-4/packages/contacts/catalog/contacts.en_US.ISO-8859-1.xml 14 Nov 2005 22:55:45 -0000 1.49 +++ openacs-4/packages/contacts/catalog/contacts.en_US.ISO-8859-1.xml 15 Nov 2005 15:56:46 -0000 1.50 @@ -141,6 +141,7 @@ exists at least exists at most Extend Option # %extend_id% deleted. + The "Extended Query" return an error Extend result list by extended by: Extended Search Options 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] } { Index: openacs-4/packages/contacts/lib/contacts-aggregated.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/contacts-aggregated.xql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/contacts/lib/contacts-aggregated.xql 14 Nov 2005 22:55:45 -0000 1.4 +++ openacs-4/packages/contacts/lib/contacts-aggregated.xql 15 Nov 2005 15:56:46 -0000 1.5 @@ -174,4 +174,96 @@ + + + $extend_subquery + and party_id in ( + select + parties.party_id + from + parties + left join organizations on (parties.party_id = organizations.organization_id) + left join cr_items on (parties.party_id = cr_items.item_id) + left join cr_revisions on (cr_items.latest_revision = cr_revisions.revision_id ), + group_distinct_member_map + where parties.party_id = group_distinct_member_map.member_id + $search_clause + ) + and parties.party_id in ( + select + distinct + p.party_id + from + ams_attribute_values a, + cr_items i, + parties p + where + a.object_id = i.latest_revision and + i.item_id = p.party_id + and a.value_id = $value_id ) + + + + + + + $extend_subquery + and party_id in ( + select + parties.party_id + from + parties + left join organizations on (parties.party_id = organizations.organization_id) + left join cr_items on (parties.party_id = cr_items.item_id) + left join cr_revisions on (cr_items.latest_revision = cr_revisions.revision_id ), + group_distinct_member_map + where parties.party_id = group_distinct_member_map.member_id + $search_clause + ) + and parties.party_id in ( + select + p.party_id + from + parties p, + ams_attribute_values a, + postal_addresses pa, + cr_items i, + cr_revisions r + where + i.item_id = p.party_id + and r.revision_id = i.latest_revision + and r.revision_id = a.object_id + and a.value_id = pa.address_id + and pa.country_code = :iso + ) + + + + + + $extend_subquery + and party_id in ( + select + t.party_id + from + ( + select + distinct + CASE WHEN r.object_id_one = parties.party_id + THEN r.object_id_one + ELSE r.object_id_two END as party_id + from + acs_rels r + where + r.rel_type = :rel_type + ) t, + cr_items ci, + cr_revisions cr + where + t.party_id = ci.item_id + and ci.latest_revision = cr.revision_id + $search_clause ) + + + Index: openacs-4/packages/contacts/lib/contacts.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/contacts.tcl,v diff -u -r1.32 -r1.33 --- openacs-4/packages/contacts/lib/contacts.tcl 14 Nov 2005 20:46:26 -0000 1.32 +++ openacs-4/packages/contacts/lib/contacts.tcl 15 Nov 2005 15:56:46 -0000 1.33 @@ -40,7 +40,9 @@ # Is to allow extend the list by any extend_options defined in contact_extend_options set available_options [concat \ [list [list "- - - - - - - -" ""]] \ - [contact::extend::get_options -ignore_extends $extend_values -search_id $search_id]] + [contact::extend::get_options \ + -ignore_extends $extend_values \ + -search_id $search_id -aggregated_p "f"]] ad_form -name extend -form { {extend_option:text(select),optional Index: openacs-4/packages/contacts/lib/contacts.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/contacts.xql,v diff -u -r1.15 -r1.16 --- openacs-4/packages/contacts/lib/contacts.xql 14 Nov 2005 20:42:03 -0000 1.15 +++ openacs-4/packages/contacts/lib/contacts.xql 15 Nov 2005 15:56:46 -0000 1.16 @@ -40,11 +40,14 @@ select - extend_id + csem.extend_id from - contact_search_extend_map + contact_search_extend_map csem, + contact_extend_options ceo where - search_id = :search_id + ceo.extend_id = csem.extend_id + and ceo.aggregated_p = 'f' + and csem.search_id = :search_id Index: openacs-4/packages/contacts/tcl/contact-extend-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contact-extend-procs-postgresql.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/contacts/tcl/contact-extend-procs-postgresql.xql 14 Nov 2005 22:55:45 -0000 1.2 +++ openacs-4/packages/contacts/tcl/contact-extend-procs-postgresql.xql 15 Nov 2005 15:56:46 -0000 1.3 @@ -47,7 +47,8 @@ extend_id from contact_extend_options - $extra_query + $extra_query + and aggregated_p = :aggregated_p @@ -57,7 +58,8 @@ var_name, pretty_name, subquery, - description + description, + aggregated_p from contact_extend_options where Index: openacs-4/packages/contacts/tcl/contact-extend-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contact-extend-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/contacts/tcl/contact-extend-procs.tcl 14 Nov 2005 22:55:45 -0000 1.3 +++ openacs-4/packages/contacts/tcl/contact-extend-procs.tcl 15 Nov 2005 15:56:46 -0000 1.4 @@ -57,12 +57,15 @@ ad_proc -public contact::extend::get_options { {-ignore_extends ""} -search_id:required + -aggregated_p:required } { Returns a list of the form { pretty_name extend_id } of all available extend options in contact_extend_options, if search_id is passed then ignore the extends in contact_search_extend_map @param ignore_extends A list of extend_id's to ignore on the result + @param search_id The id of the search to get the mapped extend options + @param aggregated_p Set it to t or f to get the extends that have aggregated_p set to t or f } { set extra_query "where extend_id not in (select extend_id from contact_search_extend_map where search_id = $search_id)" if { ![empty_string_p $ignore_extends] } { @@ -76,7 +79,7 @@ ad_proc -public contact::extend::option_info { -extend_id:required } { - Returns a list of the form { var_name pretty_name subquery description } of the extend_id + Returns a list of the form { var_name pretty_name subquery description aggregated_p } of the extend_id } { return [db_list_of_lists get_options { }] } \ No newline at end of file