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 -N -r1.3 -r1.4 --- openacs-4/packages/xowf/lib/online-exam.wf 11 Aug 2017 13:35:48 -0000 1.3 +++ openacs-4/packages/xowf/lib/online-exam.wf 14 Sep 2017 09:22:22 -0000 1.4 @@ -6,7 +6,7 @@ # questions, which are typically open text questions. The user # selects one ore several exam question via drag and drop The teacher # can test the exam by entering test answers. The results are provided -# in form of a table. +# in form of a table. # # When the teacher has finished testing of the exam, the exam can be # published. In this step, all answers of the testing phase are @@ -32,26 +32,26 @@ State initial -actions {select} -form en:select_question.form -view_method edit State created -actions {publish restart} -form_loader load_form -view_method edit \ - -form "Prüfungsentwurf (Prüfung nicht freigeschalten)" + -form "Prüfungsentwurf (Prüfung nicht freigeschaltet)" State published -actions {unpublish} -form_loader load_form -view_method edit \ - -form "Prüfung ist freigeschalten" + -form "Prüfung ist freigeschaltet" State done -actions {republish restart} -form_loader load_form -view_method edit \ - -form "Die Prüfung ist geschlossen." + -form "Die Prüfung ist geschlossen." ######################################################################## # Activate action select: After the teacher has selected the # exercises, the answer workflow is created. # select proc activate {obj} { - [:wf_context] create_answer_workflow $obj + [[:wf_context] wf_container] create_answer_workflow $obj } ######################################################################## # Activate action publish: delete all responses for the workflow and # publish user participation link. # publish proc activate {obj} { - [$obj wf_context] delete_all_answer_data $obj + [[:wf_context] wf_container] delete_all_answer_data $obj :publish_link $obj } @@ -71,93 +71,6 @@ } ######################################################################## -# -# Helper methods for the workflow context -# -######################################################################## - -######################################################################## -# form loader: create dynamically a form containing the disabled -# questions and the survey results (the results can be refreshed) -# -my proc load_form {title} { - set state [my property _state] - - set questions [my get_questions] - set counter 0 - set fullQuestionForm "" - foreach q $questions { - append fullQuestionForm \ - "

Frage [incr counter]

\n" \ - [$q property form] - } - - # disable fields, remove wrapping form - regsub -all {]*>} $fullQuestionForm {} fullQuestionForm - - set text "

$title

" - set obj [my object] - - set wf [my get_answer_wf $obj] - if {$wf eq ""} { - my msg "cannot get current workflow for [$obj name]" - set lLink "." - set tLink "." - set aLink "." - set pLink "." - set menu "" - } else { - 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 "[$obj pretty_link]?m=answer" - set pLink "[$obj pretty_link]?m=print-answers" - #util_user_message -html -message "$survey is available as $pLink" - set menu "\[refresh,\ - listing,\ - print\]" - } - - set extraAction "" - switch [my property _state] { - "created" {set extraAction "
Do you want to try out the exam?"} - "published" {set extraAction "
Students can now answer via $aLink"} - } - append text "$menu $extraAction\n" - - set style "background: #cccccc; padding: 10px; margin:10px;" - set report "" - set wfName [my property wfName] - if {$wfName ne ""} {set report "{{form-stats -parent_id [$obj item_id] -form $wfName}}\n"} - append report "
$menu" - - set f [::xowiki::Form new \ - -set name en:quesiton \ - -form [subst {
$text
$fullQuestionForm
$report
text/html}] \ - -text {} \ - -anon_instances t \ - -form_constraints {@cr_fields:hidden} \ - ] -} - -######################################################################## -# get_question: load and initialize the interaction forms -# -my proc get_questions {} { - set questionNames [join [my property question] |] - set object [my object] - set questionForms [::xowiki::Weblog instantiate_forms \ - -parent_id [$object parent_id] -package_id [$object package_id] \ - -default_lang [$object lang] \ - -forms $questionNames] - if {[llength $questionForms] < 1} {error "unknown form $questionNames"} - #my msg "questionNames '$questionNames', questionForms 'questionForms'" - return $questionForms -} - -######################################################################## # create_answer_workflow: create a workflow based on the template # provided in this method for answering the question for the # students. The name of the workflow is derived from the wokflow @@ -178,8 +91,9 @@ set wfMaster [my set masterWorkflow] set wfTitle [$obj property _title] - set questionObjs [my get_questions] + set questionObjs [[:wf_context] get_questions] set wfQuestionNames {} + set wfQuestionTitles {} set attributeNames {} foreach q $questionObjs { set counter 0 @@ -193,14 +107,16 @@ } } lappend wfQuestionNames ../[$q name] + lappend wfQuestionTitles [$q title] } set wfID [$obj item_id] set wfDef [subst -nocommands { - set wfID $wfID + set wfID $wfID set wfTitle "$wfTitle" set wfQuestionNames [list $wfQuestionNames] - xowf::include /packages/xowf/lib/online-exam-answer.wf [list wfID wfTitle wfQuestionNames] + set wfQuestionTitles [list $wfQuestionTitles] + xowf::include /packages/xowf/lib/online-exam-answer.wf [list wfID wfTitle wfQuestionNames wfQuestionTitles] }] set attributeNames [join $attributeNames ,] @@ -272,58 +188,172 @@ # TODO: make it happen } +:object-specific { + ######################################################################## + # Extern callable methods + ######################################################################## -######################################################################## -# Extern callable methods -######################################################################## + ######################################################################## + # delete: delete the workflow instance and all its associated data + # + :proc www-delete {} { + set ctx [::xowf::Context require [self]] + [$ctx wf_container] delete_all_answer_data [self] + next + } -######################################################################## -# delete: delete the workflow instance and all its associated data -# -[my object] proc delete {} { - set ctx [::xowf::Context require [self]] - $ctx delete_all_answer_data [self] - next -} + :proc -deprecated delete {} { + :www-delete + } -######################################################################## -# print-answers: print the answers in a somewhat printer friendly way -# -[my object] proc print-answers {} { - set HTML "" - set ctx [::xowf::Context require [self]] - set wf [$ctx get_answer_wf [self]] - if {$wf ne ""} { - set items [$ctx get_wf_instances $wf] - foreach i [$items children] { - set time [::xo::db::tcl_date [$i property _last_modified] tz_var] - set pretty_date [clock format [clock scan $time] -format "%Y-%m-%d %T"] - set uid [$i property _creation_user] - set text "

