Index: openacs-4/packages/xowf/lib/online-exam-answer.wf =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowf/lib/online-exam-answer.wf,v diff -u -r1.2.2.4 -r1.2.2.5 --- openacs-4/packages/xowf/lib/online-exam-answer.wf 15 Oct 2019 21:41:45 -0000 1.2.2.4 +++ openacs-4/packages/xowf/lib/online-exam-answer.wf 17 Oct 2019 19:48:17 -0000 1.2.2.5 @@ -238,15 +238,10 @@ }] } -#MAP OLD demc-exercise-1-1:checkbox,answer=demc-exercise-1-1 -#MAP demc-exercise-1-1 => mc-exercise-1-a1 -#MAP NEW mc-exercise-1-a1:checkbox,answer=demc-exercise-1-1 -#MAP match with *value=demc-exercise-1-1* -> 0 - - -:proc get_question_form_object {form_name} { - #:msg "renaming_form_loader for form_name <$form_name> (counter $counter)" - set form_id [:default_load_form_id $form_name] +:proc get_question_form_object {ctx form_name} { + #:msg "renaming_form_loader for form_name <$form_name>" + set form_id [$ctx default_load_form_id $form_name] + set obj [$ctx object] set form_obj [::xo::db::CrClass get_instance_from_db -item_id $form_id] set form [$form_obj get_property -name form] @@ -257,12 +252,12 @@ # Map "answer" to a generic name in the form "@answer@" and in the # form constraints # - # set strippedName [lindex [split [$form_obj name] :] end] regsub -all {[-]} $strippedName _ formName set newName ${formName}_a; #$counter 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 } @@ -314,11 +309,11 @@ # # Update IP address each time the form is loaded. # - if {[${:object} state] in {"initial" "working"}} { - ${:object} set_property ip [expr {[ns_conn isconnected] ? [ad_conn peeraddr] : "nowhere"}] + if {[$obj state] in {"initial" "working"}} { + $obj set_property ip [expr {[ns_conn isconnected] ? [ad_conn peeraddr] : "nowhere"}] } - :set_title -question 1 -minutes [:minutes_string $form_obj] + :set_title $obj -question 1 -minutes [:minutes_string $form_obj] return $form_obj } @@ -327,22 +322,22 @@ # # Set "title" with question and user information # -:proc set_title {{-question:boolean true} {-minutes ""}} { +:proc set_title {obj {-question:boolean true} {-minutes ""}} { set t [list ] - set state [${:object} state] - set position [${:object} property position] + set state [$obj state] + set position [$obj property position] if {$question && $state eq "working"} { - set titleString "[_ xowf.question] [expr {$position + 1}]: [lindex [${:object} property titles] $position]" + set titleString "[_ xowf.question] [expr {$position + 1}]: [lindex [$obj property titles] $position]" if {$minutes ne ""} { append titleString " $minutes" } lappend title $titleString } lappend title \ "@wfTitle@" \ - "IP: [${:object} property ip]" + "IP: [$obj property ip]" - ${:object} title [join $title " · "] + $obj title [join $title " · "] } # @@ -374,17 +369,17 @@ # This form loader is also called indirectly by www-print-answers of # oneline-exam.wf # -:proc summary_form {form_title} { - #:msg "summary_form_loader $form_title [${:object} instance_attributes]" +:proc summary_form {ctx form_title} { + set obj [$ctx object] + #:msg "summary_form_loader $form_title [$obj instance_attributes]" #:set_title -question 0 set summary_form "" set fc {} set counter 0 - foreach form_name [${:object} property pages] { - set form_obj [:get_question_form_object $form_name] - #set form_id [:default_load_form_id $form_name] - set title [lindex [${:object} property titles] $counter] + foreach form_name [$obj property pages] { + set form_obj [:get_question_form_object $ctx $form_name] + set title [lindex [$obj property titles] $counter] set minutes [:minutes_string $form_obj] append summary_form \ "

[_ xowf.question] [incr counter]: $title $minutes

