Index: openacs-4/contrib/packages/simulation/www/simplay/cast-join.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/cast-join.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/simplay/cast-join.tcl 19 Jan 2004 14:02:33 -0000 1.1 @@ -0,0 +1,125 @@ +ad_page_contract { + This script will cast a user in a simulation case. If role id is provided the user + will be cast in that role. + + @author Peter Marklund +} { + {workflow_id:integer ""} + {case_id:integer ""} + {role_id:integer ""} +} + +# We need either case_id or workflow_id +if { [empty_string_p $workflow_id] && [empty_string_p $case_id] } { + ad_return_error "Missing parameters" "Either of the HTTP parameters workflow_id and case_id must be provided. Please contact the system administrator about this error." + ad_script_abort +} + +# Get simulation info +if { [empty_string_p $workflow_id] } { + workflow::case::get -case_id $case_id -array case + set workflow_id $case(workflow_id) +} +simulation::template::get -workflow_id $workflow_id -array simulation + +# We require the user to be enrolled +auth::require_login +set user_id [ad_conn user_id] +set enrolled_p [simulation::template::user_enrolled_p -workflow_id $workflow_id] +if { !$enrolled_p } { + ad_return_forbidden \ + "Not enrolled in simulation \"$simulation(pretty_name)\"" \ + "
+ We are sorry, but since you are not enrolled in simulation \"$simulation(pretty_name)\" you can not choose case or role in it. +
" + ad_script_abort +} + +if { ![empty_string_p $role_id] } { + # Role id specified so cast to that role + + if { ![string equal $simulation(casting_type) "open"] } { + ad_return_forbidden \ + "Cannot choose role in \"$simulation(pretty_name)\"" \ + "
+ We are sorry, but simulation \"$simulation(pretty_name)\" does not allow users to choose role (casting type is not open). This message means the system is not operating correctly. Please contact the system administrator. + +Thank you! +
" + ad_script_abort + } + + # TODO: Check the max number of users for the role? + +} else { + # No role id specified + + if { [string equal $simulation(casting_type) "auto"] } { + ad_return_forbidden \ + "Cannot choose case in \"$simulation(pretty_name)\"" \ + "
+ We are sorry, but simulation \"$simulation(pretty_name)\" does not allow users to choose case (casting type is auto). This message means the system is not operating correctly. Please contact the system administrator. + +Thank you! +
" + ad_script_abort + } + + if { [empty_string_p $case_id] } { + # Create a new case + set current_n_cases [db_string current_n_cases { + select count(*) + from workflow_cases + where workflow_id = :workflow_id + }] + set sim_case_id [simulation::case::new \ + -workflow_id $workflow_id \ + -label "Case \#[expr $current_n_cases + 1]"] + set workflow_short_name [workflow::get_element -workflow_id $workflow_id -element short_name] + set case_id [workflow::case::get_id \ + -object_id $sim_case_id \ + -workflow_short_name $workflow_short_name] + } + + # Cast the user in the role with the most empty spaces. + # TODO: check for no empty spaces? + db_foreach role_with_most_empty_spaces { + select wr.role_id, + sr.users_per_case as max_n_users, + (select count(*) + from workflow_case_role_party_map wcrpm + where wcrpm.case_id = :case_id + and wcrpm.role_id = wr.role_id + ) as n_users + from workflow_roles wr, + sim_roles sr + where wr.workflow_id = :workflow_id + and wr.role_id = sr.role_id + } { + set n_empty_spots [expr $max_n_users - $n_users] + if { [expr $n_empty_spots <= 0] } { + continue + } else { + break + } + } + + if { [empty_string_p $role_id] } { + # We weren't able to find a role with empty slots + # TODO: what do we do now? + ad_return_error "No available roles" "We couldn't find any roles that you could join in the selected case (case_id=$case_id) in simulation $simulation(pretty_name). You would need to join a new case. Select your administrator if you have questions. + +Thank you!" + ad_script_abort + } +} + +# We now know the user is authorized to cast himself and we have a role to cast him to +# so carry out the casting. +set role_short_name [workflow::role::get_element -role_id $role_id -element short_name] +set role_array($role_short_name) [list $user_id] +workflow::case::role::assign \ + -case_id $case_id \ + -array role_array + +ad_returnredirect [export_vars -base cast { workflow_id }] Index: openacs-4/contrib/packages/simulation/www/simplay/cast.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/cast.adp,v diff -u -r1.3 -r1.4 --- openacs-4/contrib/packages/simulation/www/simplay/cast.adp 16 Jan 2004 17:31:45 -0000 1.3 +++ openacs-4/contrib/packages/simulation/www/simplay/cast.adp 19 Jan 2004 14:02:33 -0000 1.4 @@ -2,16 +2,52 @@ @page_title;noquote@ @context;noquote@ -

