Forum OpenACS Development: Getting the group_id from the group_name

One of these days I will pass an inflection point and start contributing more information then I suck out of people, I promise.

I have multiple subsites, and each subsite has the same collection of groups. Is there a proc I can use that when given a group_name it returns the group_id of the group for the subsite you are currently in?

I'm looking for the same thing as groups::member_p but I need it to know what subsite you are in.

Collapse
Posted by Alex Kroman on
Here's the code. Thanks to leeldn for helping me out on IRC. If you pass in $group_name it will return true or false depending on if you are in that group for the subsite you are currently in.
set application_group_id [application_group::group_id_from_package_id -package_id [ad_conn subsite_id]]

set group_id [db_string get_group_id "SELECT g.group_id                                                                                    
                                          FROM acs_rels rels                                                                                   
                                          INNER JOIN composition_rels comp ON                                                                  
                                          rels.rel_id = comp.rel_id                                                                            
                                          INNER JOIN groups g ON rels.object_id_two = g.group_id                                               
                                          WHERE rels.object_id_one = :application_group_id AND                                                 
                                          g.group_name = :group_name" -default 0]

set group_member_p [group::member_p -user_id $user_id -group_id $group_id]
Collapse
Posted by Malte Sussdorff on
I added this functionality to the group::get_id procedure in oacs-5-2. Furthermore I fixed it so that it does not bomb if there are more than one group with the same name. It will just return the first id it finds :).