- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables
Class ::xowf::test_item::Renaming_form_loader
::xowf::test_item::Renaming_form_loader create ...Form loader that renames "generic" form-field-names as provided by the test-item form-field classes (@answer@) into names based on the form name, such that multiple of these form names can be processed together without name clashes. - answer_attributes - answer_for_form - answers_for_form - form_name_based_attribute_stem - name_to_question_obj_dict - rename_attributes
Defined in packages/xowf/tcl/test-item-procs.tcl
Class Relations
::nx::Class create ::xowf::test_item::Renaming_form_loader \ -superclass ::xowf::test_item::AssessmentInterfaceMethods (to be applied on instances)
answer_attributes (scripted, public)
<instance of xowf::test_item::Renaming_form_loader> answer_attributes \ instance_attributesReturn all form-loader specific attributes from instance_attributes.
- Parameters:
- instance_attributes (required)
- Testcases:
- No testcase defined.
set result "" foreach key [lsort [dict keys $instance_attributes]] { if {[string match *_ $key]} { lappend result $key [dict get $instance_attributes $key] } } return $resultanswer_for_form (scripted, public)
<instance of xowf::test_item::Renaming_form_loader> answer_for_form \ formName instance_attributesReturn answer for the provided formName from instance_attributes of a single object.
- Parameters:
- formName (required)
- instance_attributes (required)
- Testcases:
- No testcase defined.
set result "" set stem [:form_name_based_attribute_stem $formName] set answerAttributes [:answer_attributes $instance_attributes] #ns_log notice "answer_for_form\ninstance_attributes $instance_attributes" if {[dict exists $answerAttributes $stem]} { set value [dict get $answerAttributes $stem] if {$value ne ""} { lappend result $value } } return $resultanswers_for_form (scripted, public)
<instance of xowf::test_item::Renaming_form_loader> answers_for_form \ formName answersReturn a list of dicts for the provided formName from the answers (as returned from [answer_manager get_answer_attributes ...]).
- Parameters:
- formName (required)
- answers (required)
- Testcases:
- No testcase defined.
set stem [:form_name_based_attribute_stem $formName] set result "" foreach answer $answers { set value answer_for_form set answerAttributes [dict get $answer answerAttributes] if {[dict exists $answerAttributes $stem]} { set value [dict get $answerAttributes $stem] if {$value ne ""} { lappend result [list item [dict get $answer item] value $value] } } } return $resultform_name_based_attribute_stem (scripted, public)
<instance of xowf::test_item::Renaming_form_loader> form_name_based_attribute_stem \ formNameProduce from the provided 'formName' an attribute stem for the input fields of this form.
- Parameters:
- formName (required)
- Testcases:
- No testcase defined.
set strippedName [lindex [split $formName :] end] regsub -all -- {[-]} $strippedName _ stem return ${stem}_name_to_question_obj_dict (scripted, public)
<instance of xowf::test_item::Renaming_form_loader> name_to_question_obj_dict \ question_objsProduce a dict for attribute name to question_obj
- Parameters:
- question_objs (required)
- Testcases:
- No testcase defined.
set nameToQuestionObjDict {} foreach o $question_objs { dict set nameToQuestionObjDict [:form_name_based_attribute_stem [$o name]] $o } return $nameToQuestionObjDictrename_attributes (scripted, public)
<instance of xowf::test_item::Renaming_form_loader> rename_attributes \ form_objPerform attribute renaming in the provided form_obj and return this form_obj. In essence, this changes the generic "@answer@" value in the form and in the form constraints to a name based on the form name.
- Parameters:
- form_obj (required, object)
- Testcases:
- No testcase defined.
set form [$form_obj get_property -name form] set fc [$form_obj get_property -name form_constraints] # # Map "answer" to a generic name "@answer@" in the form and in # the form constraints. # set newName [:form_name_based_attribute_stem [$form_obj name]] #ns_log notice "renaming form loader: MAP '[$form_obj name]' -> '$newName'" regsub -all -- {@answer} $form @$newName form set fc [:map_form_constraints $fc "answer" $newName] set disabled_fc [lmap f $fc { if {[string match "$newName*" $f]} { append f ,disabled=true } set f }] lappend fc @cr_fields:hidden lappend disabled_fc @cr_fields:hidden #:msg fc=$fc $form_obj set_property -new 1 form $form $form_obj set_property -new 1 form_constraints $fc $form_obj set_property -new 1 disabled_form_constraints $disabled_fc #ns_log notice "RENAMED form $form\n$fc\n$disabled_fc" return $form_obj
- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables