Index: openacs-4/contrib/packages/simulation/tcl/object-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/object-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/tcl/object-procs.tcl 7 Nov 2003 16:08:45 -0000 1.1 @@ -0,0 +1,173 @@ +ad_library { + API for Simulation objects. + + @author Peter Marklund + @creation-date 2003-11-07 + @cvs-id $Id: object-procs.tcl,v 1.1 2003/11/07 16:08:45 peterm Exp $ +} + +namespace eval simulation::object {} + +ad_proc -public simulation::object::schedule_generate_xml_file { + {-package_id ""} +} { +

+ Schedules the proc simulation::object::generate_xml_file to be + executed now in its own thread. +

+ +

+ This proc needs to be invoked upon the create, edit, and delete + event for simulation objects that have the on_map_p attribute + set to true. It also needs to be invoked if the on_map_p attribute + is toggled from false to true for a sim object. +

+ + + + @author Peter Marklund +} { + if { [empty_string_p $package_id] } { + set package_id [ad_conn package_id] + } + + ad_schedule_proc -thread t -once t 0 simulation::object::generate_xml_file -package_id $package_id +} + +ad_proc -public simulation::object::generate_xml_file { + {-package_id:required} +} { +

+ Re-generates (or generates for the first time) the XML file + containing information about all simulation objects that are + to be on the SIMBUILD flash map. +

+ + @author Peter Marklund +} { + ########## + # Get data to be written to file + ########## + + # Get a list of names of tables storing the on_map_p attribute for + # items created in the given package + set parent_id [bcms::folder::get_id_by_package_id -parent_id 0] + set sim_table_lists [db_list select_sim_tables { + select aot.table_name, + aot.id_column + from acs_object_types aot, + acs_attributes aa + where aot.object_type = aa.object_type + and aa.attribute_name = 'on_map_p' + and exists (select 1 + from cr_items ci + where ci.parent_id = :parent_id + and ci.content_type = aot.object_type + ) + }] + + foreach sim_table $sim_table_list { + set table_name [lindex $sim_table 0] + set id_column [lindex $sim_table 1] + + set object_lists [db_list_of_lists select_on_map_objects " + select ci.item_id, + cr.content_type + cr.title, + ci.name, + cr.description, + from cr_items ci + cr_revisions cr + $table_name st + where st.on_map_p = 't' + and st.$id_column = ci.item_id + and ci.live_revision = cr.revision_id + and ci.parent_id = :parent_id + "] + } + + ########## + # Generate XML document + ########## + + set xml_doc " +" + foreach object_list $object_lists { + append xml_doc [generate_xml \ + -item_id [lindex $object_list 0] \ + -content_type [lindex $object_list 1] \ + -title [lindex $object_list 2] \ + -name [lindex $object_list 3] \ + -description [lindex $object_list 4]] + } + append xml_doc "" + + ########## + # Write to file + ########## + + # TODO: make filepath a parameter + set file_path "/tmp/map-objects.xml" + set file_id [open $file_path w] + puts $file_id $xml_doc + close $catalog_file_id +} + +ad_proc -public simulation::object::generate_xml { + {-item_id:required} + {-content_type ""} + {-title ""} + {-name ""} + {-description ""} +} { +

+ Generate XML to be used by the CityBuild flash map for a certain + simulation object. Requires there to be an HTTP connection as it + uses ad_conn package_url to get the URL of the object. +

+ + @param item_id Stored in cr_items.item_id + @param content_type Stored in cr_items.content_type + @param title Stored in cr_revisions.title + @param name Stored in cr_items.name + @param description Stored in cr_revisions.description + + @author Peter Marklund +} { + # Set default values for optional args + set optional_args {content_type title name description} + foreach arg_name $optional_args { + if { [empty_string_p [set $arg_name]] } { + if { ![info exists item_info] } { + array set item_info [bcms::item::get_item -item_id $item_id -revision live] + } + + set $arg_name $item_info($arg_name) + } + } + + # Get object url and thumbnail url + set full_package_url "[ad_url]/[ad_conn package_url]" + set url "$full_package_url/object/$name" + if { [lsearch -exact {sim_location sim_prop sim_character} $content_type] != -1 } { + set thumbnail_list [bcms::item::list_related_items \ + -return_list \ + -item_id $item_id \ + -relation_tag thumbnail] + set thumbnail_uri [lindex [lindex $thumbnail_list 0] 1] + set thumbnail_url "$full_package_url/object-content/$thumbnail_uri" + } else { + set thumbnail_url "" + } + + # Create XML document + append flash_xml " + $item_id + [ad_quotehtml $name] + [ad_quotehtml $url] + [ad_quotehtml $thumbnail_url] + [ad_quotehtml $description] +" + + return $flash_xml +} Index: openacs-4/contrib/packages/simulation/www/object-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/object-edit.adp,v diff -u -r1.3 -r1.4 --- openacs-4/contrib/packages/simulation/www/object-edit.adp 3 Nov 2003 14:13:43 -0000 1.3 +++ openacs-4/contrib/packages/simulation/www/object-edit.adp 7 Nov 2003 16:08:45 -0000 1.4 @@ -49,4 +49,10 @@ + +

+ View map XML +

+
+ Index: openacs-4/contrib/packages/simulation/www/object-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/object-edit.tcl,v diff -u -r1.16 -r1.17 --- openacs-4/contrib/packages/simulation/www/object-edit.tcl 3 Nov 2003 14:13:43 -0000 1.16 +++ openacs-4/contrib/packages/simulation/www/object-edit.tcl 7 Nov 2003 16:08:45 -0000 1.17 @@ -12,21 +12,6 @@ # TODO: Joel will do something about this? auth::require_login -#--------------------------------------------------------------------- -# Determine if we are in edit mode or display mode -#--------------------------------------------------------------------- -# this is prototype code to correct for get_action's apparent -# unreliability - -#set mode [template::form::get_action sim_template] -#if { ![exists_and_not_null workflow_id]} { -# set mode "add" -#} else { -# # for now, use edit mode in place of display mode -# # set mode "display" -# set mode "edit" -#} - if { ![ad_form_new_p -key item_id] } { # Get data for existing object array set item_info [bcms::item::get_item -item_id $item_id -revision live] @@ -41,7 +26,6 @@ } set context [list [list "object-list" "Sim Objects"] $page_title] - ###################################################################### # # object @@ -695,8 +679,6 @@ regexp {__.+__(.+)$} $elm match order_n set related_object_id [set $elm] - ns_log Notice "LARS: $elm - $related_object_id" - if { ![empty_string_p $related_object_id] } { bcms::item::relate_item \ -relation_tag $relation_tag \ Index: openacs-4/contrib/packages/simulation/www/object-xml.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/object-xml.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/object-xml.tcl 7 Nov 2003 16:08:45 -0000 1.1 @@ -0,0 +1,12 @@ +ad_page_contract { + Show flash xml for a simulation object. + + @creation-date 2003-11-07 + @cvs-id $Id: object-xml.tcl,v 1.1 2003/11/07 16:08:45 peterm Exp $ +} { + item_id:integer +} + +set flash_xml [simulation::object::generate_xml -item_id $item_id] + +ns_return 200 text/plain $flash_xml Index: openacs-4/packages/simulation/tcl/object-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/object-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/tcl/object-procs.tcl 7 Nov 2003 16:08:45 -0000 1.1 @@ -0,0 +1,173 @@ +ad_library { + API for Simulation objects. + + @author Peter Marklund + @creation-date 2003-11-07 + @cvs-id $Id: object-procs.tcl,v 1.1 2003/11/07 16:08:45 peterm Exp $ +} + +namespace eval simulation::object {} + +ad_proc -public simulation::object::schedule_generate_xml_file { + {-package_id ""} +} { +

+ Schedules the proc simulation::object::generate_xml_file to be + executed now in its own thread. +

+ +

+ This proc needs to be invoked upon the create, edit, and delete + event for simulation objects that have the on_map_p attribute + set to true. It also needs to be invoked if the on_map_p attribute + is toggled from false to true for a sim object. +

+ + + + @author Peter Marklund +} { + if { [empty_string_p $package_id] } { + set package_id [ad_conn package_id] + } + + ad_schedule_proc -thread t -once t 0 simulation::object::generate_xml_file -package_id $package_id +} + +ad_proc -public simulation::object::generate_xml_file { + {-package_id:required} +} { +

+ Re-generates (or generates for the first time) the XML file + containing information about all simulation objects that are + to be on the SIMBUILD flash map. +

+ + @author Peter Marklund +} { + ########## + # Get data to be written to file + ########## + + # Get a list of names of tables storing the on_map_p attribute for + # items created in the given package + set parent_id [bcms::folder::get_id_by_package_id -parent_id 0] + set sim_table_lists [db_list select_sim_tables { + select aot.table_name, + aot.id_column + from acs_object_types aot, + acs_attributes aa + where aot.object_type = aa.object_type + and aa.attribute_name = 'on_map_p' + and exists (select 1 + from cr_items ci + where ci.parent_id = :parent_id + and ci.content_type = aot.object_type + ) + }] + + foreach sim_table $sim_table_list { + set table_name [lindex $sim_table 0] + set id_column [lindex $sim_table 1] + + set object_lists [db_list_of_lists select_on_map_objects " + select ci.item_id, + cr.content_type + cr.title, + ci.name, + cr.description, + from cr_items ci + cr_revisions cr + $table_name st + where st.on_map_p = 't' + and st.$id_column = ci.item_id + and ci.live_revision = cr.revision_id + and ci.parent_id = :parent_id + "] + } + + ########## + # Generate XML document + ########## + + set xml_doc " +" + foreach object_list $object_lists { + append xml_doc [generate_xml \ + -item_id [lindex $object_list 0] \ + -content_type [lindex $object_list 1] \ + -title [lindex $object_list 2] \ + -name [lindex $object_list 3] \ + -description [lindex $object_list 4]] + } + append xml_doc "" + + ########## + # Write to file + ########## + + # TODO: make filepath a parameter + set file_path "/tmp/map-objects.xml" + set file_id [open $file_path w] + puts $file_id $xml_doc + close $catalog_file_id +} + +ad_proc -public simulation::object::generate_xml { + {-item_id:required} + {-content_type ""} + {-title ""} + {-name ""} + {-description ""} +} { +

+ Generate XML to be used by the CityBuild flash map for a certain + simulation object. Requires there to be an HTTP connection as it + uses ad_conn package_url to get the URL of the object. +

+ + @param item_id Stored in cr_items.item_id + @param content_type Stored in cr_items.content_type + @param title Stored in cr_revisions.title + @param name Stored in cr_items.name + @param description Stored in cr_revisions.description + + @author Peter Marklund +} { + # Set default values for optional args + set optional_args {content_type title name description} + foreach arg_name $optional_args { + if { [empty_string_p [set $arg_name]] } { + if { ![info exists item_info] } { + array set item_info [bcms::item::get_item -item_id $item_id -revision live] + } + + set $arg_name $item_info($arg_name) + } + } + + # Get object url and thumbnail url + set full_package_url "[ad_url]/[ad_conn package_url]" + set url "$full_package_url/object/$name" + if { [lsearch -exact {sim_location sim_prop sim_character} $content_type] != -1 } { + set thumbnail_list [bcms::item::list_related_items \ + -return_list \ + -item_id $item_id \ + -relation_tag thumbnail] + set thumbnail_uri [lindex [lindex $thumbnail_list 0] 1] + set thumbnail_url "$full_package_url/object-content/$thumbnail_uri" + } else { + set thumbnail_url "" + } + + # Create XML document + append flash_xml " + $item_id + [ad_quotehtml $name] + [ad_quotehtml $url] + [ad_quotehtml $thumbnail_url] + [ad_quotehtml $description] +" + + return $flash_xml +} Index: openacs-4/packages/simulation/www/object-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/object-edit.adp,v diff -u -r1.3 -r1.4 --- openacs-4/packages/simulation/www/object-edit.adp 3 Nov 2003 14:13:43 -0000 1.3 +++ openacs-4/packages/simulation/www/object-edit.adp 7 Nov 2003 16:08:45 -0000 1.4 @@ -49,4 +49,10 @@ + +

+ View map XML +

+
+ Index: openacs-4/packages/simulation/www/object-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/object-edit.tcl,v diff -u -r1.16 -r1.17 --- openacs-4/packages/simulation/www/object-edit.tcl 3 Nov 2003 14:13:43 -0000 1.16 +++ openacs-4/packages/simulation/www/object-edit.tcl 7 Nov 2003 16:08:45 -0000 1.17 @@ -12,21 +12,6 @@ # TODO: Joel will do something about this? auth::require_login -#--------------------------------------------------------------------- -# Determine if we are in edit mode or display mode -#--------------------------------------------------------------------- -# this is prototype code to correct for get_action's apparent -# unreliability - -#set mode [template::form::get_action sim_template] -#if { ![exists_and_not_null workflow_id]} { -# set mode "add" -#} else { -# # for now, use edit mode in place of display mode -# # set mode "display" -# set mode "edit" -#} - if { ![ad_form_new_p -key item_id] } { # Get data for existing object array set item_info [bcms::item::get_item -item_id $item_id -revision live] @@ -41,7 +26,6 @@ } set context [list [list "object-list" "Sim Objects"] $page_title] - ###################################################################### # # object @@ -695,8 +679,6 @@ regexp {__.+__(.+)$} $elm match order_n set related_object_id [set $elm] - ns_log Notice "LARS: $elm - $related_object_id" - if { ![empty_string_p $related_object_id] } { bcms::item::relate_item \ -relation_tag $relation_tag \ Index: openacs-4/packages/simulation/www/object-xml.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/object-xml.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/object-xml.tcl 7 Nov 2003 16:08:45 -0000 1.1 @@ -0,0 +1,12 @@ +ad_page_contract { + Show flash xml for a simulation object. + + @creation-date 2003-11-07 + @cvs-id $Id: object-xml.tcl,v 1.1 2003/11/07 16:08:45 peterm Exp $ +} { + item_id:integer +} + +set flash_xml [simulation::object::generate_xml -item_id $item_id] + +ns_return 200 text/plain $flash_xml