Index: openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/simulation-procs.tcl,v diff -u -r1.16 -r1.17 --- openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 17 Dec 2003 16:51:24 -0000 1.16 +++ openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 18 Dec 2003 08:31:03 -0000 1.17 @@ -134,10 +134,17 @@ }] } -ad_proc simulation::groups_eligible_for_casting {} { - Return a list of groups eligible for enrollment and invitation - for the current simulation package. +ad_proc simulation::casting_groups { + {-workflow_id:required} + {-enrolled_only:boolean} +} { + Return a list of groups eligible for enrollment and casting for a given + workflow. + @param workflow_id The id of the workflow to get casting groups for. + @param enrolled_only Provide this switch to only get groups selected for + auto enrollment. + @return A list of lists, with label-id pairs, suitable to be passed as the options attribute of a form builder select widget. @@ -146,18 +153,25 @@ set options_list [list] # We only want the label and the id, i.e. strip off the count - array set groups [groups_eligible_for_casting_with_counts] + array set groups [casting_groups_with_counts -enrolled_only=$enrolled_only_p -workflow_id $workflow_id] foreach group_id [array names groups] { lappend options_list [list "[lindex $groups($group_id) 0] ([lindex $groups($group_id) 1] users)" $group_id] } return $options_list } -ad_proc simulation::groups_eligible_for_casting_with_counts {} { - Return a list of groups eligible for enrollment and invitation - for the current simulation package. +ad_proc simulation::casting_groups_with_counts { + {-workflow_id:required} + {-enrolled_only:boolean} +} { + Return a list of groups eligible for enrollment and casting for a given + workflow. + @param workflow_id The id of the workflow to get casting groups for. + @param enrolled_only Provide this switch to only get groups selected for + auto enrollment. + @return An array lists on the format [list group_id1 [list group_name1 n_users1] group_id2 [list group_name2 n_users2] ...] @@ -174,8 +188,14 @@ -package_id $closest_subsite(package_id)] # Get all groups related to (children of) the subsite group (only one level down) + set enrollment_clause [ad_decode $enrolled_only_p "0" "" "and exists (select 1 + from sim_party_sim_map + where party_id = g.group_id + and simulation_id = :workflow_id + and type = 'auto-enroll' + )"] set groups_list [list] - db_foreach subsite_group_options { + db_foreach subsite_group_options " select g.group_name, g.group_id, (select count(*) @@ -194,7 +214,8 @@ where pamm.party_id = g.group_id and pamm.member_id = u.user_id ) - } { + $enrollment_clause + " { lappend groups_list $group_id [list $group_name $n_users] } Index: openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/siminst/Attic/simulation-casting-2.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-2.tcl 17 Dec 2003 16:51:24 -0000 1.9 +++ openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-2.tcl 18 Dec 2003 08:31:03 -0000 1.10 @@ -21,7 +21,7 @@ set in_three_months_date [clock format [expr [clock seconds] + 3*3600*24*31] -format "%Y %m %d"] set in_four_months_date [clock format [expr [clock seconds] + 4*3600*24*31] -format "%Y %m %d"] -set eligible_groups [simulation::groups_eligible_for_casting] +set eligible_groups [simulation::casting_groups -workflow_id $workflow_id] ad_form -export { workflow_id } -name simulation -form { {enroll_start:date,optional Index: openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-3.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/siminst/Attic/simulation-casting-3.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-3.tcl 17 Dec 2003 16:51:24 -0000 1.5 +++ openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-3.tcl 18 Dec 2003 08:31:03 -0000 1.6 @@ -14,7 +14,7 @@ # Loop over all workflow roles and append the actor and "in groups of" widgets to the form set form [list] -set eligible_groups [simulation::groups_eligible_for_casting] +set eligible_groups [simulation::casting_groups -enrolled_only -workflow_id $workflow_id] foreach role_id [workflow::get_roles -workflow_id $workflow_id] { set role_pretty_name [workflow::role::get_element -role_id $role_id -element pretty_name] @@ -44,7 +44,7 @@ # Validation # Make sure the number of users per case does not exceed the number of users # in each group - array set groups [simulation::groups_eligible_for_casting_with_counts] + array set groups [simulation::casting_groups_with_counts -enrolled_only -workflow_id $workflow_id] set error_p 0 foreach role_id [workflow::get_roles -workflow_id $workflow_id] { set group_size [set group_$role_id] Index: openacs-4/packages/simulation/tcl/simulation-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/simulation-procs.tcl,v diff -u -r1.16 -r1.17 --- openacs-4/packages/simulation/tcl/simulation-procs.tcl 17 Dec 2003 16:51:24 -0000 1.16 +++ openacs-4/packages/simulation/tcl/simulation-procs.tcl 18 Dec 2003 08:31:03 -0000 1.17 @@ -134,10 +134,17 @@ }] } -ad_proc simulation::groups_eligible_for_casting {} { - Return a list of groups eligible for enrollment and invitation - for the current simulation package. +ad_proc simulation::casting_groups { + {-workflow_id:required} + {-enrolled_only:boolean} +} { + Return a list of groups eligible for enrollment and casting for a given + workflow. + @param workflow_id The id of the workflow to get casting groups for. + @param enrolled_only Provide this switch to only get groups selected for + auto enrollment. + @return A list of lists, with label-id pairs, suitable to be passed as the options attribute of a form builder select widget. @@ -146,18 +153,25 @@ set options_list [list] # We only want the label and the id, i.e. strip off the count - array set groups [groups_eligible_for_casting_with_counts] + array set groups [casting_groups_with_counts -enrolled_only=$enrolled_only_p -workflow_id $workflow_id] foreach group_id [array names groups] { lappend options_list [list "[lindex $groups($group_id) 0] ([lindex $groups($group_id) 1] users)" $group_id] } return $options_list } -ad_proc simulation::groups_eligible_for_casting_with_counts {} { - Return a list of groups eligible for enrollment and invitation - for the current simulation package. +ad_proc simulation::casting_groups_with_counts { + {-workflow_id:required} + {-enrolled_only:boolean} +} { + Return a list of groups eligible for enrollment and casting for a given + workflow. + @param workflow_id The id of the workflow to get casting groups for. + @param enrolled_only Provide this switch to only get groups selected for + auto enrollment. + @return An array lists on the format [list group_id1 [list group_name1 n_users1] group_id2 [list group_name2 n_users2] ...] @@ -174,8 +188,14 @@ -package_id $closest_subsite(package_id)] # Get all groups related to (children of) the subsite group (only one level down) + set enrollment_clause [ad_decode $enrolled_only_p "0" "" "and exists (select 1 + from sim_party_sim_map + where party_id = g.group_id + and simulation_id = :workflow_id + and type = 'auto-enroll' + )"] set groups_list [list] - db_foreach subsite_group_options { + db_foreach subsite_group_options " select g.group_name, g.group_id, (select count(*) @@ -194,7 +214,8 @@ where pamm.party_id = g.group_id and pamm.member_id = u.user_id ) - } { + $enrollment_clause + " { lappend groups_list $group_id [list $group_name $n_users] } Index: openacs-4/packages/simulation/www/siminst/simulation-casting-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/Attic/simulation-casting-2.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/simulation/www/siminst/simulation-casting-2.tcl 17 Dec 2003 16:51:24 -0000 1.9 +++ openacs-4/packages/simulation/www/siminst/simulation-casting-2.tcl 18 Dec 2003 08:31:03 -0000 1.10 @@ -21,7 +21,7 @@ set in_three_months_date [clock format [expr [clock seconds] + 3*3600*24*31] -format "%Y %m %d"] set in_four_months_date [clock format [expr [clock seconds] + 4*3600*24*31] -format "%Y %m %d"] -set eligible_groups [simulation::groups_eligible_for_casting] +set eligible_groups [simulation::casting_groups -workflow_id $workflow_id] ad_form -export { workflow_id } -name simulation -form { {enroll_start:date,optional Index: openacs-4/packages/simulation/www/siminst/simulation-casting-3.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/simulation-casting-3.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/simulation/www/siminst/simulation-casting-3.tcl 17 Dec 2003 16:51:24 -0000 1.5 +++ openacs-4/packages/simulation/www/siminst/simulation-casting-3.tcl 18 Dec 2003 08:31:03 -0000 1.6 @@ -14,7 +14,7 @@ # Loop over all workflow roles and append the actor and "in groups of" widgets to the form set form [list] -set eligible_groups [simulation::groups_eligible_for_casting] +set eligible_groups [simulation::casting_groups -enrolled_only -workflow_id $workflow_id] foreach role_id [workflow::get_roles -workflow_id $workflow_id] { set role_pretty_name [workflow::role::get_element -role_id $role_id -element pretty_name] @@ -44,7 +44,7 @@ # Validation # Make sure the number of users per case does not exceed the number of users # in each group - array set groups [simulation::groups_eligible_for_casting_with_counts] + array set groups [simulation::casting_groups_with_counts -enrolled_only -workflow_id $workflow_id] set error_p 0 foreach role_id [workflow::get_roles -workflow_id $workflow_id] { set group_size [set group_$role_id]