Index: openacs-4/packages/dotlrn/tcl/site-nodes-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/tcl/Attic/site-nodes-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/dotlrn/tcl/site-nodes-procs.tcl 11 Dec 2001 00:45:15 -0000 1.2 +++ openacs-4/packages/dotlrn/tcl/site-nodes-procs.tcl 13 Dec 2001 22:12:55 -0000 1.3 @@ -37,4 +37,195 @@ } { return [db_string select_parent_site_node {}] } + + + # site_nodes_list procs + + ad_proc -public get_site_nodes_list { + } { + Return the list-ified site_nodes array. + } { + return [nsv_array get site_nodes] + } + + ad_proc -public get_site_nodes_list_key { + {-site_nodes_list:required} + {-index:required} + } { + return [lindex $site_nodes_list $index] + } + + ad_proc -public get_site_nodes_list_value { + {-site_nodes_list:required} + {-index:required} + } { + # ns_log notice "llength [llength $site_nodes_list] [lindex $site_nodes_list [expr $index + 1 ]] " + return [lindex $site_nodes_list [expr $index + 1 ]] + } + + + ad_proc -public get_site_nodes_list_value_param { + {-site_nodes_list:required} + {-index:required} + {-param:required} + } { + The 'site_nodes' nsv_array is chock full of information + about every package mounted on every node in the system, let's + access that information. + + Here's a sample: + key = /portal/ + + value = directory_p t + object_type apm_package + package_key new-portal + package_id 3482 + pattern_p t + node_id 3481 + url /portal/ + object_id 3482 + + @author arjun@openforce.net + } { + + #ns_log notice "aks12 llength [llength $site_nodes_list]" + + array set snlv [get_site_nodes_list_value \ + -site_nodes_list $site_nodes_list \ + -index $index] + + switch $param { + "directory_p" { + return $snlv(directory_p) + } + "object_type" { + return $snlv(object_type) + } + "package_key" { + return $snlv(package_key) + } + "package_id" { + return $snlv(package_id) + } + "pattern_p" { + return $snlv(pattern_p) + } + "node_id" { + return $snlv(node_id) + } + "url" { + return $snlv(url) + } + "object_id" { + return $snlv(object_id) + } + default { + ns_log Error \ + "site_nodes::get_site_nodes_list_value_param failed! \n + bad param ($param) was specified" + ad_return_complaint 1 \ + "site_nodes::get_site_nodes_list_value_param failed! \n + bad param ($param) was specified" + } + } + } + + ad_proc -private get_info { + {-return:required} + {-param ""} + {-package_key:required} + } { + returns either 1. number of times this package_key is mounted + 2. the url a singleton is mounted at (or the first match it finds + for a multi-mounted package) or 3. a singleon's param (see list above). + Same deal appiles to non-singletons + + ret = count, url, param + } { + + set get_count_p 0 + set get_url_p 0 + set get_param_p 0 + + if {$return == "count"} { + set get_count_p 1 + set $param "package_key" + } elseif {$return == "url"} { + set get_url_p 1 + } elseif {$return == "param"} { + if {[empty_string_p $param]} { + ns_log Error \ + "site_nodes::get_info failed! \n + no param specified to get" + ad_return_complaint 1 \ + "site_nodes::get_info failed! \n + no param specified to get" + } else { + set get_param_p 1 + } + } + + set site_nodes_list [get_site_nodes_list] + + # ad_return_complaint 1 "aks 17 $site_nodes_list" + + # iterate through the array, counting the number of times the + # passed in package key is in the site_nodes array + set count 0 + + for {set x 0} {$x < [llength $site_nodes_list]} {incr x 2} { + + set key [get_site_nodes_list_key \ + -site_nodes_list $site_nodes_list \ + -index $x] + + if {$get_url_p} { return $key } + + set poss_key_match [get_site_nodes_list_value_param \ + -site_nodes_list $site_nodes_list \ + -index $x \ + -param "package_key"] + + if { $poss_key_match == $package_key} { + + if {$get_param_p} { + return [get_site_nodes_list_value_param \ + -site_nodes_list $site_nodes_list \ + -index $x \ + -param $param] + } + + incr count + } + } + + if {$get_count_p} { + return $count + } else { + ns_log error "site_nodes::get_info get_count_p assertion failed!\n + we should never get here" + } + } + + ad_proc -public mount_count { + {-package_key:required} + } { + returns the number of times this package_key is mounted + } { + return [get_info -return count -package_key $package_key] + } + + ad_proc -public singleton_p { + {-package_key:required} + } { + is this package a singleton? + } { + if {[package_mount_count -package_key $package_key] == 1} { + return 1 + } else { + return 0 + } + } + + }