Class ::xowiki::includelet::form-stats
::xowiki::includelet::form-stats
create ... \
[ -__decoration (default "plain") ] \
[ -parameter_declaration (default "
{-form}
{-parent_id}
{-property _state}
{-orderby "count,desc"}
{-renderer "table"}
") ]
Include form statistics for the specofied Form page.
Defined in /var/www/openacs.org/packages/xowiki/tcl/includelet-procs.tclClass Relations
- class: ::xowiki::IncludeletClass
![[i]](/resources/acs-subsite/ZoomIn16.gif)
- superclass: ::xowiki::Includelet
![[i]](/resources/acs-subsite/ZoomIn16.gif)
::xowiki::IncludeletClass create ::xowiki::includelet::form-stats \
-superclass ::xowiki::Includelet
Methods (to be applied on instances)
__decoration (setter)
parameter_declaration (setter)
render (scripted)
:get_parameters
set o ${:__including_page}
if {![info exists parent_id]} {set parent_id [$o parent_id]}
set form_item_ids [::$package_id instantiate_forms -forms $form -parent_id $parent_id]
if {[llength $form_item_ids] != 1} {
return "no such form $form<br>\n"
}
set items [::xowiki::FormPage get_form_entries -base_item_ids $form_item_ids -form_fields "" -always_queried_attributes "*" -initialize false -publish_status all -package_id $package_id]
set sum 0
foreach i [$items children] {
set value ""
if {[string match _* $property]} {
set varname [string range $property 1 end]
if {[$i exists $varname]} {set value [$i set $varname]}
} else {
set instance_attributes [$i set instance_attributes]
if {[dict exists $instance_attributes $property]} {
set value [dict get $instance_attributes $property]
}
}
if {[info exists __count($value)]} {incr __count($value)} else {set __count($value) 1}
incr sum 1
}
if {$sum == 0} {
return "[_ xowiki.no_data]<br>\n"
}
if {$renderer eq "highcharts"} {
set percentages [list]
foreach {value count} [array get __count] {
lappend percentages $value [format %.2f [expr {$count*100.0/$sum}]]
}
set h [highcharts new -volatile -id [:js_name] -title [::xowiki::Includelet js_encode "$sum $total_text [_ xowiki.Answers_for_Survey] '[$form_item_ids title]'"]]
return [$h pie [list value count] $percentages]
} else {
[:tableWidget] create t1 -volatile -columns {
Field create value -orderby value -label value
Field create count -orderby count -label count
}
lassign [split $orderby ,] att order
t1 orderby -order [expr {$order eq "asc" ? "increasing" : "decreasing"}] $att
foreach {value count} [array get __count] {
t1 add -value $value -count $count
}
return [t1 asHTML]
}