ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSurveyEvaluationResults.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
15 protected $lng;
16
17 protected $question; // [SurveyQuestion]
18 protected $users_answered; // [int]
19 protected $users_skipped; // [int]
20 protected $mode_value; // [int]
21 protected $mode_nr_of_selections; // [int]
22 protected $arithmetic_mean; // [float]
23 protected $median; // [string|float]
24 protected $variables = array(); // [array]
25 protected $answers = array(); // [array]
26
27 public function __construct(SurveyQuestion $a_question)
28 {
29 global $DIC;
30
31 $this->lng = $DIC->language();
32 $this->question = $a_question;
33 }
34
35 public function getQuestion()
36 {
37 return $this->question;
38 }
39
40 public function setUsersAnswered($a_value)
41 {
42 $this->users_answered = (int) $a_value;
43 }
44
45 public function getUsersAnswered()
46 {
48 }
49
50 public function setUsersSkipped($a_value)
51 {
52 $this->users_skipped = (int) $a_value;
53 }
54
55 public function getUsersSkipped()
56 {
58 }
59
60 public function setMode($a_value, $a_nr_of_selections)
61 {
62 $this->mode_value = is_array($a_value)
63 ? $a_value
64 : trim($a_value);
65 $this->mode_nr_of_selections = (int) $a_nr_of_selections;
66 }
67
68 public function getModeValue()
69 {
70 return $this->mode_value;
71 }
72
73 public function getModeValueAsText()
74 {
75 if ($this->mode_value === null) {
76 return;
77 }
78
79 $res = array();
80
81 $mvalues = $this->mode_value;
82 if (!is_array($mvalues)) {
83 $mvalues = array($mvalues);
84 }
85 sort($mvalues, SORT_NUMERIC);
86 foreach ($mvalues as $value) {
87 $res[] = $this->getScaleText($value);
88 }
89
90 return implode(", ", $res);
91 }
92
93 public function getModeNrOfSelections()
94 {
96 }
97
98 public function setMean($a_mean)
99 {
100 $this->arithmetic_mean = (float) $a_mean;
101 }
102
103 public function getMean()
104 {
106 }
107
108 public function setMedian($a_value)
109 {
110 $this->median = is_array($a_value)
111 ? $a_value
112 : trim($a_value);
113 }
114
115 public function getMedian()
116 {
117 return $this->median;
118 }
119
120 public function getMedianAsText()
121 {
123
124 if ($this->median === null) {
125 return;
126 }
127
128 if (!is_array($this->median)) {
129 return $this->getScaleText($this->median);
130 } else {
131 return $lng->txt("median_between") . " " .
132 $this->getScaleText($this->median[0]) . " " .
133 $lng->txt("and") . " " .
134 $this->getScaleText($this->median[1]);
135 }
136 }
137
139 {
140 $this->variables[] = $a_variable;
141 }
142
143 public function getVariables()
144 {
145 if (sizeof($this->variables)) {
146 return $this->variables;
147 }
148 }
149
151 {
152 $this->answers[] = $a_answer;
153 }
154
155 public function getAnswers()
156 {
157 if (sizeof($this->answers)) {
158 return $this->answers;
159 }
160 }
161
162 protected function getScaleText($a_value)
163 {
164 if (!sizeof($this->variables)) {
165 return $a_value;
166 } else {
167 foreach ($this->variables as $var) {
168 if ($var->cat->scale == $a_value) {
169 return $var->cat->title . " [" . $a_value . "]";
170 }
171 }
172 }
173 }
174
175 protected function getCatTitle($a_value)
176 {
177 if (!sizeof($this->variables)) {
178 return $a_value;
179 } else {
180 foreach ($this->variables as $var) {
181 if ($var->cat->scale == $a_value) {
182 return $var->cat->title;
183 }
184 }
185 }
186 }
187
188 public function getMappedTextAnswers()
189 {
190 $res = array();
191
192 foreach ($this->answers as $answer) {
193 if ($answer->text) {
194 $res[$this->getScaleText($answer->value)][] = $answer->text;
195 }
196 }
197
198 return $res;
199 }
200
201 public function getUserResults($a_active_id)
202 {
203 $res = array();
204
205 $answers = $this->getAnswers();
206 if ($answers) {
207 foreach ($answers as $answer) {
208 if ($answer->active_id == $a_active_id) {
209 $res[] = array(
210 $this->getScaleText($answer->value),
211 $answer->text,
212 $answer->value,
213 $this->getCatTitle($answer->value)
214 );
215 }
216 }
217 }
218
219 return $res;
220 }
221}
222
224{
225 public $cat; // [SurveyCategory]
226 public $abs; // [int]
227 public $perc; // [float]
228
229 public function __construct(ilSurveyCategory $a_cat, $a_abs, $a_perc)
230 {
231 $this->cat = $a_cat;
232 $this->abs = (int) $a_abs;
233 $this->perc = (float) $a_perc;
234 }
235}
236
238{
239 public $active_id; // [int]
240 public $value; // [int|float]
241 public $text; // [string]
242
243 public function __construct($a_active_id, $a_value, $a_text)
244 {
245 $this->active_id = (int) $a_active_id;
246 $this->value = $a_value;
247 $this->text = trim($a_text);
248 }
249}
An exception for terminatinating execution or to throw for unit testing.
Basic class for all survey question types.
Survey category class.
__construct($a_active_id, $a_value, $a_text)
__construct(ilSurveyCategory $a_cat, $a_abs, $a_perc)
__construct(SurveyQuestion $a_question)
setMode($a_value, $a_nr_of_selections)
addVariable(ilSurveyEvaluationResultsVariable $a_variable)
addAnswer(ilSurveyEvaluationResultsAnswer $a_answer)
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res