Class ::xowiki::formfield::enumeration (public)
::xotcl::Class ::xowiki::formfield::enumeration
Defined in
- Testcases:
-
No testcase defined.
Source code:
namespace eval ::xowiki::formfield {}
::nsf::object::alloc ::xotcl::Class ::xowiki::formfield::enumeration {set :__default_metaclass ::xotcl::Class
set :__default_superclass ::xotcl::Object
set :abstract 1}
::xowiki::formfield::enumeration instproc value_if_nothing_is_returned_from_form default {
if {[:is_disabled]} {
return $default
} else {
return ""
}
}
::xowiki::formfield::enumeration instproc render_label_classes {} {
if {[info exists :result_statistics]} {
set values ${:answer}
} else {
set values [expr {[info exists :correction] ? ${:correction} : ""}]
}
return [lmap v $values {dict get {"" "" 1 correct 0 incorrect t correct f incorrect} $v}]
}
::xowiki::formfield::enumeration instproc pretty_value v {
if {[info exists :category_label($v)]} {
return [set :category_label($v)]
}
if {[info exists :multiple] && ${:multiple}} {
foreach o ${:options} {
lassign $o label value
set labels($value) [:localize $label]
}
set values [list]
foreach i $v {lappend values $labels($i)}
return [join $values {, }]
} else {
foreach o ${:options} {
lassign $o label value
if {$value eq $v} {return [:localize $label]}
}
}
}
::xowiki::formfield::enumeration instproc answer_is_correct {} {
if {![info exists :answer]} {
return 0
} else {
:stats_record_count
set value [:value]
set :correction {}
set r 0; set f 0; set rk 0; set fk 0; set W 0; set O 0; set R 0
foreach o ${:options} a ${:answer} {
lassign $o label v
if {$a} {
incr r
set correctly_answered [expr {$v in $value}]
} else {
set correctly_answered [expr {$v ni $value}]
incr f
}
:stats_record_detail -label $label -value $v $correctly_answered
lappend :correction $correctly_answered
if {$correctly_answered} {
incr R
} else {
incr W
}
if {$v in $value} {
if {$a} {
incr rk
} else {
incr fk
}
}
set scores [:scores -r $r -f $f -rk $rk -fk $fk -R $R -W $W]
set :correction_data [list item [list r $r f $f] marks [list rk $rk fk $fk] answers [list R $R W $W] scores $scores]
}
return [expr {0 ni ${:correction} ? 1 : -1}]
}
}
::xowiki::formfield::enumeration instproc make_correct {} {
if {[info exists :answer_value]} {
set :value ${:answer_value}
}
}
::xowiki::formfield::enumeration instproc scores {{-r 0} {-f 0} {-rk 0} {-fk 0} -R -W} {
if {$r > 0} {
if {$f == 0} {
set wi1 [expr {max((100.0/$r) * $rk, 0)}]
set wi2 [expr {max((100.0/$r) * $rk, 0)}]
} else {
set wi1 [expr {max((100.0/$r) * $rk - (100.0/$f) * $fk, 0)}]
if {$f == 1} {
set wi2 [expr {max((100.0/$r) * $rk - min(50.0, (100.0/$f)) * $fk, 0)}]
} else {
set wi2 $wi1
}
}
set canvas [expr {max(($rk * 100.0/$r) - ($fk * 100.0/$r), 0)}]
set etk [expr {100.0 * (($r*1.0+$f) /$r) * ($rk - $fk) / ($R + $W) }]
} else {
set wi1 0.0
set wi2 0.0
set etk 0.0
set canvas 0.0
}
set s1 [expr {100.0 * $R / ($R + $W) }]
set s2 [expr {100.0 * ($R - $W/2.0) / ($R + $W) }]
set ggw0 [expr {100.0 * ($R - $W) / ($R + $W) }]
set ggw [:ggw $R $W]
return [list wi1 $wi1 wi2 $wi2 s1 $s1 s2 $s2 etk $etk ggw0 $ggw0 ggw $ggw canvas $canvas]
}
::xowiki::formfield::enumeration instproc render_input {} {
if {![::xotcl::self isnextcall]} {
error "Abstract method render_input called"
} else {::xotcl::next}
}
::xowiki::formfield::enumeration instproc render_result_statistics rep {
if {[info exists :result_statistics] && [dict exists ${:result_statistics} count]} {
set alternative_counts [expr {[dict exists ${:result_statistics} $rep]
? [dict get ${:result_statistics} $rep]
: ""}]
set incorrect_count 0; set correct_count 0
if {$alternative_counts ne ""} {
foreach key {0 1} var {incorrect_count correct_count} {
if {[dict exists $alternative_counts $key]} {
set $var [dict get $alternative_counts $key]
}
}
}
set answered_count [expr {$correct_count + $incorrect_count}]
if {$answered_count > 0} {
set with_pie_charts [::xo::cc query_parameter pie:boolean 0]
if {$with_pie_charts} {
if {![info exists ::__xotcl_highcharts_pie]} {
if {[template::head::can_resolve_urn urn:ad:js:highcharts]} {
template::add_body_script -src urn:ad:js:highcharts
} else {
template::add_body_script -src "//code.highcharts.com/highcharts.js"
security::csp::require script-src code.highcharts.com
}
}
set graphID pie-[incr ::__xotcl_highcharts_pie]
}
::html::div -class container {
::html::div -class row {
::html::span -class "col-sm-2" -style "font-size: x-small; float: right;" {
::html::t "$correct_count of $answered_count correct"
}
if {$with_pie_charts} {
::html::div -class "col-sm-2" -style "width: 400px; height:120px;" -id $graphID {}
} else {
::html::div -class "progress col-sm-8" -style "padding: 0px 0px 0px 0px;" {
set percentage [format %2.0f [expr {$correct_count * 100.0 / $answered_count}]]
::html::div -class "progress-bar progress-bar-success" -role "progressbar" -aria-valuenow $percentage -aria-valuemin "0" -aria-valuemax "100" -style "width:$percentage%" {
if {$percentage > 0} {
::html::t "$percentage % correct"
}
}
}
}
}
}
if {$with_pie_charts} {
set startAngle [expr {$correct_count == 0 || $incorrect_count == 0 ? 90: 0}]
template::add_body_script -script [subst [ns_trim {
Highcharts.chart('$graphID', {
chart: {type: 'pie'},
plotOptions: {pie: {size: 35, startAngle: $startAngle }},
title: {text: ''},
colors: \['green', 'red'\],
credits: {enabled: false },
series: \[{name: 'Results', data: \[ {name:'correct', y: $correct_count}, {name:'incorrect', y: $incorrect_count}\]}\]
});
}]]
}
}
}
}
::xowiki::formfield::enumeration instproc get_labels values {
if {${:multiple}} {
set labels [list]
foreach v $values {
lappend labels [list [:get_entry_label $v] $v]
}
return $labels
} else {
return [list [list [:get_entry_label $values] $values]]
}
}
::xowiki::formfield::enumeration instproc initialize {} {
if {[info exists :category_tree]} {
:config_from_category_tree ${:category_tree}
}
if {[info exists :answer]} {
set count 1
set :answer_value {}
try {
foreach a ${:answer} {
if {$a} {
lappend :answer_value $count
}
incr count
}
} on error {errorMsg} {
ns_log error "${:name}: invalid answer value provided '${:answer}': must be list of booleans"
error $errorMsg
}
}
next
if {${:required} && ${:value} eq ""} {
set :value [lindex ${:options} 0 1]
}
}
::xowiki::formfield::enumeration instproc render_label_text {label CSSclass description} {
if {${:richtext}} {
::html::div -class richtext-label {
::html::t -disableOutputEscaping $label
if {[info exists :evaluated_answer_result]
&& "incorrect" in $CSSclass
&& $description ne ""
} {
html::div -class "help-block description" {
html::t $description
}
}
}
} else {
::html::t " $label "
}
}
::xowiki::formfield::enumeration instproc add_statistics {{-options ""}} {
next
foreach v ${:value} {
dict incr :result_statistics $v
}
}
::xowiki::formfield::enumeration instproc ggw {R W} {
return [expr {100.0 * ($R - $W*0.5) / ($R + $W) }]
}
::xowiki::formfield::enumeration instproc config_from_category_tree tree_name {
set package_id [${:object} package_id]
set tree_ids [::xowiki::Category get_mapped_trees -object_id $package_id -locale ${:locale} -names $tree_name -output tree_id]
set tree_id [lindex $tree_ids 0]
if {$tree_id eq ""} {
:msg "cannot lookup mapped category tree name '$tree_name'"
return
}
set subtree_id ""
set options [list]
foreach category [::xowiki::Category get_category_infos -subtree_id $subtree_id -tree_id $tree_id] {
lassign $category category_id category_name deprecated_p level
set category_name [ns_quotehtml [lang::util::localize $category_name]]
set :category_label($category_id) $category_name
if { $level>1 } {
set category_name "[string repeat {.} [expr {2*$level-4}]]..$category_name"
}
lappend options [list $category_name $category_id]
}
set :options $options
if {[info exists :default] && ${:default} ne ""} {
set optdict [concat {*}$options]
if {[dict exists $optdict ${:default}]} {
set :default [dict get $optdict ${:default}]
}
}
set :is_category_field 1
}
::xowiki::formfield::enumeration instproc stats_record_detail {-label -value correctly_answered} {
set reporting_obj ::[${:object} parent_id]
$reporting_obj stats_record_detail -label $label -value $value -name ${:name} -correctly_answered $correctly_answered
}
::xowiki::formfield::enumeration instparametercmd category_tree
::xowiki::formfield::enumeration instparametercmd descriptions
::nsf::relation::set ::xowiki::formfield::enumeration superclass ::xowiki::formfield::ShuffleField
::nx::slotObj -container slot ::xowiki::formfield::enumeration
::xowiki::formfield::enumeration::slot eval {set :__parameter {
{category_tree}
{descriptions ""}
}}
::nsf::object::alloc ::xotcl::Attribute ::xowiki::formfield::enumeration::slot::category_tree {set :accessor public
set :configurable true
set :convert false
set :defaultmethods {}
set :disposition alias
set :domain ::xowiki::formfield::enumeration
set :incremental 0
set :manager ::xowiki::formfield::enumeration::slot::category_tree
set :methodname category_tree
set :multiplicity 1..1
set :name category_tree
set :per-object false
set :position 0
set :required false
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::xowiki::formfield::enumeration::slot::descriptions {set :accessor public
set :configurable true
set :convert false
set :default {}
set :defaultmethods {}
set :disposition alias
set :domain ::xowiki::formfield::enumeration
set :incremental 0
set :manager ::xowiki::formfield::enumeration::slot::descriptions
set :methodname descriptions
set :multiplicity 1..1
set :name descriptions
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
XQL Not present:Generic, PostgreSQL, Oracle
[
hide source ]
| [
make this the default ]