Index: openacs-4/packages/assessment/tcl/as-item-display-sb-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/tcl/as-item-display-sb-procs.tcl,v diff -u -r1.12 -r1.13 --- openacs-4/packages/assessment/tcl/as-item-display-sb-procs.tcl 12 Jun 2006 12:29:21 -0000 1.12 +++ openacs-4/packages/assessment/tcl/as-item-display-sb-procs.tcl 2 Sep 2008 17:21:29 -0000 1.13 @@ -12,7 +12,7 @@ {-choice_label_orientation ""} {-sort_order_type ""} {-item_answer_alignment ""} - {-prepend_empty_p "f"} + {-prepend_empty_p "t"} } { @author Timo Hentschel (timo@timohentschel.de) @creation-date 2004-12-08 @@ -106,6 +106,7 @@ {-random_p ""} {-default_value ""} {-data ""} + -item:required } { @author Timo Hentschel (timo@timohentschel.de) @creation-date 2004-12-10 @@ -145,10 +146,23 @@ if {$required_p != "t"} { set optional ",optional" } + array set item_array $item + set allow_other_p $item_array(allow_other_p) + + if {[string is true $allow_other_p]} { + set widget select_text + set datatype select_text + } else { + set widget select + set datatype text + } + set param_list [list [list label \$title] [list help_text \$subtext] [list values \$default_value] [list options \$data] [list html \$type(html_display_options)]] - set element_params [concat [list "$element\:text($widget)$optional"] $param_list] + set element_params [concat [list "$element\:${datatype}($widget)$optional"] $param_list] ad_form -extend -name $form -form [list $element_params] + + return [expr {$allow_other_p ? "sbo" : "sb"}] } ad_proc -public as::item_display_sb::data { @@ -173,3 +187,54 @@ db_1row display_item_data {} -column_array type return [array get type] } + +ad_proc as::item_display_sb::set_item_display_type { + -assessment_id + -section_id + -as_item_id + -after + {-type ""} + {-html_options ""} + {-order_type "order_of_entry"} +} { + + db_transaction { + set new_assessment_rev_id [as::assessment::new_revision -assessment_id $assessment_id] + set section_id [as::section::latest -section_id $section_id -assessment_rev_id $new_assessment_rev_id] + set new_section_id [as::section::new_revision -section_id $section_id -assessment_id $assessment_id] + db_dml update_section_in_assessment {} + set old_item_id $as_item_id + + if {![db_0or1row item_display {}] || $object_type != "as_item_display_sb"} { + set as_item_display_id [as::item_display_sb::new \ + -html_display_options $html_options \ + -sort_order_type $order_type] + + if {![info exists object_type]} { + # first item display mapped + as::item_rels::new -item_rev_id $as_item_id -target_rev_id $as_item_display_id -type as_item_display_rel + } else { + # old item display existing + set as_item_id [as::item::new_revision -as_item_id $as_item_id] + } + } else { + # old sb item display existing + set as_item_id [as::item::new_revision -as_item_id $as_item_id] + set as_item_display_id [as::item_display_sb::edit \ + -as_item_display_id $as_item_display_id \ + -html_display_options $html_options \ + -sort_order_type $order_type] + } + + set old_item_id [as::item::latest -as_item_id $old_item_id -section_id $new_section_id -default 0] + if {$old_item_id == 0} { + db_dml move_down_items {} + incr after + db_dml insert_new_item {} + } else { + db_dml update_item_display {} + db_1row item_data {} + db_dml update_item {} + } + } +}