ad_page_contract { Export an assessment in IMS QTI format @author Natalia Pérez (nperper@it.uc3m.es) @creation-date 2004-11-25 } -query { {assessment_id:integer,optional} } if {[exists_and_not_null assessment_id]} { # Get the assessment data as::assessment::data -assessment_id $assessment_id set download_name $assessment_data(title) # We get rid of spaces since they are annoying regsub -all { } $download_name {_} download_name set tmp_dir $download_name set ext "zip" append download_name ".${ext}" ad_returnredirect "${assessment_id}/${download_name}" ad_script_abort } # convenient way to get the values out of a list foreach {assessment_id download_name} [split [ad_conn path_info] /] {break} ad_require_permission $assessment_id admin # Get the assessment data as::assessment::data -assessment_id $assessment_id set assessment_id $assessment_data(assessment_rev_id) # First create our top-level document #set doc [dom createDocument questestinterop] dom createDocument questestinterop doc set root [$doc documentElement] # Build our XML document set assessment [$doc createElement assessment] $assessment setAttribute title $assessment_data(title) $assessment setAttribute ident $assessment_data(name) $root appendChild $assessment if {![empty_string_p $assessment_data(description)]} { # set qticomment [$doc createElement qticomment] $assessment appendChild $qticomment set text [$doc createCDATASection $assessment_data(description)] $qticomment appendChild $text # set objectives [$doc createElement objectives] $assessment appendChild $objectives # set material [$doc createElement material] $objectives appendChild $material set mattext [$doc createElement mattext] $material appendChild $mattext set text [$doc createCDATASection $assessment_data(description)] $mattext appendChild $text } if {![empty_string_p $assessment_data(instructions)]} { # set rubric [$doc createElement rubric] $assessment appendChild $rubric # set material [$doc createElement material] $rubric appendChild $material set mattext [$doc createElement mattext] $material appendChild $mattext set text [$doc createCDATASection $assessment_data(instructions)] $mattext appendChild $text } # set assessmentcontrol [$doc createElement assessmentcontrol] $assessmentcontrol setAttribute feedbackswitch "No" $assessmentcontrol setAttribute solutionswitch "No" $assessment appendChild $assessmentcontrol db_multirow sections query_all_sections {} { #
set section [$doc createElement section] $section setAttribute title $section_title $section setAttribute ident $section_name $assessment appendChild $section # set selection_ordering [$doc createElement selection_ordering] $section appendChild $selection_ordering # set selection [$doc createElement selection] $selection_ordering appendChild $selection # set selection_number [$doc createElement selection_number] $selection appendChild $selection_number set text [$doc createCDATASection "All"] $selection_number appendChild $text # set order [$doc createElement order] $order setAttribute order_type "Sequential" $selection_ordering appendChild $order db_foreach query_all_items {} { #reset variables set cb__display_id {} unset cb__display_id set rb__display_id {} unset rb__display_id set tb__display_id {} unset tb__display_id set ta__display_id {} unset ta__display_id set mc_id [as::item_rels::get_target -item_rev_id $as_item_id -type as_item_type_rel] set item_display_id [as::item_rels::get_target -item_rev_id $as_item_id -type as_item_display_rel] set items_as_item_id [db_string items_items_as_item_id "SELECT item_id FROM cr_revisions WHERE revision_id = :as_item_id"] #checkbox db_0or1row as_item_display_cbx "SELECT as_item_display_id AS cb__display_id FROM as_item_display_cb WHERE as_item_display_id=:item_display_id" #radiobutton db_0or1row as_item_display_rbx "SELECT as_item_display_id AS rb__display_id FROM as_item_display_rb WHERE as_item_display_id=:item_display_id" #textbox (fill-in-the-blank) db_0or1row as_item_display_tbx "SELECT as_item_display_id AS tb__display_id FROM as_item_display_tb WHERE as_item_display_id=:item_display_id" #textarea (short answer) db_0or1row as_item_display_tax "SELECT as_item_display_id AS ta__display_id FROM as_item_display_ta WHERE as_item_display_id=:item_display_id" # set item [$doc createElement item] $item setAttribute ident $item_name $section appendChild $item if {![empty_string_p $item_subtext]} { # set objectives [$doc createElement objectives] $item appendChild $objectives # set material [$doc createElement material] $objectives appendChild $material # set mattext [$doc createElement mattext] $material appendChild $mattext set text [$doc createCDATASection $item_subtext] $mattext appendChild $text } # set presentation [$doc createElement presentation] $item appendChild $presentation # set flow [$doc createElement flow] $presentation appendChild $flow if {![info exists tb__display_id]} { # set material [$doc createElement material] $flow appendChild $material # set mattext [$doc createElement mattext] $material appendChild $mattext set text [$doc createCDATASection $item_title] $mattext appendChild $text } #find out the item type (multiple choice or multiple response) if {[info exists cb__display_id] || [info exists rb__display_id]} { if {[info exists cb__display_id]} { # checkbox set rcardinality "Multiple" } else { # radiobutton set rcardinality "Single" } # set response_lid [$doc createElement response_lid] $response_lid setAttribute ident $item_name $response_lid setAttribute rcardinality $rcardinality $response_lid setAttribute rtiming "No" $flow appendChild $response_lid # set render_choice [$doc createElement render_choice] $response_lid appendChild $render_choice db_foreach query_all_choices {} { # set flow_label [$doc createElement flow_label] $render_choice appendChild $flow_label # set response_label [$doc createElement response_label] $response_label setAttribute ident $choice_name $response_label setAttribute rshuffle "Yes" $flow_label appendChild $response_label # set material [$doc createElement material] $response_label appendChild $material # set mattext [$doc createElement mattext] $material appendChild $mattext set text [$doc createCDATASection $choice_title] $mattext appendChild $text } } else { #short answer if {[info exists ta__display_id]} { # set response_str [$doc createElement response_str] $response_str setAttribute ident $item_name $response_str setAttribute rcardinality "Single" $response_str setAttribute rtiming "No" $flow appendChild $response_str #get rows and cols for painting a textarea (in abs_size is stored as "rows value cols value", we need to add the symbol =) db_0or1row html_rows_cols "SELECT html_display_options FROM as_item_display_ta WHERE as_item_display_id=:item_display_id" set rows "[lindex $html_display_options 1]" set columns "[lindex $html_display_options 3]" # set render_fib [$doc createElement render_fib] $render_fib setAttribute fibtype "String" $render_fib setAttribute prompt "Box" $render_fib setAttribute encoding "UTF-8" $render_fib setAttribute rows $rows $render_fib setAttribute columns $columns $response_str appendChild $render_fib # set response_label [$doc createElement response_label] $response_label setAttribute ident $item_name $response_label setAttribute rshuffle "Yes" $render_fib appendChild $response_label } else { #fill in the blank #whether it's a fill-in-blank I have to split by regsub -all -line -nocase -- "" $html ":" html1 set item_title1 [split $html1 :] set longitud [llength $item_title1] for {set i 0} {$i<[llength $item_title1]-1} {incr i 2} { set item_title [lindex $item_title1 $i] # set material [$doc createElement material] $flow appendChild $material # set mattext [$doc createElement mattext] $material appendChild $mattext set text [$doc createCDATASection $item_title] $mattext appendChild $text # set response_str [$doc createElement response_str] $response_str setAttribute ident $item_name$i $response_str setAttribute rcardinality "Single" $response_str setAttribute rtiming "No" $flow appendChild $response_str # set render_fib [$doc createElement render_fib] $render_fib setAttribute fibtype "String" $render_fib setAttribute prompt "Box" $render_fib setAttribute encoding "UTF-8" $response_str appendChild $render_fib # set response_label [$doc createElement response_label] $response_label setAttribute ident $item_name $response_label setAttribute rshuffle "Yes" $render_fib appendChild $response_label } } } if { $assessment_data(survey_p) == "f" && ![info exists ta__display_id] } { # set resprocessing [$doc createElement resprocessing] $item appendChild $resprocessing # set respcondition [$doc createElement respcondition] $resprocessing appendChild $respcondition # set conditionvar [$doc createElement conditionvar] $respcondition appendChild $conditionvar #fill-in-blank if {[info exists tb__display_id]} { set i 0 db_foreach query_all_choices {} { # set or [$doc createElement or] $conditionvar appendChild $or set list_choice_title $choice_title for {set j 0} {$j < [llength $list_choice_title]} {incr j 1} { # set varequal [$doc createElement varequal] $varequal setAttribute respident $item_name$i $or appendChild $varequal set text [$doc createCDATASection [lindex $list_choice_title $j]] $varequal appendChild $text } incr i 2 } } else { # set and [$doc createElement and] $conditionvar appendChild $and set exist_false 0 db_foreach query_all_choices2 {} { if {$correct_answer_p == "t" } { # set varequal [$doc createElement varequal] $varequal setAttribute respident $item_name $and appendChild $varequal set text [$doc createCDATASection $name] $varequal appendChild $text } else { set exist_false 1 } } if { $exist_false == 1 } { # set not [$doc createElement not] $and appendChild $not # set or [$doc createElement or] $not appendChild $or db_foreach query_all_choices2 {} { if {$correct_answer_p == "f" } { # set varequal [$doc createElement varequal] $varequal setAttribute respident $item_name $or appendChild $varequal set text [$doc createCDATASection $name] $varequal appendChild $text } } } } # set displayfeedback [$doc createElement displayfeedback] set linkrefid { } append linkrefid $item_name displayRight $displayfeedback setAttribute linkrefid $linkrefid $respcondition appendChild $displayfeedback # set respcondition [$doc createElement respcondition] $resprocessing appendChild $respcondition # set conditionvar [$doc createElement conditionvar] $respcondition appendChild $conditionvar #fill-in-blank if {[info exists tb__display_id]} { set i 0 # set not [$doc createElement not] $conditionvar appendChild $not db_foreach query_all_choices {} { # set or [$doc createElement or] $not appendChild $or set list_choice_title $choice_title for {set j 0} {$j < [llength $list_choice_title]} {incr j 1} { # set varequal [$doc createElement varequal] $varequal setAttribute respident $item_name$i $or appendChild $varequal set text [$doc createCDATASection [lindex $list_choice_title $j]] $varequal appendChild $text } incr i 2 } } else { # set or [$doc createElement or] $conditionvar appendChild $or set exist_true 0 db_foreach query_all_choices2 {} { if {$correct_answer_p == "f" } { # set varequal [$doc createElement varequal] $varequal setAttribute respident $item_name $or appendChild $varequal set text [$doc createCDATASection $name] $varequal appendChild $text } else { set exist_true 1 } } if { $exist_true == 1 } { # set not [$doc createElement not] $or appendChild $not # set and [$doc createElement and] $not appendChild $and db_foreach query_all_choices2 {} { if {$correct_answer_p == "t" } { # set varequal [$doc createElement varequal] $varequal setAttribute respident $item_name $and appendChild $varequal set text [$doc createCDATASection $name] $varequal appendChild $text } } } } # set displayfeedback [$doc createElement displayfeedback] set linkrefid { } append linkrefid $item_name displayWrong $displayfeedback setAttribute linkrefid $linkrefid $respcondition appendChild $displayfeedback db_foreach query_all_choices {} { set i 0 # [info exists tb__display_id] because for fib item choice_correct_answer_p is null if { $choice_correct_answer_p == "t" || [info exists tb__display_id] } { set list_choice_title $choice_title set length_list_choice_title [llength $list_choice_title] if {![info exists tb__display_id]} { set length_list_choice_title 1 } for {set j 0} {$j < $length_list_choice_title} {incr j 1} { # set respcondition [$doc createElement respcondition] $respcondition setAttribute title "adjustscore" $resprocessing appendChild $respcondition # set conditionvar [$doc createElement conditionvar] $respcondition appendChild $conditionvar # set varequal [$doc createElement varequal] if {[info exists tb__display_id]} { $varequal setAttribute respident $item_name$i } else { $varequal setAttribute respident $item_name } $conditionvar appendChild $varequal if {[info exists tb__display_id]} { set text [$doc createCDATASection [lindex $list_choice_title $j]] } else { set text [$doc createCDATASection $choice_name] } $varequal appendChild $text # set setvar [$doc createElement setvar] $setvar setAttribute varname "SCORE" $setvar setAttribute action "Add" $respcondition appendChild $setvar # in fib items choice_percent_score column is null if {[empty_string_p $choice_percent_score]} { set choice_percent_score 1 } set text [$doc createCDATASection $choice_percent_score] $setvar appendChild $text } } incr i 2 } #feedback_wrong if {![empty_string_p $item_feedback_wrong] } { # set itemfeedback [$doc createElement itemfeedback] set ident { } append ident $item_name displayWrong $itemfeedback setAttribute ident $ident $item appendChild $itemfeedback # set flow_mat [$doc createElement flow_mat] $itemfeedback appendChild $flow_mat # set material [$doc createElement material] $flow_mat appendChild $material # set mattext [$doc createElement mattext] $material appendChild $mattext set text [$doc createCDATASection $item_feedback_wrong] $mattext appendChild $text } #feedback_right if {![empty_string_p $item_feedback_right]} { # set itemfeedback [$doc createElement itemfeedback] set ident { } append ident $item_name displayRight $itemfeedback setAttribute ident $ident $item appendChild $itemfeedback # set flow_mat [$doc createElement flow_mat] $itemfeedback appendChild $flow_mat # set material [$doc createElement material] $flow_mat appendChild $material # set mattext [$doc createElement mattext] $material appendChild $mattext set text [$doc createCDATASection $item_feedback_right] $mattext appendChild $text } } } } #puts [$root asXML] set outfd "" append outfd "" append outfd [$root asXML] # publish the object to the file system set in_path [ns_tmpnam] file mkdir $in_path # store the tree xml into a file set file_name "$in_path/$assessment_data(title).xml" set file [open $file_name w 0600] puts $file $outfd close $file # create a temp dir to put the archive in set out_path [ns_tmpnam] file mkdir $out_path set out_file [file join ${out_path} ${download_name}] # get the archive command # TODO SECURITY DONT USE GLOBBING set cmd "zip -r -9 -X '$out_file' *" # create the archive with_catch errmsg { # TODO SECURITY DONT USE THE SHELL exec bash -c "cd '$in_path'; $cmd; cd -" } { # some day we'll do something useful here error $errmsg } # return the archive to the connection. ns_returnfile 200 [ns_guesstype $out_file] $out_file # clean everything up file delete -force $in_path file delete -force $out_path