Index: openacs-4/packages/acs-subsite/tcl/group-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/tcl/group-procs.tcl,v diff -u -r1.26 -r1.27 --- openacs-4/packages/acs-subsite/tcl/group-procs.tcl 8 Jun 2005 16:13:36 -0000 1.26 +++ openacs-4/packages/acs-subsite/tcl/group-procs.tcl 4 Jun 2006 00:45:42 -0000 1.27 @@ -21,6 +21,7 @@ { -group_id "" } { -context_id "" } { -group_name "" } + { -pretty_name ""} {group_type "group"} } { Creates a group of this type by calling the .new function for @@ -106,9 +107,12 @@ if { ![empty_string_p $group_name] } { set group_name [lang::util::convert_to_i18n -prefix "group" -text "$group_name"] lappend var_list [list group_name $group_name] + if {[empty_string_p $pretty_name]} { + set pretty_name $group_name + } } - return [package_instantiate_object \ + set group_id [package_instantiate_object \ -creation_user $creation_user \ -creation_ip $creation_ip \ -package_name $package_name \ @@ -118,6 +122,21 @@ -variable_prefix $variable_prefix \ $group_type] + # We can't change the group_name to an I18N version as this would + # break compatability with group::member_p -group_name and the + # like. So instead we change the title of the object of the group + # (through the pretty name). We just have to change the display of + # groups to the title at the appropriate places. + + if { ![empty_string_p [info procs "::lang::util::convert_to_i18n"]] } { + set pretty_name [lang::util::convert_to_i18n -message_key "group_title_${group_id}" -text "$pretty_name"] + } + + # Update the title to the pretty name + if {![empty_string_p $pretty_name]} { + db_dml title_update "update acs_objects set title=:pretty_name where object_id = :group_id" + } + return $group_id } ad_proc group::delete { group_id } { @@ -169,6 +188,7 @@ END; " + util_memoize_flush "group::get_title_not_cached -group_id $group_id" return $object_type } @@ -184,9 +204,10 @@ } { upvar 1 $array row db_1row group_info { - select group_name, join_policy - from groups + select group_name, title, join_policy + from groups g, acs_objects o where group_id = :group_id + and object_id = :group_id } -column_array row } @@ -202,6 +223,113 @@ return $row($element) } +ad_proc -public group::get_id { + {-group_name:required} + {-subsite_id ""} + {-application_group_id ""} +} { + Retrieve the group_id to a given group-name. If you have more than one group with this name, it will return the first one it finds. + Keep that in mind when using this procedure. + + @author Christian Langmann (C_Langmann@gmx.de) + @author Malte Sussdorff (openacs@sussdorff.de) + @creation-date 2005-06-09 + + @param group_name the name of the group to look for + @param subsite_id the ID of the subsite to search for the group name + @param application_group_id the ID of the application group to search for the group name + + @return the first group_id of the groups found for that group_name. + + @error +} { + return [util_memoize [list group::get_id_not_cached -group_name $group_name -subsite_id $subsite_id -application_group_id ""]] +} + +ad_proc -private group::get_id_not_cached { + {-group_name:required} + {-subsite_id ""} + {-application_group_id ""} +} { + Retrieve the group_id to a given group-name. + + @author Christian Langmann (C_Langmann@gmx.de) + @author Malte Sussdorff (openacs@sussdorff.de) + @creation-date 2005-06-09 + + @param group_name the name of the group to look for + + @return the id of the group + + @error +} { + if {[exists_and_not_null subsite_id]} { + set application_group_id [application_group::group_id_from_package_id -package_id [ad_conn subsite_id]] + } + + if {[exists_and_not_null application_group_id]} { + set group_ids [db_list get_group_id_with_application {}] + } else { + set group_ids [db_list get_group_id {}] + } + return [lindex $group_ids 0] +} + +ad_proc -public group::get_members { + {-group_id:required} + {-type "party"} +} { + Get party_ids of all members from cache. + + @param type Type of members - party, person, user + + @see group::get_members_not_cached + @see group::flush_members_cache + + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2005-07-26 +} { + return [util_memoize [list group::get_members_not_cached -group_id $group_id -type $type]] +} + +ad_proc -private group::get_members_not_cached { + {-group_id:required} + {-type:required} +} { + Get party_ids of all members. + + @param type Type of members - party, person, user + + @see group::get_members + @see group::flush_members_cache + + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2005-07-26 +} { + switch $type { + party { set member_list [db_list group_members_party {}] } + default { set member_list [db_list group_members {}] } + } + + return $member_list +} + +ad_proc -private group::flush_members_cache { + {-group_id:required} +} { + Flush group members cache. + + @see group::get_members + @see group::get_members_not_cached + + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2005-07-26 +} { + util_memoize_flush "group::get_members_not_cached -group_id $group_id -type party" + util_memoize_flush "group::get_members_not_cached -group_id $group_id -type user" + util_memoize_flush "group::get_members_not_cached -group_id $group_id -type person" +} + ad_proc -public group::permission_p { { -user_id "" } { -privilege "read" } @@ -272,11 +400,13 @@ " if {[info exists group_name]} { + set pretty_name [lang::util::convert_to_i18n -message_key "group_title.${group_id}" -text "$group_name"] db_dml update_object_title { update acs_objects - set title = :group_name + set title = :pretty_name where object_id = :group_id } + util_memoize_flush "group::get_title_not_cached -group_id $group_id" } } @@ -356,25 +486,22 @@ { -user_id "" } { -group_name "" } { -group_id "" } + { -subsite_id "" } -cascade:boolean } { Return 1 if the user is a member of the group specified. You can specify a group name or group id.

- Note: The group name is not unique - by definition, - and if you call this function with a duplicate group name it - will bomb!!! Using the group name as a parameter is - thus strongly discouraged unless you are really, really sure the - name is unique.

-

+ If there is more than one group with this name, it will use the first one. +

If cascade is true, check to see if the user is a member of the group by virtue of any other component group. (e.g. if group B is a component of group A then if a user is a member of group B then he is automatically a member of A also.) If cascade is false, then the user must have specifically been granted membership on the group in question.

+ @param subsite_id Only useful when using group_name. Marks the subsite in which to search for the group_id that belongs to the group_name } { if { [empty_string_p $user_id] } { set user_id [ad_conn user_id] @@ -385,7 +512,7 @@ } if { ![empty_string_p $group_name] } { - set group_id [db_string group_id_from_name {} -default {}] + set group_id [group::get_id -group_name $group_name -subsite_id $subsite_id] if { [empty_string_p $group_id] } { return 0 } @@ -397,7 +524,41 @@ return [template::util::is_true $result] } +ad_proc -public group::party_member_p { + -party_id + { -group_name "" } + { -group_id "" } + { -subsite_id "" } +} { + Return 1 if the party is an approved member of the group specified. + You can specify a group name or group id. +

+ Note: The group name is not unique + by definition, + and if you call this function with a duplicate group name it + will bomb!!! Using the group name as a parameter is + thus strongly discouraged unless you are really, really sure the + name is unique.

+

The party must have specifically + been granted membership on the group in question.

+} { + if { [empty_string_p $group_name] && [empty_string_p $group_id] } { + return 0 + } + + if { ![empty_string_p $group_name] } { + set group_id [group::get_id -group_name $group_name -subsite_id $subsite_id] + if { [empty_string_p $group_id] } { + return 0 + } + } + + set result [db_string party_is_member {} -default "f"] + + return [template::util::is_true $result] +} + ad_proc -public group::get_rel_segment { {-group_id:required} {-type:required} @@ -487,6 +648,7 @@ } relation_add -member_state $member_state $rel_type $group_id $user_id + flush_members_cache -group_id $group_id } @@ -512,4 +674,59 @@ relation_remove $rel_id } } + + flush_members_cache -group_id $group_id } + +ad_proc -public group::title { + {-group_name ""} + {-group_id ""} +} { + Get the title of a group, cached + Use either the group_id or the group_name + + @param group_id The group_id of the group + @param group_name The name of the group. Note this is not the I18N title we want to retrieve with this procedure +} { + if {![empty_string_p $group_name]} { + set group_id [group::get_id -group_name $group_name] + } + + if {![empty_string_p $group_id]} { + return [util_memoize [list group::title_not_cached -group_id $group_id]] + } else { + return "" + } +} + +ad_proc -private group::title_not_cached { + {-group_id ""} +} { + Get the title of a group, not cached + + @param group_id The group_id of the group +} { + return [group::get_element -group_id $group_id -element "title"] +} + +ad_proc -private group::group_p { + {-group_id ""} +} { + Get the title of a group, not cached + + @param group_id The group_id of the group +} { + return [util_memoize [list group::group_p_not_cached -group_id $group_id]] +} + + +ad_proc -private group::group_p_not_cached { + {-group_id ""} +} { + Get the title of a group, not cached + + @param group_id The group_id of the group +} { + return [db_string group "select 1 from groups where group_id = :group_id" -default 0] +} +