Index: openacs-4/packages/curriculum-central/tcl/uos-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/curriculum-central/tcl/uos-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/curriculum-central/tcl/uos-procs.tcl 11 Dec 2005 07:47:40 -0000 1.3 +++ openacs-4/packages/curriculum-central/tcl/uos-procs.tcl 15 Dec 2005 06:27:41 -0000 1.4 @@ -64,10 +64,9 @@ states { open { pretty_name "#curriculum-central.open#" - hide_fields { resolution fixed_in_version } } - completed { - pretty_name "#curriculum-central.completed#" + submitted { + pretty_name "#curriculum-central.submitted#" } closed { pretty_name "#curriculum-central.closed#" @@ -103,50 +102,46 @@ privileges { write } always_enabled_p t edit_fields { - component_id - summary - found_in_version - role_resolver - fix_for_version - resolution - fixed_in_version + contact_hours + assessments + online_course_content + objectives + outcomes } } reassign { pretty_name "#curriculum-central.reassign#" pretty_past_tense "#curriculum-central.reassigned#" allowed_roles { stream_coordinator - unit_coordinator } privileges { write } - enabled_states { completed } + enabled_states { submitted } assigned_states { open } - edit_fields { role_resolver } + edit_fields { unit_coordinator_id } } - complete { - pretty_name "#curriculum-central.complete#" - pretty_past_tense "#curriculum-central.completed#" + submit { + pretty_name "#curriculum-central.submit#" + pretty_past_tense "#curriculum-central.submitted#" assigned_role unit_coordinator - enabled_states { completed } + enabled_states { submitted } assigned_states { open } - new_state completed + new_state submitted privileges { write } - edit_fields { resolution fixed_in_version } } close { pretty_name "#curriculum-central.close#" pretty_past_tense "#curriculum-central.closed#" assigned_role stream_coordinator - assigned_states { completed } + assigned_states { submitted } new_state closed privileges { write } } reopen { pretty_name "#curriculum-central.reopen#" pretty_past_tense "#curriculum-central.reopened#" allowed_roles { stream_coordinator unit_coordinator } - enabled_states { completed closed } + enabled_states { submitted closed } new_state open privileges { write } } @@ -221,77 +216,260 @@ # ##### +ad_proc -public curriculum_central::uos::get { + {-uos_id:required} + {-array:required} + {-enabled_action_id {}} +} { + Get the fields for a Unit of Study. + + @param uos_id The ID of the Unit of Study for which we return + fields for. + @param array A predefined array for returning fields in. + @param enabled_action_id ID ofthe enabled workflow action. +} { + # Select the info into the upvar'ed Tcl array + upvar $array row + + db_1row select_latest_uos_data {} -column_array row + + # Get the case ID, so we can get state information + set case_id [workflow::case::get_id \ + -object_id $uos_id \ + -workflow_short_name [curriculum_central::uos::workflow_short_name]] + + # Get state information + workflow::case::fsm::get -case_id $case_id -array case \ + -enabled_action_id $enabled_action_id + + set row(pretty_state) $case(pretty_state) + set row(state_short_name) $case(state_short_name) + set row(hide_fields) $case(state_hide_fields) + set row(entry_id) $case(entry_id) +} + + ad_proc -public curriculum_central::uos::new { -uos_id:required -package_id:required -uos_code:required -uos_name:required -credit_value:required -semester:required - -online_course_content -unit_coordinator_id:required - -contact_hours:required - -assessments:required -core_uos_for -recommended_uos_for -prerequisites:required - -objectives:required - -outcomes:required - -syllabus:required - -syllabus_format:required + -activity_log:required + -activity_log_format:required {-user_id ""} } { Create a new Unit of Study, then send out notifications, starts workflow, etc. + This proc creates a new Unit of Study revision. The live revision is + set at the end of the workflow, when the stream coordinator approves + the Unit of Study. + + Calls curriculum_central::uos::insert. + + @see curriculum_central::uos::insert. @return uos_id The same uos_id passed in, for convenience. } { db_transaction { if { $user_id eq ""} { set user_id [ad_conn user_id] } - set uos_id [package_instantiate_object \ - -var_list [list [list uos_id $uos_id] \ - [list package_id $package_id] \ - [list user_id $user_id] \ - [list uos_code $uos_code] \ - [list uos_name $uos_name] \ - [list credit_value $credit_value] \ - [list semester $semester] \ - [list online_course_content $online_course_content] \ - [list unit_coordinator_id $unit_coordinator_id] \ - [list contact_hours $contact_hours] \ - [list assessments $assessments] \ - [list core_uos_for $core_uos_for] \ - [list recommended_uos_for $recommended_uos_for] \ - [list prerequisites $prerequisites] \ - [list objectives $objectives] \ - [list outcomes $outcomes] \ - [list syllabus $syllabus] \ - [list syllabus_format $syllabus_format] \ - [list object_type "cc_uos"]] \ - -package_name "cc_uos" \ - "cc_uos"] + set uos_id [curriculum_central::uos::insert \ + -uos_id $uos_id \ + -package_id $package_id \ + -user_id $user_id \ + -uos_code $uos_code \ + -uos_name $uos_name \ + -credit_value $credit_value \ + -semester $semester \ + -unit_coordinator_id $unit_coordinator_id \ + -core_uos_for $core_uos_for \ + -recommended_uos_for $recommended_uos_for \ + -prerequisites $prerequisites \ + -activity_log $activity_log \ + -activity_log_format $activity_log_format ] array set assign_array [list unit_coordinator $unit_coordinator_id] + set workflow_id [workflow::get_id \ + -object_id $package_id \ + -short_name [workflow_short_name]] + # Create a new workflow case for the given UoS. set case_id [workflow::case::new \ - -workflow_id [workflow::get_id \ - -object_id $package_id \ - -short_name [workflow_short_name]] \ + -workflow_id $workflow_id \ -object_id $uos_id \ - -comment $syllabus \ - -comment_mime_type $syllabus_format \ + -comment $activity_log \ + -comment_mime_type $activity_log_format \ -user_id $user_id \ -assignment [array get assign_array]] + + # Get the role_id for the stream coordinator role. + set role_id [workflow::role::get_id -workflow_id $workflow_id \ + -short_name stream_coordinator] + + # Get a list of stream coordinator IDs. + # All stream coordinators are assigned the role of stream coordinator + # for all Units of Study. + set stream_coordinator_ids [db_list get_stream_coordinator_ids {}] + + # Assign the stream coordinators + workflow::case::role::assignee_insert -case_id $case_id \ + -role_id $role_id -party_ids $stream_coordinator_ids -replace + return $uos_id } } +ad_proc -public curriculum_central::uos::insert { + -uos_id:required + -package_id:required + -uos_code:required + -uos_name:required + -credit_value:required + -semester:required + -unit_coordinator_id:required + -core_uos_for + -recommended_uos_for + -prerequisites:required + -activity_log:required + -activity_log_format:required + {-user_id ""} +} { + Inserts a new Unit of Study into the content repository. You should + use curriculum_central::uos::new to make use of workflow side-effects. + + @see curriculum_central::uos::new + @return uos_id The same uos_id passed in, for convenience. +} { + set uos_id [package_instantiate_object \ + -var_list [list [list uos_id $uos_id] \ + [list package_id $package_id] \ + [list user_id $user_id] \ + [list uos_code $uos_code] \ + [list uos_name $uos_name] \ + [list credit_value $credit_value] \ + [list semester $semester] \ + [list unit_coordinator_id $unit_coordinator_id] \ + [list core_uos_for $core_uos_for] \ + [list recommended_uos_for $recommended_uos_for] \ + [list prerequisites $prerequisites] \ + [list activity_log $activity_log] \ + [list activity_log_format $activity_log_format] \ + [list object_type "cc_uos"]] \ + -package_name "cc_uos" \ + "cc_uos"] +} + + +ad_proc -public curriculum_central::uos::edit { + -uos_id:required + -enabled_action_id:required + -activity_log:required + -activity_log_format:required + -array:required + {-user_id ""} + {-creation_ip ""} + {-entry_id {}} +} { + Edit a Unit of Study, then send out notifications as workflow + side-effects. + + @return uos_id The same uos_id passed in, for convenience. +} { + # TODO: Implement this proc. + upvar $array row + + array set assignments [list] + + set role_prefix "role_" + foreach name [array names row "${role_prefix}*"] { + set assignments([string range $name \ + [string length $role_prefix] end]) $row($name) + unset row($name) + } + + db_transaction { + # Update the UoS info. + curriculum_central::uos::update -uos_id $uos_id \ + -user_id $user_id \ + -creation_ip $creation_ip \ + -array row + + set case_id [workflow::case::get_id \ + -workflow_short_name [workflow_short_name] \ + -object_id $uos_id] + + # Assignments + workflow::case::role::assign \ + -replace \ + -case_id $case_id \ + -array assignments + + workflow::case::action::execute \ + -enabled_action_id $enabled_action_id \ + -comment $activity_log \ + -comment_mime_type $activity_log_format \ + -user_id $user_id \ + -entry_id $entry_id + + } + + return $uos_id +} + + +ad_proc -public curriculum_central::uos::update { + -uos_id:required + {-user_id ""} + {-creation_ip ""} + -array:required +} { + Update a Unit of Study in the DB. This proc is called by + curriculum_central::uos::edit. Use the edit proc to change + workflow. This update proc creates a new revision of the + given Unit of Study. + + @param uos_id The ID of the Unit of Study to update. + @param user_id The ID of the user that updated the Unit of Study. + @param creation_ip The IP of the user that made the update. + @param array An array of updated Unit of Study fields. + @see curriculum_central::uos::edit + @return uos_id The same uos_id passed in, for convenience. +} { + upvar $array row + + if { ![exists_and_not_null user_id] } { + set user_id [ad_conn user_id] + } + + curriculum_central::uos::get -uos_id $uos_id -array new_row + + foreach column [array names row] { + set new_row($column) $row($column) + } + set new_row(creation_user) $user_id + set new_row(creation_ip) $creation_ip + + foreach name [array names new_row] { + set $name $new_row($name) + } + + set revision_id [db_exec_plsql update_uos {}] + + return $uos_id +} + + ##### # # Format log title