ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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;
29 protected array|string|null $mode_value = null;
30 protected int $mode_nr_of_selections = 0;
31 protected float $arithmetic_mean = 0;
32 protected string|array|null $median = null;
33 protected array $variables = [];
34 protected array $answers = [];
35
36 public function __construct(
37 SurveyQuestion $a_question
38 ) {
39 global $DIC;
40
41 $this->lng = $DIC->language();
42 $this->question = $a_question;
43 }
44
45 public function getQuestion(): SurveyQuestion
46 {
47 return $this->question;
48 }
49
50 public function setUsersAnswered(int $a_value): void
51 {
52 $this->users_answered = $a_value;
53 }
54
55 public function getUsersAnswered(): int
56 {
58 }
59
60 public function setUsersSkipped(int $a_value): void
61 {
62 $this->users_skipped = $a_value;
63 }
64
65 public function getUsersSkipped(): int
66 {
68 }
69
73 public function setMode(
74 $a_value,
75 int $a_nr_of_selections
76 ): void {
77 $this->mode_value = is_array($a_value)
78 ? $a_value
79 : trim($a_value ?? "");
80 $this->mode_nr_of_selections = $a_nr_of_selections;
81 }
82
86 public function getModeValue(): array|string|null
87 {
88 return $this->mode_value;
89 }
90
91 public function getModeValueAsText(): string
92 {
93 if ($this->mode_value === null) {
94 return "";
95 }
96
97 $res = array();
98
99 $mvalues = $this->mode_value;
100 if (!is_array($mvalues)) {
101 $mvalues = array($mvalues);
102 }
103 sort($mvalues, SORT_NUMERIC);
104 foreach ($mvalues as $value) {
105 $res[] = $this->getScaleText($value);
106 }
107
108 return implode(", ", $res);
109 }
110
111 public function getModeNrOfSelections(): int
112 {
113 return $this->mode_nr_of_selections;
114 }
115
116 public function setMean(float $a_mean): void
117 {
118 $this->arithmetic_mean = $a_mean;
119 }
120
121 public function getMean(): float
122 {
123 return $this->arithmetic_mean;
124 }
125
129 public function setMedian(string|array $a_value): void
130 {
131 $this->median = is_array($a_value)
132 ? $a_value
133 : trim($a_value ?? "");
134 }
135
139 public function getMedian(): string|array
140 {
141 return $this->median;
142 }
143
144 public function getMedianAsText(): string
145 {
147
148 if ($this->median === null) {
149 return "";
150 }
151
152 if (!is_array($this->median)) {
153 return $this->getScaleText($this->median);
154 }
155
156 return $lng->txt("median_between") . " " .
157 $this->getScaleText($this->median[0]) . " " .
158 $lng->txt("and") . " " .
159 $this->getScaleText($this->median[1]);
160 }
161
162 public function addVariable(
164 ): void {
165 $this->variables[] = $a_variable;
166 }
167
168 public function getVariables(): array
169 {
170 return $this->variables ?? [];
171 }
172
173 public function addAnswer(
175 ): void {
176 $this->answers[] = $a_answer;
177 }
178
179 public function getAnswers(): array
180 {
181 return $this->answers ?? [];
182 }
183
188 public function getScaleText(
189 $a_value
190 ): string {
191 if (!count($this->variables)) {
192 return $a_value;
193 } else {
194 foreach ($this->variables as $var) {
195 if ($var->cat->scale == $a_value) {
196 return $var->cat->title . " [" . $a_value . "]";
197 }
198 }
199 }
200 return "";
201 }
202
203 protected function getCatTitle(
204 float $a_value
205 ): string {
206 if (!count($this->variables)) {
207 return $a_value;
208 } else {
209 foreach ($this->variables as $var) {
210 if ($var->cat->scale == $a_value) {
211 return $var->cat->title;
212 }
213 }
214 }
215 return "";
216 }
217
218 public function getMappedTextAnswers(): array
219 {
220 $res = array();
221
222 foreach ($this->answers as $answer) {
223 if ($answer->text) {
224 $res[$this->getScaleText($answer->value)][] = $answer->text;
225 }
226 }
227
228 return $res;
229 }
230
231 public function getUserResults(
232 int $a_active_id
233 ): array {
234 $res = array();
235
236 $answers = $this->getAnswers();
237 if ($answers) {
238 foreach ($answers as $answer) {
239 if ($answer->active_id == $a_active_id) {
240 $res[] = array(
241 $this->getScaleText($answer->value),
242 $answer->text,
243 $answer->value,
244 $this->getCatTitle($answer->value)
245 );
246 }
247 }
248 }
249
250 return $res;
251 }
252}
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