ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SurveyMetricQuestionEvaluation.php
Go to the documentation of this file.
1<?php
2
25{
26 //
27 // RESULTS
28 //
29
30 protected function parseResults(
32 array $a_answers,
33 ?SurveyCategories $a_categories = null
34 ): void {
35 parent::parseResults($a_results, $a_answers);
36
37 // add arithmetic mean
38 $total = $sum = 0;
39 foreach ($a_answers as $answers) {
40 foreach ($answers as $answer) {
41 $total++;
42 $sum += $answer["value"];
43 }
44 }
45 if ($total > 0) {
46 $a_results->setMean($sum / $total);
47 }
48 }
49
50
51 //
52 // DETAILS
53 //
54
58 public function getGrid(
59 $a_results,
60 bool $a_abs = true,
61 bool $a_perc = true
62 ): array {
63 $lng = $this->lng;
64
65 if ($a_abs && $a_perc) {
66 $cols = array(
67 $lng->txt("category_nr_selected"),
68 $lng->txt("svy_fraction_of_selections")
69 );
70 } elseif ($a_abs) {
71 $cols = array(
72 $lng->txt("category_nr_selected")
73 );
74 } else {
75 $cols = array(
76 $lng->txt("svy_fraction_of_selections")
77 );
78 }
79
80 $res = array(
81 "cols" => $cols,
82 "rows" => array()
83 );
84
85 // as we have no variables build rows from answers directly
86 $answ = $a_results->getAnswers();
87 $total = count($answ);
88
89 if ($total > 0) {
90 $cumulated = array();
91 foreach ($a_results->getAnswers() as $answer) {
92 $cumulated[(string) $answer->value] = ($cumulated[(string) $answer->value] ?? 0) + 1;
93 }
94 foreach ($cumulated as $value => $count) {
95 $perc = sprintf("%.2f", $count / $total * 100) . "%";
96 if ($a_abs && $a_perc) {
97 $res["rows"][] = array(
98 $value,
99 $count,
100 $perc
101 );
102 } elseif ($a_abs) {
103 $res["rows"][] = array(
104 $value,
105 $count
106 );
107 } else {
108 $res["rows"][] = array(
109 $value,
110 $perc
111 );
112 }
113 }
114 }
115
116 return $res;
117 }
118
122 public function getChart($a_results): ?array
123 {
125
126 $chart = ilChart::getInstanceByType(ilChart::TYPE_GRID, $a_results->getQuestion()->getId());
127 $chart->setYAxisToInteger(true);
128
129 $colors = $this->getChartColors();
130 $chart->setColors($colors);
131
132 // :TODO:
133 $chart->setSize((string) $this->chart_width, (string) $this->chart_height);
134
135 $data = $chart->getDataInstance(ilChartGrid::DATA_BARS);
136 $data->setLabel($lng->txt("category_nr_selected"));
137 $data->setBarOptions(0.5, "center");
138 $data->setFill(1);
139
140 $total = count($a_results->getAnswers());
141 if ($total > 0) {
142 $cumulated = array();
143 foreach ($a_results->getAnswers() as $answer) {
144 $cumulated[(string) $answer->value] = ($cumulated[(string) $answer->value] ?? 0) + 1;
145 }
146
147 $labels = array();
148 foreach ($cumulated as $value => $count) {
149 $data->addPoint($value, $count);
150 $labels[$value] = $value;
151 }
152 $chart->addData($data);
153
154 $chart->setTicks($labels, false, true);
155
156 return array(
157 $chart->getHTML(),
158 null
159 );
160 }
161 return null;
162 }
163
164
165 //
166 // EXPORT
167 //
168
173 public function getExportGrid($a_results): array
174 {
176
177 $res = array(
178 "cols" => array(
179 $lng->txt("value"),
180 $lng->txt("category_nr_selected"),
181 $lng->txt("svy_fraction_of_selections")
182 ),
183 "rows" => array()
184 );
185
186 // as we have no variables build rows from answers directly
187 $total = count($a_results->getAnswers());
188 if ($total > 0) {
189 $cumulated = array();
190 foreach ($a_results->getAnswers() as $answer) {
191 $cumulated[(string) $answer->value] = ($cumulated[(string) $answer->value] ?? 0) + 1;
192 }
193 foreach ($cumulated as $value => $count) {
194 $res["rows"][] = array(
195 $value,
196 $count,
197 sprintf("%.2f", $count / $total * 100) . "%"
198 );
199 }
200 }
201
202 return $res;
203 }
204
208 public function addUserSpecificResults(
209 array &$a_row,
210 int $a_user_id,
211 $a_results
212 ): void {
213 $answer = $a_results->getUserResults($a_user_id);
214 if (count($answer) === 0) {
215 $a_row[] = $this->getSkippedValue();
216 } else {
217 $a_row[] = $answer[0][0];
218 }
219 }
220}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addUserSpecificResults(array &$a_row, int $a_user_id, $a_results)
getGrid( $a_results, bool $a_abs=true, bool $a_perc=true)
parseResults(ilSurveyEvaluationResults $a_results, array $a_answers, ?SurveyCategories $a_categories=null)
Parse answer data into results instance.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByType(int $a_type, string $a_id)
const TYPE_GRID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
global $lng
Definition: privfeed.php:31