ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSurveyEvaluationResults.php
Go to the documentation of this file.
1<?php
2
24{
25 protected ilLanguage $lng;
27 protected int $users_answered = 0;
28 protected int $users_skipped = 0;
32 protected $mode_value;
33 protected int $mode_nr_of_selections = 0;
34 protected float $arithmetic_mean = 0;
38 protected $median;
39 protected array $variables = array();
40 protected array $answers = array();
41
42 public function __construct(
43 SurveyQuestion $a_question
44 ) {
45 global $DIC;
46
47 $this->lng = $DIC->language();
48 $this->question = $a_question;
49 }
50
51 public function getQuestion(): SurveyQuestion
52 {
53 return $this->question;
54 }
55
56 public function setUsersAnswered(int $a_value): void
57 {
58 $this->users_answered = $a_value;
59 }
60
61 public function getUsersAnswered(): int
62 {
64 }
65
66 public function setUsersSkipped(int $a_value): void
67 {
68 $this->users_skipped = $a_value;
69 }
70
71 public function getUsersSkipped(): int
72 {
74 }
75
79 public function setMode(
80 $a_value,
81 int $a_nr_of_selections
82 ): void {
83 $this->mode_value = is_array($a_value)
84 ? $a_value
85 : trim($a_value ?? "");
86 $this->mode_nr_of_selections = $a_nr_of_selections;
87 }
88
92 public function getModeValue()
93 {
94 return $this->mode_value;
95 }
96
97 public function getModeValueAsText(): string
98 {
99 if ($this->mode_value === null) {
100 return "";
101 }
102
103 $res = array();
104
105 $mvalues = $this->mode_value;
106 if (!is_array($mvalues)) {
107 $mvalues = array($mvalues);
108 }
109 sort($mvalues, SORT_NUMERIC);
110 foreach ($mvalues as $value) {
111 $res[] = $this->getScaleText($value);
112 }
113
114 return implode(", ", $res);
115 }
116
117 public function getModeNrOfSelections(): int
118 {
119 return $this->mode_nr_of_selections;
120 }
121
122 public function setMean(float $a_mean): void
123 {
124 $this->arithmetic_mean = $a_mean;
125 }
126
127 public function getMean(): float
128 {
129 return $this->arithmetic_mean;
130 }
131
135 public function setMedian($a_value): void
136 {
137 $this->median = is_array($a_value)
138 ? $a_value
139 : trim($a_value ?? "");
140 }
141
145 public function getMedian()
146 {
147 return $this->median;
148 }
149
150 public function getMedianAsText(): string
151 {
153
154 if ($this->median === null) {
155 return "";
156 }
157
158 if (!is_array($this->median)) {
159 return $this->getScaleText($this->median);
160 }
161
162 return $lng->txt("median_between") . " " .
163 $this->getScaleText($this->median[0]) . " " .
164 $lng->txt("and") . " " .
165 $this->getScaleText($this->median[1]);
166 }
167
168 public function addVariable(
170 ): void {
171 $this->variables[] = $a_variable;
172 }
173
174 public function getVariables(): array
175 {
176 return $this->variables ?? [];
177 }
178
179 public function addAnswer(
181 ): void {
182 $this->answers[] = $a_answer;
183 }
184
185 public function getAnswers(): array
186 {
187 return $this->answers ?? [];
188 }
189
194 public function getScaleText(
195 $a_value
196 ): string {
197 if (!count($this->variables)) {
198 return $a_value;
199 } else {
200 foreach ($this->variables as $var) {
201 if ($var->cat->scale == $a_value) {
202 return $var->cat->title . " [" . $a_value . "]";
203 }
204 }
205 }
206 return "";
207 }
208
209 protected function getCatTitle(
210 float $a_value
211 ): string {
212 if (!count($this->variables)) {
213 return $a_value;
214 } else {
215 foreach ($this->variables as $var) {
216 if ($var->cat->scale == $a_value) {
217 return $var->cat->title;
218 }
219 }
220 }
221 return "";
222 }
223
224 public function getMappedTextAnswers(): array
225 {
226 $res = array();
227
228 foreach ($this->answers as $answer) {
229 if ($answer->text) {
230 $res[$this->getScaleText($answer->value)][] = $answer->text;
231 }
232 }
233
234 return $res;
235 }
236
237 public function getUserResults(
238 int $a_active_id
239 ): array {
240 $res = array();
241
242 $answers = $this->getAnswers();
243 if ($answers) {
244 foreach ($answers as $answer) {
245 if ($answer->active_id == $a_active_id) {
246 $res[] = array(
247 $this->getScaleText($answer->value),
248 $answer->text,
249 $answer->value,
250 $this->getCatTitle($answer->value)
251 );
252 }
253 }
254 }
255
256 return $res;
257 }
258}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(SurveyQuestion $a_question)
addVariable(ilSurveyEvaluationResultsVariable $a_variable)
addAnswer(ilSurveyEvaluationResultsAnswer $a_answer)
setMode( $a_value, int $a_nr_of_selections)
$res
Definition: ltiservices.php:69
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26