template::data::transform::party_search (private)

 template::data::transform::party_search element_ref

Defined in packages/acs-templating/tcl/widget-procs.tcl

Do the actual search of parties using the input value and return a list of lists consisting of (party_name, party_id). DRB: The blank string check should actually be in the validate procedure.

Parameters:
element_ref (required)
Reference variable to the form element.
Returns:
search result or error

Partial Call Graph (max 5 caller/called nodes):
%3 db_list_of_lists db_list_of_lists (public) lang::util::localize_list_of_lists lang::util::localize_list_of_lists (public) template::element::set_error template::element::set_error (public) template::data::transform::party_search template::data::transform::party_search template::data::transform::party_search->db_list_of_lists template::data::transform::party_search->lang::util::localize_list_of_lists template::data::transform::party_search->template::element::set_error

Testcases:
No testcase defined.
Source code:
    upvar $element_ref element
    set element_id $element(id)

    set value [string trim [ns_queryget $element_id]]
    set is_optional [info exists element(optional)]

    if { $value eq "" } {
        if { [string is true $is_optional] } {
            return ""
        } else {
            template::element::set_error $element(form_id) $element_id "Please enter a search string."
            return [list]
        }
    }

    if {$value eq ":search:"} {
        # user has selected 'search again' previously
        template::element::set_error $element(form_id) $element_id "Please enter a search string."
        return [list]
    }

    if { [ns_queryexists $element_id:search_string] } {
        # request comes from a page with a select widget and the
        # search string has been passed as hidden value
        set search_string [ns_queryget $element_id:search_string]
        set element(search_string) $search_string

        # the value to be returned
        set value [ns_queryget $element_id]
    } else {
        # request is an initial search
        set search_string $value
        set element(search_string) $value
    }

    # search in persons
    set persons [db_list_of_lists search_persons {}]

    # search in groups and relsegs
    set groups_relsegs [db_list_of_lists search_groups_relsegs {}]

    # Localize the groups
    set groups_relsegs [lang::util::localize_list_of_lists -list $groups_relsegs]

    if { [llength $persons] == 0 && [llength $groups_relsegs] == 0 } {
        # no search results so return text entry back to the user

        unset -nocomplain element(options)

        template::element::set_error $element(form_id) $element_id [subst {
            No matches were found for "[ns_quotehtml $search_string]".<br>Please try again.
        }]

    } else {
        # we need to return a select list

        set options [list]

        if { [llength $persons] > 0 } {
            set options $persons
            lappend options [list "---" ""]
        }
        if { [llength $groups_relsegs] > 0 } {
            lappend options {*}$groups_relsegs [list "---" ""]
        }
        set element(options) [concat $options { { "Search again..." ":search:" } }]
        if { ![info exists value] } {
            # set value to first item
            set value [lindex $options 0 1]
        }

        if { ![ns_queryexists $element_id:confirmed_p] } {
            template::element::set_error $element(form_id) $element_id "Please choose an entry."
        }
    }

    if { [info exists element(result_datatype)]
         && [ns_queryexists $element_id:select] } {
        set element(datatype) $element(result_datatype)
    }

    return $value
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
<fullquery name="template::data::transform::party_search.search_persons">
    <querytext>
        select (first_names || ' ' || last_name) as name, pe.person_id from persons pe 
        join parties pa on pe.person_id=pa.party_id
        where lower(pe.first_names || ' ' || pe.last_name) like '%' || lower(:search_string) || '%'
        or lower(pa.email) like '%' || lower(:search_string) || '%'
        order by lower(first_names || ' ' || last_name)
      </querytext>
</fullquery>

<fullquery name="template::data::transform::party_search.search_groups_relsegs">
    <querytext>
        (
        select g1.group_name as party_name, g1.group_id as party_id from groups g1
        where lower(g1.group_name) like '%' || lower(:search_string) || '%'
        )
        union
        (
        select g2.group_name || ' : ' || s2.segment_name as party_name, s2.segment_id as party_id
        from rel_segments s2
        join groups g2 on s2.group_id=g2.group_id
        where lower(g2.group_name || ' : ' || s2.segment_name) like '%' || lower(:search_string) || '%'
        )
        order by party_name
      </querytext>
</fullquery>
packages/acs-templating/tcl/widget-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: