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.12 -r1.13 --- openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 14 Nov 2003 11:40:35 -0000 1.12 +++ openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 28 Nov 2003 16:55:52 -0000 1.13 @@ -108,6 +108,124 @@ } } +ad_proc simulation::get_object_options { + {-content_type:required} +} { + Returns a list of cr_revision.title, cr_item.item_id pairs + for all cr_items of the given content_type in the root + folder of the current package. Suitable for ad_form options for + select boxes. + + @return [list [list cr_revision.title1 cr_item.item_id1] [list cr_revision.title2 cr_item.item_id2] ....] + + @author Peter Marklund +} { + set package_id [ad_conn package_id] + set parent_id [bcms::folder::get_id_by_package_id -package_id $package_id] + + return [db_list_of_lists character_options { + select cr.title, + ci.item_id + from cr_items ci, + cr_revisions cr + where ci.live_revision = cr.revision_id + and ci.parent_id = :parent_id + and ci.content_type = :content_type + }] +} + +ad_proc -public simulation::cast { + {-workflow_id:required} + {-pretty_name:required} + {-actors:required} + {-groupings:required} +} { + Takes a mapped simulation template and creates a casted simulation + with simulation cases. It does this by cloning the simulation + template. + + TODO: agent support + + TODO: taking actor type into account + + @param actors An array list with the actors of the simulation. The keys + of the list are role_ids and the values ids of the actor to play the role. + @param groups An array list with the groupings of the simulation. The keys + of the list are role_ids and the values are integers indicaing + a number of users to play that role. + + @return workflow_id of the simulation created. + + @author Peter Marklund +} { + array set actors_array $actors + array set groupings_array $groupings + + # TODO: make sure this is a proper clone also after mapping (tasks and characters...) + set workflow_id [simulation::template::clone \ + -pretty_name $pretty_name \ + -workflow_id $workflow_id] + + set user_list [db_list select_users { + select member_id + from party_approved_member_map + where party_id in (select + party_id from sim_party_sim_map + where simulation_id = :workflow_id + ) + }] + set total_n_users [llength $user_list] + + set n_users_per_case 0 + foreach role_id [array names groupings_array] { + set n_users_per_case [expr $n_users_per_case + $groupings_array($role_id)] + } + + set mod_n_users [expr $total_n_users % $n_users_per_case] + set n_cases [expr ($total_n_users - $mod_n_users) / $n_users_per_case] + + + if { $mod_n_users == "0" } { + # No rest in dividing, the cases add up nicely + + } else { + # We are missing mod_n_users to fill up the simulation. Create a new simulation + # for those students. + set n_cases [expr $n_cases + 1] + } + + # Create the cases and for each case assign roles to parties + set users_start_index 0 + for { set case_counter 0 } { $case_counter < $n_cases } { incr case_counter } { + # TODO: what should object_id be here? + set object_id [ad_conn package_id] + set case_id [workflow::case::new \ + -workflow_id $workflow_id \ + -object_id $object_id] + + # Assign a group of users to each role in the case + set party_array_list [list] + foreach role_id [array names actors] { + set role_short_name [workflow::role::get_element -role_id $role_id -element short_name] + + set users_end_index [expr $users_start_index + $groupings_array($role_id) - 1] + + set parties_list [lrange $user_list $users_start_index $users_end_index] + + lappend parties_array_list $role_short_name $users_list + + set users_start_index [expr $users_end_index + 1] + } + + workflow::case::role::assign \ + -case_id $case_id \ + -array $party_array_list \ + -replace + } + + return $workflow_id +} + template_tag relation { params } { publish::process_tag relation $params }