[acs_user::get_element -user_id $uid -element username] / [::xo::get_user_name $uid] / $pretty_date

" - append HTML "

[$i title]

$text[$i render_content]
" + ######################################################################## + # print-answers: print the answers in a somewhat printer friendly way + # + :proc print-answers {} { + set HTML "" + set ctx [::xowf::Context require [self]] + set wf [[$ctx wf_container] get_answer_wf [self]] + if {$wf ne ""} { + set items [[$ctx wf_container] get_wf_instances $wf] + foreach i [$items children] { + set time [::xo::db::tcl_date [$i property _last_modified] tz_var] + set pretty_date [clock format [clock scan $time] -format "%Y-%m-%d %T"] + set uid [$i property _creation_user] + set text "

[acs_user::get_element -user_id $uid -element username] / [::xo::get_user_name $uid] / $pretty_date

" + set question_form [$i render_content] + set answer $question_form + set title [$i title] + array set ia [$i set instance_attributes] + regsub -all {
|} $answer {

} answer + regsub -all {
} $answer {} answer + regsub -all {IP\: (.*)} $title "$ia(ip)" title + append HTML "

$title

$text$answer
" + } } + if {$HTML ne ""} { + ns_return 200 text/html " + + + + + $HTML + + " + } else { + util_user_message -html -message "No answer data available" + ad_returnredirect [::xo::cc url] + } } - if {$HTML ne ""} { - ns_return 200 text/html $HTML - } else { - util_user_message -html -message "No answer data available" - ad_returnredirect [::xo::cc url] + + ######################################################################## + # answer: answer the exam; this is a conveniance routine to shorten + # the published URL; make sure, that no-one trys to start the answer + # workflow in a state different to "published" + # + :proc www-answer {} { + if {[my property _state] ne "published"} { + util_user_message -html -message "Cannot start answer workflow in this state" + } else { + set ctx [::xowf::Context require [self]] + set wf [[$ctx wf_container] get_answer_wf [self]] + $wf www-create-or-use -parent_id [my item_id] + } } -} -######################################################################## -# answer: answer the exam; this is a conveniance routine to shorten -# the published URL; make sure, that no-one trys to start the answer -# workflow in a state different to "published" -# -[my object] proc answer {} { - if {[my property _state] ne "published"} { - util_user_message -html -message "Cannot start answer workflow in this state" - } else { - set ctx [::xowf::Context require [self]] - set wf [$ctx get_answer_wf [self]] - $wf create-or-use + :proc -deprecated answer {args} { + ad_log warning "????? who is calling me?" + :www-answer {*}$args } + + ######################################################################## + # + # Helper methods for the workflow context + # + ######################################################################## + + set ctx [:wf_context] + + ######################################################################## + # form loader: create dynamically a form containing the disabled + # questions and the survey results (the results can be refreshed) + # + $ctx proc load_form {title} { + set state [my property _state] + + set questions [my get_questions] + set counter 0 + set fullQuestionForm "" + foreach q $questions { + append fullQuestionForm \ + "

Frage [incr counter]

\n" \ + [$q property form] + } + + # disable fields, remove wrapping form + regsub -all {]*>} $fullQuestionForm {} fullQuestionForm + + set text "

$title

" + set obj ${:object} + + set wf [[:wf_container] get_answer_wf $obj] + if {$wf eq ""} { + my msg "cannot get current workflow for [$obj name]" + set lLink "." + set tLink "." + set aLink "." + set pLink "." + set menu "" + } else { + 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 "[$obj pretty_link]?m=answer" + set pLink "[$obj pretty_link]?m=print-answers" + #util_user_message -html -message "$survey is available as $pLink" + set menu "\[refresh,\ + listing,\ + print\]" + } + + set extraAction "" + switch [my property _state] { + "created" {set extraAction "
Do you want to try out the exam?"} + "published" {set extraAction "
Students can now answer via $aLink"} + } + append text "$menu $extraAction\n" + + set style "background: #cccccc; padding: 10px; margin:10px;" + set report "" + set wfName [my property wfName] + if {$wfName ne ""} {set report "{{form-stats -parent_id [$obj item_id] -form $wfName}}\n"} + append report "
$menu" + + set f [::xowiki::Form new \ + -set name en:quesiton \ + -form [subst {
$text
$fullQuestionForm
$report
text/html}] \ + -text {} \ + -anon_instances t \ + -form_constraints {@cr_fields:hidden} \ + ] + } + + ######################################################################## + # get_question: load and initialize the interaction forms + # + $ctx proc get_questions {} { + set questionNames [join [my property question] |] + set questionForms [::xowiki::Weblog instantiate_forms \ + -parent_id [${:object} parent_id] -package_id [${:object} package_id] \ + -default_lang [${:object} lang] \ + -forms $questionNames] + if {[llength $questionForms] < 1} {error "unknown form $questionNames"} + #my msg "questionNames '$questionNames', questionForms 'questionForms'" + return $questionForms + } } #