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.15 -r1.16 --- openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 16 Dec 2003 16:03:29 -0000 1.15 +++ openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 17 Dec 2003 16:51:24 -0000 1.16 @@ -143,6 +143,29 @@ @author Peter Marklund } { + 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] + 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. + + @return An array lists on the format + [list group_id1 [list group_name1 n_users1] group_id2 [list group_name2 n_users2] ...] + +with label-id pairs, suitable to be passed + as the options attribute of a form builder select widget. + + @author Peter Marklund +} { # lookup package_id of the nearest subsite subsite::get -array closest_subsite @@ -151,14 +174,31 @@ -package_id $closest_subsite(package_id)] # Get all groups related to (children of) the subsite group (only one level down) - return [db_list_of_lists subsite_group_options { + set groups_list [list] + db_foreach subsite_group_options { select g.group_name, - g.group_id + g.group_id, + (select count(*) + from party_approved_member_map pamm, + users u + where pamm.party_id = g.group_id + and pamm.member_id = u.user_id + ) as n_users from acs_rels ar, groups g where ar.object_id_one = :subsite_group_id and ar.object_id_two = g.group_id - }] + and exists (select 1 + from party_approved_member_map pamm, + users u + where pamm.party_id = g.group_id + and pamm.member_id = u.user_id + ) + } { + lappend groups_list $group_id [list $group_name $n_users] + } + + return $groups_list } template_tag relation { params } { Index: openacs-4/contrib/packages/simulation/tcl/template-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/template-procs.tcl,v diff -u -r1.21 -r1.22 --- openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 17 Dec 2003 16:30:32 -0000 1.21 +++ openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 17 Dec 2003 16:51:24 -0000 1.22 @@ -274,7 +274,6 @@ } } - ad_proc -public simulation::template::get_parties { {-workflow_id:required} {-rel_type "auto-enroll"} @@ -398,11 +397,15 @@ select to_char(current_timestamp, 'YYYY-MM-DD') }] if { [clock scan $today] < [clock scan $simulation(enroll_end)] } { - set simulation_edit(enroll_date) $today + set simulation_edit(enroll_end) $today } + # enroll_start must be before or equal enroll_end + if { [clock scan $today] < [clock scan $simulation(enroll_start)] } { + set simulation_edit(enroll_start) $today + } # Set start_date to now - set simulation_edit(start_date) $today + set simulation_edit(case_start) $today # Auto enroll users in auto-enroll groups set simulation_edit(enrolled) [list] @@ -448,7 +451,7 @@ }] set total_n_users [llength $user_list] - simulation::template::get_role_mappings -workflow_id $workflow_id -array roles + simulation::template::get_role_group_mappings -workflow_id $workflow_id -array roles set n_users_per_case 0 foreach role_id [array names roles] { Index: openacs-4/contrib/packages/simulation/tcl/template-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/template-procs.xql,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/simulation/tcl/template-procs.xql 16 Dec 2003 16:03:29 -0000 1.4 +++ openacs-4/contrib/packages/simulation/tcl/template-procs.xql 17 Dec 2003 16:51:24 -0000 1.5 @@ -14,11 +14,11 @@ s.sim_type, s.enroll_type, s.casting_type, - to_char(s.enroll_start, 'YYYY-MM-DD'), - to_char(s.enroll_end, 'YYYY-MM-DD'), - to_char(s.case_start, 'YYYY-MM-DD'), - to_char(s.case_end, 'YYYY-MM-DD'), - to_char(s.send_start_note_date, 'YYYY-MM-DD') + to_char(s.enroll_start, 'YYYY-MM-DD') as enroll_start, + to_char(s.enroll_end, 'YYYY-MM-DD') as enroll_end, + to_char(s.case_start, 'YYYY-MM-DD') as case_start, + to_char(s.case_end, 'YYYY-MM-DD') as case_end, + to_char(s.send_start_note_date, 'YYYY-MM-DD') as send_start_note_date from workflows w, sim_simulations s where w.workflow_id = :workflow_id 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.8 -r1.9 --- openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-2.tcl 17 Dec 2003 10:43:07 -0000 1.8 +++ openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-2.tcl 17 Dec 2003 16:51:24 -0000 1.9 @@ -33,7 +33,7 @@ {value $in_two_months_date} } {notification_date:date - {label "Date to send start notification"} + {label "Date to send start notification (mockup only)"} {value $in_two_and_a_half_months_date} } {case_start:date @@ -83,7 +83,8 @@ array unset sim_template set sim_template(enroll_start) $enroll_start_ansi set sim_template(enroll_end) $enroll_end_ansi - set sim_template(notification_date) $notification_date_ansi + # TODO: + #set sim_template(notification_date) $notification_date_ansi set sim_template(case_start) $case_start_ansi set sim_template(case_end) $case_end_ansi set sim_template(enroll_type) $enroll_type 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.4 -r1.5 --- openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-3.tcl 17 Dec 2003 11:02:36 -0000 1.4 +++ openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-3.tcl 17 Dec 2003 16:51:24 -0000 1.5 @@ -41,11 +41,29 @@ } } -on_submit { - # TODO: move this code into the simulation::template::edit proc? Low priority. + # 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] + set error_p 0 + foreach role_id [workflow::get_roles -workflow_id $workflow_id] { + set group_size [set group_$role_id] + set group_id [set actor_$role_id] + set n_members [lindex $groups($group_id) 1] + if { $group_size > $n_members } { + template::form::set_error actors group_$role_id "Group size is larger than the number of users in the group: $n_members" + set error_p 1 + break + } + } + if { $error_p } { + break + } + + # TODO: move this code into the simulation::template::edit proc? Low priority. # Clear out old mappings simulation::template::delete_role_group_mappings -workflow_id $workflow_id - foreach role_id [workflow::get_roles -workflow_id $workflow_id] { simulation::template::new_role_group_mapping \ -role_id $role_id \ Index: openacs-4/contrib/packages/simulation/www/siminst/simulation-start.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/siminst/Attic/simulation-start.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/simulation/www/siminst/simulation-start.tcl 16 Dec 2003 16:00:34 -0000 1.1 +++ openacs-4/contrib/packages/simulation/www/siminst/simulation-start.tcl 17 Dec 2003 16:51:24 -0000 1.2 @@ -7,6 +7,6 @@ workflow_id:integer } -#simulation::start -workflow_id $workflow_id +simulation::template::start -workflow_id $workflow_id ad_returnredirect "../simplay" 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.15 -r1.16 --- openacs-4/packages/simulation/tcl/simulation-procs.tcl 16 Dec 2003 16:03:29 -0000 1.15 +++ openacs-4/packages/simulation/tcl/simulation-procs.tcl 17 Dec 2003 16:51:24 -0000 1.16 @@ -143,6 +143,29 @@ @author Peter Marklund } { + 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] + 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. + + @return An array lists on the format + [list group_id1 [list group_name1 n_users1] group_id2 [list group_name2 n_users2] ...] + +with label-id pairs, suitable to be passed + as the options attribute of a form builder select widget. + + @author Peter Marklund +} { # lookup package_id of the nearest subsite subsite::get -array closest_subsite @@ -151,14 +174,31 @@ -package_id $closest_subsite(package_id)] # Get all groups related to (children of) the subsite group (only one level down) - return [db_list_of_lists subsite_group_options { + set groups_list [list] + db_foreach subsite_group_options { select g.group_name, - g.group_id + g.group_id, + (select count(*) + from party_approved_member_map pamm, + users u + where pamm.party_id = g.group_id + and pamm.member_id = u.user_id + ) as n_users from acs_rels ar, groups g where ar.object_id_one = :subsite_group_id and ar.object_id_two = g.group_id - }] + and exists (select 1 + from party_approved_member_map pamm, + users u + where pamm.party_id = g.group_id + and pamm.member_id = u.user_id + ) + } { + lappend groups_list $group_id [list $group_name $n_users] + } + + return $groups_list } template_tag relation { params } { Index: openacs-4/packages/simulation/tcl/template-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/template-procs.tcl,v diff -u -r1.21 -r1.22 --- openacs-4/packages/simulation/tcl/template-procs.tcl 17 Dec 2003 16:30:32 -0000 1.21 +++ openacs-4/packages/simulation/tcl/template-procs.tcl 17 Dec 2003 16:51:24 -0000 1.22 @@ -274,7 +274,6 @@ } } - ad_proc -public simulation::template::get_parties { {-workflow_id:required} {-rel_type "auto-enroll"} @@ -398,11 +397,15 @@ select to_char(current_timestamp, 'YYYY-MM-DD') }] if { [clock scan $today] < [clock scan $simulation(enroll_end)] } { - set simulation_edit(enroll_date) $today + set simulation_edit(enroll_end) $today } + # enroll_start must be before or equal enroll_end + if { [clock scan $today] < [clock scan $simulation(enroll_start)] } { + set simulation_edit(enroll_start) $today + } # Set start_date to now - set simulation_edit(start_date) $today + set simulation_edit(case_start) $today # Auto enroll users in auto-enroll groups set simulation_edit(enrolled) [list] @@ -448,7 +451,7 @@ }] set total_n_users [llength $user_list] - simulation::template::get_role_mappings -workflow_id $workflow_id -array roles + simulation::template::get_role_group_mappings -workflow_id $workflow_id -array roles set n_users_per_case 0 foreach role_id [array names roles] { Index: openacs-4/packages/simulation/tcl/template-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/template-procs.xql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/simulation/tcl/template-procs.xql 16 Dec 2003 16:03:29 -0000 1.4 +++ openacs-4/packages/simulation/tcl/template-procs.xql 17 Dec 2003 16:51:24 -0000 1.5 @@ -14,11 +14,11 @@ s.sim_type, s.enroll_type, s.casting_type, - to_char(s.enroll_start, 'YYYY-MM-DD'), - to_char(s.enroll_end, 'YYYY-MM-DD'), - to_char(s.case_start, 'YYYY-MM-DD'), - to_char(s.case_end, 'YYYY-MM-DD'), - to_char(s.send_start_note_date, 'YYYY-MM-DD') + to_char(s.enroll_start, 'YYYY-MM-DD') as enroll_start, + to_char(s.enroll_end, 'YYYY-MM-DD') as enroll_end, + to_char(s.case_start, 'YYYY-MM-DD') as case_start, + to_char(s.case_end, 'YYYY-MM-DD') as case_end, + to_char(s.send_start_note_date, 'YYYY-MM-DD') as send_start_note_date from workflows w, sim_simulations s where w.workflow_id = :workflow_id 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.8 -r1.9 --- openacs-4/packages/simulation/www/siminst/simulation-casting-2.tcl 17 Dec 2003 10:43:07 -0000 1.8 +++ openacs-4/packages/simulation/www/siminst/simulation-casting-2.tcl 17 Dec 2003 16:51:24 -0000 1.9 @@ -33,7 +33,7 @@ {value $in_two_months_date} } {notification_date:date - {label "Date to send start notification"} + {label "Date to send start notification (mockup only)"} {value $in_two_and_a_half_months_date} } {case_start:date @@ -83,7 +83,8 @@ array unset sim_template set sim_template(enroll_start) $enroll_start_ansi set sim_template(enroll_end) $enroll_end_ansi - set sim_template(notification_date) $notification_date_ansi + # TODO: + #set sim_template(notification_date) $notification_date_ansi set sim_template(case_start) $case_start_ansi set sim_template(case_end) $case_end_ansi set sim_template(enroll_type) $enroll_type 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.4 -r1.5 --- openacs-4/packages/simulation/www/siminst/simulation-casting-3.tcl 17 Dec 2003 11:02:36 -0000 1.4 +++ openacs-4/packages/simulation/www/siminst/simulation-casting-3.tcl 17 Dec 2003 16:51:24 -0000 1.5 @@ -41,11 +41,29 @@ } } -on_submit { - # TODO: move this code into the simulation::template::edit proc? Low priority. + # 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] + set error_p 0 + foreach role_id [workflow::get_roles -workflow_id $workflow_id] { + set group_size [set group_$role_id] + set group_id [set actor_$role_id] + set n_members [lindex $groups($group_id) 1] + if { $group_size > $n_members } { + template::form::set_error actors group_$role_id "Group size is larger than the number of users in the group: $n_members" + set error_p 1 + break + } + } + if { $error_p } { + break + } + + # TODO: move this code into the simulation::template::edit proc? Low priority. # Clear out old mappings simulation::template::delete_role_group_mappings -workflow_id $workflow_id - foreach role_id [workflow::get_roles -workflow_id $workflow_id] { simulation::template::new_role_group_mapping \ -role_id $role_id \ Index: openacs-4/packages/simulation/www/siminst/simulation-start.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/simulation-start.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/simulation/www/siminst/simulation-start.tcl 16 Dec 2003 16:00:34 -0000 1.1 +++ openacs-4/packages/simulation/www/siminst/simulation-start.tcl 17 Dec 2003 16:51:24 -0000 1.2 @@ -7,6 +7,6 @@ workflow_id:integer } -#simulation::start -workflow_id $workflow_id +simulation::template::start -workflow_id $workflow_id ad_returnredirect "../simplay"