xowf::test_item::Question_manager method replace_pool_question (public)
<instance of xowf::test_item::Question_manager> replace_pool_question \ [ -position position ] [ -seed seed ] \ [ -allowed_forms allowed_forms ] [ -field_name field_name ] \ [ -pool_question_obj pool_question_obj ] \ [ -exam_question_names exam_question_names ]
Defined in packages/xowf/tcl/test-item-procs.tcl
- Switches:
- -position (optional)
- -seed (optional)
- -allowed_forms (optional, defaults to
"en:edit-interaction.wf"
)- -field_name (optional)
- -pool_question_obj (optional)
- -exam_question_names (optional)
- Returns:
- an initialized replacement form obj if this is possible
- Testcases:
- No testcase defined.
Source code: set field_name ""; ## rely on fallback set candidate_dict [:get_pool_questions -allowed_forms $allowed_forms -field_name $field_name $pool_question_obj $exam_question_names] set candidate_names [dict keys $candidate_dict] set nrCandidates [llength $candidate_names] if {$nrCandidates == 0} { set h [ns_set iget [ns_conn headers] referrer] set url [join [lrange [split [xo::cc url] /] 0 end-1] /]?m=edit util_user_message -message "could not find a replacement item for pool question: no matching item found" ad_returnredirect $url ad_script_abort } # # It might be the case that we select the same item for an exam # twice. Therefore, we have to iterate, until we find different # items. # expr {srand($seed)} set maxiter 100 while {1} { set i [expr {int(($nrCandidates) * rand())}] set new_name [lindex $candidate_names $i] #ns_log notice "replace_pool_question position $position seed $seed random_index $i" set contained [expr {$new_name in $exam_question_names}] #ns_log notice "replace_pool_question replace [$pool_question_obj name] by $new_name contained in" # "[lsort $exam_question_names] contained $contained" if {!$contained || [incr maxiter -1] < 0} { break } } if {$contained} { error "could not find a replacement item for [$pool_question_obj name]: only duplicate items found" } set form_obj [::xowiki::FormPage get_instance_from_db -item_id [dict get $candidate_dict $new_name item_id]] #$form_obj initialize # ns_log notice [$form_obj serialize] return $form_objXQL Not present: Generic, PostgreSQL, Oracle