- Select which case and role to join, or create a new case for yourself. - If you do not select a case and role to join, you will be automatically - assigned to a case and role when the simulation begins. -

+ +

+ You are already cast in the following roles: +

+ +

+ +

+ Below is a listing of all users in the simulation. +

+
+ +

+ Select which case and + role to join, or create a new case for yourself. If you do not + select a case and role + to join, you will be automatically assigned to a case and role when the + simulation begins. +

+
+

+ +

+ Be the first user in a new case +

+
+ +

+  +

+

+  +

+

+  +

+

+  +

+

Mockup below:

@@ -98,11 +134,7 @@
+

-If no rows, display this text: "There are no cases yet." -

-After clicking join, redirect back to this page. Hide all buttons. -Show new text at the bottom: "You are participating in this simulation -as a player in case #X. The simulation will start XXX." -

If casting type is group instead of open, do not display or group +TODO: If casting type is group instead of open, do not display or group by the role column. Index: openacs-4/contrib/packages/simulation/www/simplay/cast.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/cast.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/contrib/packages/simulation/www/simplay/cast.tcl 16 Jan 2004 17:31:45 -0000 1.3 +++ openacs-4/contrib/packages/simulation/www/simplay/cast.tcl 19 Jan 2004 14:02:33 -0000 1.4 @@ -1,27 +1,35 @@ ad_page_contract { - This page allows users to choose which group to join. It is only relevant for simulations with casting type of group. + Page allows users to cast themselves in simulations with casting type open or group. + For casting type group the user can only choose the case to be in. If casting type + is open he/she can also choose role. + + @author Peter Marklund } { - {workflow_id:integer ""} + workflow_id:integer } auth::require_login set user_id [ad_conn user_id] set package_id [ad_conn package_id] simulation::template::get -workflow_id $workflow_id -array simulation -set page_title "Join a Case in Simulation SIMNAME" -set context [list [list "." "SimPlay"] $page_title] - +# Check user is enrolled set enrolled_p [simulation::template::user_enrolled_p -workflow_id $workflow_id] if { !$enrolled_p } { + set enroll_now_text "" + if { [string equal $simulation(enroll_type) "open"] } { + set enroll_now_text "Click here to enroll now." + } + ad_return_forbidden \ "Not enrolled in simulation \"$simulation(pretty_name)\"" \ "

