Index: openacs-4/packages/dotlrn/tcl/community-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/tcl/community-procs.tcl,v diff -u -r1.96 -r1.97 --- openacs-4/packages/dotlrn/tcl/community-procs.tcl 3 Apr 2002 00:33:12 -0000 1.96 +++ openacs-4/packages/dotlrn/tcl/community-procs.tcl 4 Apr 2002 05:55:45 -0000 1.97 @@ -885,11 +885,20 @@ ad_proc -public has_subcommunity_p { {-community_id:required} } { + Returns 1 if the community has a subcommunity, memoized for 1 min + } { + return [util_memoize "dotlrn_community::has_subcommunity_p_memoized -community_id $community_id" 60] + } + + ad_proc -public has_subcommunity_p_memoized { + {-community_id:required} + } { Returns 1 if the community has a subcommunity } { return [db_0or1row select_subcomm_check {}] } + ad_proc -public get_subcomm_list { {-community_id:required} } { @@ -914,8 +923,10 @@ member of all the supergroups to the leaf subgroup. Not even admins see the whole tree. - FIXME: totally unoptimized!! + FIXME: still rather slow + things to get: has_subcom, member_p, url, name, admin_p, not_closed_p, member_pending, needs_approval + things to send: user_id, sc_id, } { set chunk "" @@ -987,6 +998,117 @@ return $chunk } + + ad_proc -public get_subcomm_chunk_new { + {-user_id ""} + {-community_id:required} + {-pretext "
  • "} + {-join_target "register"} + {-only_member_p 0} + } { + Returns a html fragment of the subcommunity hierarchy of this + community or if none, the empty list. + + Brief notes: his proc always shows the subgroups of the + passed-in group, but shows deeper groups _only if_ you are a + member of all the supergroups to the leaf subgroup. Not even + admins see the whole tree. + + more things to get from PL/SQL: not_closed_p, member_pending, needs_approval + } { + set chunk "" + + if {[empty_string_p $user_id]} { + set user_id [ad_get_user_id] + } + + db_foreach select_subcomm_info {} { + + # the lazy man's decode + if {[string equal $has_subcomm_p t]} { + set has_subcomm_p 1 + } else { + set has_subcomm_p 0 + } + + set m_s $member_p + + if {[string equal $member_p t]} { + set member_p 1 + } else { + set member_p 0 + } + + set a_s $admin_p + + if {[string equal $admin_p t]} { + set admin_p 1 + } else { + set admin_p 0 + } + + + + if {$has_subcomm_p && $member_p} { + # Shows the subcomms of this subcomm ONLY IF I'm a + # member of the current comm + append chunk \ + "$pretext $name\n" + + append chunk "

    debug: $has_subcomm_p / $m_s = $member_p / $a_s = $admin_p " + + if {$admin_p} { + append chunk \ + "\[admin\]" + } + + append chunk \ + "

    \n" + } elseif { $member_p || $admin_p || [not_closed_p -community_id $sc_id]} { + # Shows the subcomm if: + # 1. I'm a member of this subcomm OR + # 2. I'm have admin rights over the subcomm OR + # 3. The subcomm has an "open" OR "request" join policy + # but if the only_member_p flag is true, the user must be + # a member of the subcomm to see it. + + if {$only_member_p && !$member_p} { + continue + } + + append chunk "$pretext $name\n" + + append chunk "

    debug: $has_subcomm_p / $m_s = $member_p / $a_s = $admin_p " + + if {!$member_p && [not_closed_p -community_id $sc_id]} { + + append chunk \ + "\[" + + if {[member_pending_p -community_id $sc_id -user_id $user_id]} { + append chunk \ + "waiting for approval" + } elseif {[needs_approval_p -community_id $sc_id]} { + append chunk \ + "request membership" + } else { + append chunk \ + "join" + } + + append chunk "\]\n" + } + + if {$admin_p} { + append chunk \ + " \[admin\]\n" + } + } + } + + return $chunk + } + ad_proc -public get_community_type_url { community_type } { @@ -1041,6 +1163,14 @@ } { get the name for a community } { + return [util_memoize "dotlrn_community::get_community_name_memoized $community_id"] + } + + ad_proc -public get_community_name_memoized { + community_id + } { + memo helper + } { return [db_string select_community_name {} -default ""] }