" \n \ @@ -421,7 +416,12 @@ # ensure default value is updated for each instance individually Property ip -default [expr {[ns_conn isconnected] ? [ad_conn peeraddr] : "nowhere"}] - set working_state_object [[:wf_context] wf_definition_object working] + set ctx [:wf_context] + set container [$ctx wf_container] + $ctx forward get_question_form_object $container %proc $ctx + $ctx forward summary_form $container %proc $ctx + + set working_state_object [$ctx wf_definition_object working] $working_state_object set form [:property current_form] # fallback if the current_form isn't set if {[$working_state_object set form] eq ""} { Index: openacs-4/packages/xowf/lib/online-exam.wf =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowf/lib/online-exam.wf,v diff -u -r1.6.2.5 -r1.6.2.6 --- openacs-4/packages/xowf/lib/online-exam.wf 15 Oct 2019 21:41:45 -0000 1.6.2.5 +++ openacs-4/packages/xowf/lib/online-exam.wf 17 Oct 2019 19:48:17 -0000 1.6.2.6 @@ -106,7 +106,7 @@ set wfMaster ${:masterWorkflow} set wfTitle [$obj property _title] - set questionObjs [[$obj wf_context] get_questions] + set questionObjs [[[$obj wf_context] wf_container] get_questions $obj] set wfQuestionNames {} set wfQuestionTitles {} set attributeNames {} @@ -206,20 +206,39 @@ + ######################################################################## +# get_questions: load and initialize the interaction forms # -# Helper methods for the workflow context -# -######################################################################## +:proc get_questions {obj} { + set questions [lmap ref [$obj property question] { + if {![string match "*/*" $ref]} { + set ref [[$obj parent_id] name]/$ref + } + set ref + }] + set questionNames [join $questions |] + set questionForms [::xowiki::Weblog instantiate_forms \ + -package_id [$obj package_id] \ + -default_lang [$obj lang] \ + -forms $questionNames] + if {[llength $questionForms] < 1} { + error "unknown form $questionNames" + } + #:msg "questionNames '$questionNames', questionForms 'questionForms'" + return $questionForms +} + ######################################################################## # form loader: create dynamically a form containing the disabled # questions and the survey results (the results can be refreshed) # -:proc load_form {title} { - set state [:property _state] +:proc load_form {ctx title} { + set obj [$ctx object] + set state [$obj property _state] - set questions [:get_questions] + set questions [:get_questions $obj] set counter 0 set fullQuestionForm "" foreach q $questions { @@ -236,9 +255,9 @@ #:log fullQuestionForm=$fullQuestionForm set text "

$title

" - set wf [[:wf_container] get_answer_wf ${:object}] + set wf [:get_answer_wf $obj] if {$wf eq ""} { - :msg "cannot get current workflow for [${:object} name]" + :msg "cannot get current workflow for [$obj name]" set lLink "." set tLink "." set aLink "." @@ -248,16 +267,16 @@ set wf_pretty_link [$wf pretty_link] set tLink "$wf_pretty_link?m=create-new&p.return_url=[::xo::cc url]&p.try_out_mode=1" set lLink "$wf_pretty_link?m=list" - set aLink [${:object} pretty_link -query m=answer] - set pLink [${:object} pretty_link -query m=print-answers] + set aLink [$obj pretty_link -query m=answer] + set pLink [$obj pretty_link -query m=print-answers] #util_user_message -html -message "$survey is available as $pLink" set menu "\[#xowf.refresh#,\ #xowf.online-exam-exam_instances#,\ #xowf.print#\]" } set extraAction "" - switch [:property _state] { + switch [$obj property _state] { "created" { set extraAction "
#xowf.online-exam-try_out# #xowf.testrun#" } @@ -267,9 +286,9 @@ } append text "$menu $extraAction\n" - set wfName [:property wfName] + set wfName [$obj property wfName] set report [expr {$wfName ne "" - ? "{{form-stats -parent_id [${:object} item_id] -form $wfName}}\n" + ? "{{form-stats -parent_id [$obj item_id] -form $wfName}}\n" : ""}] append report "
$menu" @@ -284,37 +303,24 @@ } ######################################################################## -# get_question: load and initialize the interaction forms # -:proc get_questions {} { - set questions [lmap ref [:property question] { - if {![string match "*/*" $ref]} { - set ref [[${:object} parent_id] name]/$ref - } - set ref - }] - set questionNames [join $questions |] - set questionForms [::xowiki::Weblog instantiate_forms \ - -package_id [${:object} package_id] \ - -default_lang [${:object} lang] \ - -forms $questionNames] - if {[llength $questionForms] < 1} { - error "unknown form $questionNames" - } - #:msg "questionNames '$questionNames', questionForms 'questionForms'" - return $questionForms -} - - - -######################################################################## -# # Object specific operations # ######################################################################## :object-specific { + ######################################################################## + # + # Helper methods for the workflow context + # + ######################################################################## + + set ctx [:wf_context] + set container [$ctx wf_container] + $ctx forward load_form $container %proc $ctx + + ######################################################################## # Extern callable methods ########################################################################