- We are sorry, but since you are not enrolled in simulation \"$simulation(pretty_name)\" you can not choose case or role in it. + We are sorry, but since you are not enrolled in simulation \"$simulation(pretty_name)\" you can not choose case or role in it. $enroll_now_text
" ad_script_abort } +# Check self casting is allowed if { [string equal $simulation(casting_type) "auto"] } { ad_return_forbidden \ "You will be automatically cast in \"$simulation(pretty_name)\"" \ @@ -37,21 +45,90 @@ } template::list::create \ + -name cast_info \ + -multirow cast_info \ + -no_data "You are not cast in any roles yet" \ + -elements { + case_name { + label "Case" + } + role_name { + label "Role" + } + } + +db_multirow cast_info cast_info { + select sc.label as case_name, + wr.pretty_name as role_name + from workflow_case_role_party_map wcrpm, + workflow_cases wc, + sim_cases sc, + workflow_roles wr + where wcrpm.party_id = :user_id + and wcrpm.case_id = wc.case_id + and wc.workflow_id = :workflow_id + and wc.object_id = sc.sim_case_id + and wr.role_id = wcrpm.role_id +} + +set already_cast_p [expr ${cast_info:rowcount} > 0] + +if { !$already_cast_p } { + set page_title "Join a Case in Simulation \"$simulation(pretty_name)\"" +} else { + set page_title "User castings in simulation \"$simulation(pretty_name)\"" +} +set context [list [list "." "SimPlay"] $page_title] + + +template::list::create \ -name roles \ -multirow roles \ -no_data "There are no cases in this simulation yet" \ -elements { case_pretty { label "Case" + display_template { + @roles.case_pretty@ \[\join case] + } } + role_name { + label "Role" + } + user_name { + label "User" + } } -db_multirow -extend { join_url } roles select_case_info { - select sc.label as case_pretty +db_multirow -extend { join_case_url join_role_url } roles select_case_info { + select wc.case_id, + sc.label as case_pretty, + cu.first_names || ' ' || cu.last_name as user_name, + wr.pretty_name as role_name from workflow_cases wc, - sim_cases sc - where wc.case_id = sc.sim_case_id + sim_cases sc, + workflow_case_role_party_map wcrpm, + workflow_roles wr, + cc_users cu + where wc.object_id = sc.sim_case_id and wc.workflow_id = :workflow_id + and wcrpm.case_id = wc.case_id + and wcrpm.party_id = cu.user_id + and wr.role_id = wcrpm.role_id + order by sc.label, wr.pretty_name, cu.last_name } { - set join_url [export_vars -base cast-join { case_id role_id }] + set join_case_url "" + set join_role_url "" + + if { !$already_cast_p } { + if { [string equal $simulation(casting_type) "group"] } { + set join_case_url [export_vars -base cast-join { case_id }] + } else { + set join_role_url [export_vars -base cast-join { case_id role_id }] + } + } } + +if { !$already_cast_p } { + set join_new_case_url [export_vars -base cast-join { workflow_id }] +} Index: openacs-4/packages/simulation/www/simplay/cast-join.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/cast-join.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/simplay/cast-join.tcl 19 Jan 2004 14:02:33 -0000 1.1 @@ -0,0 +1,125 @@ +ad_page_contract { + This script will cast a user in a simulation case. If role id is provided the user + will be cast in that role. + + @author Peter Marklund +} { + {workflow_id:integer ""} + {case_id:integer ""} + {role_id:integer ""} +} + +# We need either case_id or workflow_id +if { [empty_string_p $workflow_id] && [empty_string_p $case_id] } { + ad_return_error "Missing parameters" "Either of the HTTP parameters workflow_id and case_id must be provided. Please contact the system administrator about this error." + ad_script_abort +} + +# Get simulation info +if { [empty_string_p $workflow_id] } { + workflow::case::get -case_id $case_id -array case + set workflow_id $case(workflow_id) +} +simulation::template::get -workflow_id $workflow_id -array simulation + +# We require the user to be enrolled +auth::require_login +set user_id [ad_conn user_id] +set enrolled_p [simulation::template::user_enrolled_p -workflow_id $workflow_id] +if { !$enrolled_p } { + ad_return_forbidden \ + "Not enrolled in simulation \"$simulation(pretty_name)\"" \ + "
+ We are sorry, but since you are not enrolled in simulation \"$simulation(pretty_name)\" you can not choose case or role in it. +
" + ad_script_abort +} + +if { ![empty_string_p $role_id] } { + # Role id specified so cast to that role + + if { ![string equal $simulation(casting_type) "open"] } { + ad_return_forbidden \ + "Cannot choose role in \"$simulation(pretty_name)\"" \ + "
+ We are sorry, but simulation \"$simulation(pretty_name)\" does not allow users to choose role (casting type is not open). This message means the system is not operating correctly. Please contact the system administrator. + +Thank you! +
" + ad_script_abort + } + + # TODO: Check the max number of users for the role? + +} else { + # No role id specified + + if { [string equal $simulation(casting_type) "auto"] } { + ad_return_forbidden \ + "Cannot choose case in \"$simulation(pretty_name)\"" \ + "
+ We are sorry, but simulation \"$simulation(pretty_name)\" does not allow users to choose case (casting type is auto). This message means the system is not operating correctly. Please contact the system administrator. + +Thank you! +
" + ad_script_abort + } + + if { [empty_string_p $case_id] } { + # Create a new case + set current_n_cases [db_string current_n_cases { + select count(*) + from workflow_cases + where workflow_id = :workflow_id + }] + set sim_case_id [simulation::case::new \ + -workflow_id $workflow_id \ + -label "Case \#[expr $current_n_cases + 1]"] + set workflow_short_name [workflow::get_element -workflow_id $workflow_id -element short_name] + set case_id [workflow::case::get_id \ + -object_id $sim_case_id \ + -workflow_short_name $workflow_short_name] + } + + # Cast the user in the role with the most empty spaces. + # TODO: check for no empty spaces? + db_foreach role_with_most_empty_spaces { + select wr.role_id, + sr.users_per_case as max_n_users, + (select count(*) + from workflow_case_role_party_map wcrpm + where wcrpm.case_id = :case_id + and wcrpm.role_id = wr.role_id + ) as n_users + from workflow_roles wr, + sim_roles sr + where wr.workflow_id = :workflow_id + and wr.role_id = sr.role_id + } { + set n_empty_spots [expr $max_n_users - $n_users] + if { [expr $n_empty_spots <= 0] } { + continue + } else { + break + } + } + + if { [empty_string_p $role_id] } { + # We weren't able to find a role with empty slots + # TODO: what do we do now? + ad_return_error "No available roles" "We couldn't find any roles that you could join in the selected case (case_id=$case_id) in simulation $simulation(pretty_name). You would need to join a new case. Select your administrator if you have questions. + +Thank you!" + ad_script_abort + } +} + +# We now know the user is authorized to cast himself and we have a role to cast him to +# so carry out the casting. +set role_short_name [workflow::role::get_element -role_id $role_id -element short_name] +set role_array($role_short_name) [list $user_id] +workflow::case::role::assign \ + -case_id $case_id \ + -array role_array + +ad_returnredirect [export_vars -base cast { workflow_id }] Index: openacs-4/packages/simulation/www/simplay/cast.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/cast.adp,v diff -u -r1.3 -r1.4 --- openacs-4/packages/simulation/www/simplay/cast.adp 16 Jan 2004 17:31:45 -0000 1.3 +++ openacs-4/packages/simulation/www/simplay/cast.adp 19 Jan 2004 14:02:33 -0000 1.4 @@ -2,16 +2,52 @@ @page_title;noquote@ @context;noquote@ -

- Select which case and role to join, or create a new case for yourself. - If you do not select a case and role to join, you will be automatically - assigned to a case and role when the simulation begins. -

+ +

+ You are already cast in the following roles: +

+ +

+ +

+ Below is a listing of all users in the simulation. +

+
+ +

+ Select which case and + role to join, or create a new case for yourself. If you do not + select a case and role + to join, you will be automatically assigned to a case and role when the + simulation begins. +

+
+

+ +

+ Be the first user in a new case +

+
+ +

+  +

+

+  +

+

+  +

+

+  +

+

Mockup below:

@@ -98,11 +134,7 @@
+

-If no rows, display this text: "There are no cases yet." -

-After clicking join, redirect back to this page. Hide all buttons. -Show new text at the bottom: "You are participating in this simulation -as a player in case #X. The simulation will start XXX." -

If casting type is group instead of open, do not display or group +TODO: If casting type is group instead of open, do not display or group by the role column. Index: openacs-4/packages/simulation/www/simplay/cast.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/cast.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/simulation/www/simplay/cast.tcl 16 Jan 2004 17:31:45 -0000 1.3 +++ openacs-4/packages/simulation/www/simplay/cast.tcl 19 Jan 2004 14:02:33 -0000 1.4 @@ -1,27 +1,35 @@ ad_page_contract { - This page allows users to choose which group to join. It is only relevant for simulations with casting type of group. + Page allows users to cast themselves in simulations with casting type open or group. + For casting type group the user can only choose the case to be in. If casting type + is open he/she can also choose role. + + @author Peter Marklund } { - {workflow_id:integer ""} + workflow_id:integer } auth::require_login set user_id [ad_conn user_id] set package_id [ad_conn package_id] simulation::template::get -workflow_id $workflow_id -array simulation -set page_title "Join a Case in Simulation SIMNAME" -set context [list [list "." "SimPlay"] $page_title] - +# Check user is enrolled set enrolled_p [simulation::template::user_enrolled_p -workflow_id $workflow_id] if { !$enrolled_p } { + set enroll_now_text "" + if { [string equal $simulation(enroll_type) "open"] } { + set enroll_now_text "Click here to enroll now." + } + ad_return_forbidden \ "Not enrolled in simulation \"$simulation(pretty_name)\"" \ "

- We are sorry, but since you are not enrolled in simulation \"$simulation(pretty_name)\" you can not choose case or role in it. + We are sorry, but since you are not enrolled in simulation \"$simulation(pretty_name)\" you can not choose case or role in it. $enroll_now_text
" ad_script_abort } +# Check self casting is allowed if { [string equal $simulation(casting_type) "auto"] } { ad_return_forbidden \ "You will be automatically cast in \"$simulation(pretty_name)\"" \ @@ -37,21 +45,90 @@ } template::list::create \ + -name cast_info \ + -multirow cast_info \ + -no_data "You are not cast in any roles yet" \ + -elements { + case_name { + label "Case" + } + role_name { + label "Role" + } + } + +db_multirow cast_info cast_info { + select sc.label as case_name, + wr.pretty_name as role_name + from workflow_case_role_party_map wcrpm, + workflow_cases wc, + sim_cases sc, + workflow_roles wr + where wcrpm.party_id = :user_id + and wcrpm.case_id = wc.case_id + and wc.workflow_id = :workflow_id + and wc.object_id = sc.sim_case_id + and wr.role_id = wcrpm.role_id +} + +set already_cast_p [expr ${cast_info:rowcount} > 0] + +if { !$already_cast_p } { + set page_title "Join a Case in Simulation \"$simulation(pretty_name)\"" +} else { + set page_title "User castings in simulation \"$simulation(pretty_name)\"" +} +set context [list [list "." "SimPlay"] $page_title] + + +template::list::create \ -name roles \ -multirow roles \ -no_data "There are no cases in this simulation yet" \ -elements { case_pretty { label "Case" + display_template { + @roles.case_pretty@ \[\join case] + } } + role_name { + label "Role" + } + user_name { + label "User" + } } -db_multirow -extend { join_url } roles select_case_info { - select sc.label as case_pretty +db_multirow -extend { join_case_url join_role_url } roles select_case_info { + select wc.case_id, + sc.label as case_pretty, + cu.first_names || ' ' || cu.last_name as user_name, + wr.pretty_name as role_name from workflow_cases wc, - sim_cases sc - where wc.case_id = sc.sim_case_id + sim_cases sc, + workflow_case_role_party_map wcrpm, + workflow_roles wr, + cc_users cu + where wc.object_id = sc.sim_case_id and wc.workflow_id = :workflow_id + and wcrpm.case_id = wc.case_id + and wcrpm.party_id = cu.user_id + and wr.role_id = wcrpm.role_id + order by sc.label, wr.pretty_name, cu.last_name } { - set join_url [export_vars -base cast-join { case_id role_id }] + set join_case_url "" + set join_role_url "" + + if { !$already_cast_p } { + if { [string equal $simulation(casting_type) "group"] } { + set join_case_url [export_vars -base cast-join { case_id }] + } else { + set join_role_url [export_vars -base cast-join { case_id role_id }] + } + } } + +if { !$already_cast_p } { + set join_new_case_url [export_vars -base cast-join { workflow_id }] +}