Index: openacs-4/contrib/packages/simulation/tcl/action-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/action-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/simulation/tcl/action-procs.tcl 10 Dec 2003 16:06:46 -0000 1.4 +++ openacs-4/contrib/packages/simulation/tcl/action-procs.tcl 15 Dec 2003 15:28:20 -0000 1.5 @@ -8,33 +8,60 @@ namespace eval simulation::action {} + +# TODO: add simulation::action::new + ad_proc -public simulation::action::edit { {-action_id:required} {-workflow_id {}} {-array:required} {-internal:boolean} } { Edit an action. Mostly a wrapper for FSM, plus some simulation-specific stuff. + + Available attributes: recipient (role_id), recipient_role (role short_name), attachment_num } { upvar 1 $array org_row + if { ![array exists org_row] } { + error "Array $array does not exist or is not an array" + } array set row [array get org_row] - + + set set_clauses [list] + + # Handle attributes in sim_tasks table + if { [info exists row(recipient_role)] } { + if { [empty_string_p $row(recipient_role)] } { + set row(recipient) [db_null] + } else { + # Get role_id by short_name + set row(recipient) [workflow::role::get_id \ + -workflow_id $workflow_id \ + -short_name $row(recipient_role)] + } + unset row(recipient_role) + } + + foreach attr { + recipient attachment_num + } { + if { [info exists row($attr)] } { + set varname attr_$attr + # Convert the Tcl value to something we can use in the query + set $varname $row($attr) + # Add the column to the SET clause + lappend set_clauses "$attr = :$varname" + unset row($attr) + } + } + db_transaction { - if { [info exists row(recipient_role)] } { - if { ![empty_string_p $row(recipient_role)] } { - set recipient_role_id [workflow::role::get_id \ - -workflow_id $workflow_id \ - -short_name $row(recipient_role)] - } else { - set recipient_role_id [db_null] - } - db_dml edit_sim_role { + if { [llength $set_clauses] > 0 } { + db_dml edit_sim_role " update sim_tasks - set recipient = :recipient_role_id + set [join $set_clauses ", "] where task_id = :action_id - } - - unset row(recipient_role) + " } workflow::action::fsm::edit \