Index: openacs-4/packages/dotlrn/sql/oracle/dotlrn-communities-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/sql/oracle/Attic/dotlrn-communities-package-create.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/dotlrn/sql/oracle/dotlrn-communities-package-create.sql 3 Apr 2002 00:33:12 -0000 1.2 +++ openacs-4/packages/dotlrn/sql/oracle/dotlrn-communities-package-create.sql 4 Apr 2002 05:55:45 -0000 1.3 @@ -164,13 +164,14 @@ party_id in parties.party_id%TYPE ) return char; + function url ( + community_id in dotlrn_communities.community_id%TYPE + ) return varchar2; + function has_subcomm_p ( community_id in dotlrn_communities.community_id%TYPE ) return char; - function url ( - community_id in dotlrn_communities.community_id%TYPE - ) return varchar2; end dotlrn_community; / show errors @@ -325,14 +326,12 @@ is v_rv char(1); begin - - select decode(count(*), 0, 'f', 't') into v_rv - from dual where exists ( - select 'x' - from dotlrn_communities - where parent_community_id = community_id - ); - + select decode(count(*), 0, 'f', 't') + into v_rv + from dual + where exists (select 1 + from dotlrn_communities + where parent_community_id = has_subcomm_p.community_id); return v_rv; end; 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 ""] } Index: openacs-4/packages/dotlrn/tcl/community-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/tcl/community-procs.xql,v diff -u -r1.45 -r1.46 --- openacs-4/packages/dotlrn/tcl/community-procs.xql 29 Mar 2002 19:38:25 -0000 1.45 +++ openacs-4/packages/dotlrn/tcl/community-procs.xql 4 Apr 2002 05:55:45 -0000 1.46 @@ -256,7 +256,7 @@ - + select 1 from dual where exists (select 1 from dotlrn_communities where parent_community_id = :community_id) @@ -268,6 +268,19 @@ + + + select community_id as sc_id, + acs_permission.permission_p(community_id, :user_id, 'admin') as admin_p, + dotlrn_community.member_p(community_id, :user_id) as member_p, + dotlrn_community.has_subcomm_p(community_id) as has_subcomm_p, + dotlrn_community.name(community_id) as name, + dotlrn_community.url(community_id) as url + from dotlrn_communities + where parent_community_id = :community_id + + + select package_id from dotlrn_community_types where community_type= :community_type @@ -296,7 +309,7 @@ - + select pretty_name from dotlrn_communities where community_id= :community_id Index: openacs-4/packages/dotlrn/www/dotlrn-main-portlet.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/dotlrn-main-portlet.adp,v diff -u -r1.21 -r1.22 --- openacs-4/packages/dotlrn/www/dotlrn-main-portlet.adp 29 Mar 2002 19:14:46 -0000 1.21 +++ openacs-4/packages/dotlrn/www/dotlrn-main-portlet.adp 4 Apr 2002 05:55:45 -0000 1.22 @@ -35,9 +35,11 @@ [admin]

  • - + + + @@ -52,9 +54,11 @@ [admin] - + + + Index: openacs-4/packages/dotlrn/www/dotlrn-main-portlet.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/Attic/dotlrn-main-portlet.xql,v diff -u -r1.6 -r1.7 --- openacs-4/packages/dotlrn/www/dotlrn-main-portlet.xql 29 Mar 2002 19:38:26 -0000 1.6 +++ openacs-4/packages/dotlrn/www/dotlrn-main-portlet.xql 4 Apr 2002 05:55:45 -0000 1.7 @@ -6,7 +6,8 @@ select community_id, dotlrn_class_instances_full.pretty_name, dotlrn_class_instances_full.url, - acs_permission.permission_p(community_id, :user_id, 'admin') as admin_p + acs_permission.permission_p(community_id, :user_id, 'admin') as admin_p, + dotlrn_community.has_subcomm_p(community_id) as subcomm_p from dotlrn_class_instances_full, dotlrn_member_rels_approved where dotlrn_member_rels_approved.user_id = :user_id @@ -19,7 +20,8 @@ select community_id, dotlrn_clubs_full.pretty_name, dotlrn_clubs_full.url, - acs_permission.permission_p(community_id, :user_id, 'admin') as admin_p + acs_permission.permission_p(community_id, :user_id, 'admin') as admin_p, + dotlrn_community.has_subcomm_p(community_id) as subcomm_p from dotlrn_clubs_full, dotlrn_member_rels_approved where dotlrn_member_rels_approved.user_id = :user_id