acs::SiteNode method get_children (public)

 <instance of acs::SiteNode[i]> get_children -node_id node_id  \
    [ -all ] [ -package_type package_type ] \
    [ -package_key package_key ] [ -filters filters ] \
    [ -element element ]

Defined in packages/acs-tcl/tcl/site-nodes-procs.tcl

Filtering happens here exactly like in the nsv-based version. If should be possible to realize (at least some of the) filtering via the SQL query.

Switches:
-node_id (required)
-all (optional)
-package_type (optional)
-package_key (optional)
-filters (optional)
-element (optional)

Testcases:
No testcase defined.
Source code:
if {$all} {
    #
    # The following query is just for PG.  Note that
    # the query should not return the root of the
    # tree.
    #
    set sql [subst {
        WITH RECURSIVE site_node_tree(node_id, parent_id) AS (
          select node_id, parent_id from site_nodes where node_id = :node_id
        UNION ALL
          select child.node_id, child.parent_id from site_node_tree, site_nodes child
          where  child.parent_id = site_node_tree.node_id
        ) select [acs::dc map_function_name site_node__url(node_id)]
        from site_node_tree where node_id != :node_id
    }]
    if {[db_driverkey ""] eq "oracle"} {
        set sql [string map [list "WITH RECURSIVE" "WITH"$sql]
    }

    set child_urls [::acs::dc list -prepare integer dbqd..[current method]-all $sql]
} else {
    if {$package_key ne ""} {
        #
        # Simple optimization for package_keys; seems to be frequently used.
        # We leave the logic below unmodified, which could be optimized as well.
        #
        set package_key_clause "and package_id = object_id and package_key = :package_key"
        set from "site_nodes, apm_packages"
    } else {
        set package_key_clause ""
        set from "site_nodes"
    }
    set sql [subst {
        select [::acs::dc map_function_name {site_node__url(node_id)}]
        from $from
        where parent_id = :node_id $package_key_clause
    }]
    set child_urls [::acs::dc list dbqd..[current method] $sql]
}

if { $package_type ne "" } {
    lappend filters package_type $package_type
} elseif$package_key ne "" } {
    lappend filters package_key $package_key
}

if { [llength $filters] > 0 } {
    set return_val [list]
    foreach child_url $child_urls {
        if {![catch {set site_node [:get -url $child_url]}]} {

            set passed_p 1
            foreach { elm val } $filters {
                if { [dict get $site_node $elm] ne $val } {
                    set passed_p 0
                    break
                }
            }
            if { $passed_p } {
                if { $element ne "" } {
                    lappend return_val [dict get $site_node $element]
                } else {
                    lappend return_val $child_url
                }
            }
        }
    }
} elseif$element ne "" } {
    set return_val [list]
    foreach child_url $child_urls {
        if {![catch {set site_node [:get -url $child_url]}]} {
            lappend return_val [dict get $site_node $element]
        }
    }
} else {
    set return_val $child_urls
}

return $return_val
Generic XQL file:
packages/acs-tcl/tcl/site-nodes-procs.xql

PostgreSQL XQL file:
packages/acs-tcl/tcl/site-nodes-procs-postgresql.xql

Oracle XQL file:
packages/acs-tcl/tcl/site-nodes-procs-oracle.xql

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