ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.SurveyMetricQuestionEvaluation.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "Modules/SurveyQuestionPool/classes/class.SurveyQuestionEvaluation.php";
5
13{
14 //
15 // RESULTS
16 //
17
18 protected function parseResults(ilSurveyEvaluationResults $a_results, array $a_answers, SurveyCategories $a_categories = null)
19 {
20 parent::parseResults($a_results, $a_answers);
21
22 // add arithmetic mean
23 $total = $sum = 0;
24 foreach ($a_answers as $answers) {
25 foreach ($answers as $answer) {
26 $total++;
27 $sum += $answer["value"];
28 }
29 }
30 if ($total > 0) {
31 $a_results->setMean($sum/$total);
32 }
33 }
34
35
36 //
37 // DETAILS
38 //
39
40 public function getGrid($a_results, $a_abs = true, $a_perc = true)
41 {
43
44 if ((bool) $a_abs && (bool) $a_perc) {
45 $cols = array(
46 $lng->txt("category_nr_selected"),
47 $lng->txt("svy_fraction_of_selections")
48 );
49 } elseif ((bool) $a_abs) {
50 $cols = array(
51 $lng->txt("category_nr_selected")
52 );
53 } else {
54 $cols = array(
55 $lng->txt("svy_fraction_of_selections")
56 );
57 }
58
59 $res = array(
60 "cols" => $cols,
61 "rows" => array()
62 );
63
64 // as we have no variables build rows from answers directly
65 $answ = $a_results->getAnswers();
66 if (is_array($answ)) {
67 $total = sizeof($a_results->getAnswers());
68 if ($total > 0) {
69 $cumulated = array();
70 foreach ($a_results->getAnswers() as $answer) {
71 $cumulated[$answer->value]++;
72 }
73 foreach ($cumulated as $value => $count) {
74 $perc = sprintf("%.2f", $count / $total * 100) . "%";
75 if ((bool) $a_abs && (bool) $a_perc) {
76 $res["rows"][] = array(
77 $value,
78 $count,
79 $perc
80 );
81 } elseif ((bool) $a_abs) {
82 $res["rows"][] = array(
83 $value,
84 $count
85 );
86 } else {
87 $res["rows"][] = array(
88 $value,
89 $perc
90 );
91 }
92 }
93 }
94 }
95
96 return $res;
97 }
98
99 public function getChart($a_results)
100 {
102
103 include_once "Services/Chart/classes/class.ilChart.php";
104 $chart = ilChart::getInstanceByType(ilChart::TYPE_GRID, $a_results->getQuestion()->getId());
105 $chart->setYAxisToInteger(true);
106
107 $colors = $this->getChartColors();
108 $chart->setColors($colors);
109
110 // :TODO:
111 $chart->setsize($this->chart_width, $this->chart_height);
112
113 $data = $chart->getDataInstance(ilChartGrid::DATA_BARS);
114 $data->setLabel($lng->txt("category_nr_selected"));
115 $data->setBarOptions(0.5, "center");
116 $data->setFill(1);
117
118 $total = sizeof($a_results->getAnswers());
119 if ($total > 0) {
120 $cumulated = array();
121 foreach ($a_results->getAnswers() as $answer) {
122 $cumulated[$answer->value]++;
123 }
124
125 $labels = array();
126 foreach ($cumulated as $value => $count) {
127 $data->addPoint($value, $count);
128 $labels[$value] = $value;
129 }
130 $chart->addData($data);
131
132 $chart->setTicks($labels, false, true);
133
134 return $chart->getHTML();
135 }
136 }
137
138
139 //
140 // EXPORT
141 //
142
149 public function getExportGrid($a_results)
150 {
152
153 $res = array(
154 "cols" => array(
155 $lng->txt("value"),
156 $lng->txt("category_nr_selected"),
157 $lng->txt("svy_fraction_of_selections")
158 ),
159 "rows" => array()
160 );
161
162 // as we have no variables build rows from answers directly
163 $total = sizeof($a_results->getAnswers());
164 if ($total > 0) {
165 $cumulated = array();
166 foreach ($a_results->getAnswers() as $answer) {
167 $cumulated[$answer->value]++;
168 }
169 foreach ($cumulated as $value => $count) {
170 $res["rows"][] = array(
171 $value,
172 $count,
173 sprintf("%.2f", $count/$total*100) . "%"
174 );
175 }
176 }
177
178 return $res;
179 }
180
181 public function addUserSpecificResults(array &$a_row, $a_user_id, $a_results)
182 {
183 $answer = $a_results->getUserResults($a_user_id);
184 if ($answer === null) {
185 $a_row[] = $this->getSkippedValue();
186 } else {
187 $a_row[] = $answer[0][0];
188 }
189 }
190}
sprintf('%.4f', $callTime)
$total
Definition: Utf8Test.php:87
An exception for terminatinating execution or to throw for unit testing.
Class SurveyCategories.
addUserSpecificResults(array &$a_row, $a_user_id, $a_results)
getGrid($a_results, $a_abs=true, $a_perc=true)
Get grid data.
parseResults(ilSurveyEvaluationResults $a_results, array $a_answers, SurveyCategories $a_categories=null)
Parse answer data into results instance.
getSkippedValue()
Get caption for skipped value.
static getInstanceByType($a_type, $a_id)
Get type instance.
const TYPE_GRID
foreach($_POST as $key=> $value) $res
$cols
Definition: xhr_table.php:11