ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
SurveyMatrixQuestionEvaluation Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for SurveyMatrixQuestionEvaluation:
+ Collaboration diagram for SurveyMatrixQuestionEvaluation:

Public Member Functions

 getResults ()
 
 getGrid ( $a_results, bool $a_abs=true, bool $a_perc=true)
 
 getTextAnswers ($a_results)
 
 getChart ($a_results)
 
 exportResults ( $a_results, bool $a_do_title, bool $a_do_label)
 
 getUserSpecificVariableTitles (array &$a_title_row, array &$a_title_row2, bool $a_do_title, bool $a_do_label)
 Get title columns for user-specific export. More...
 
 addUserSpecificResults (array &$a_row, int $a_user_id, $a_results)
 
- Public Member Functions inherited from SurveyQuestionEvaluation
 __construct (SurveyQuestion $a_question, array $a_finished_ids=[])
 
 getResults ()
 Get results. More...
 
 getSumScores ()
 Get sum score for this question for all active ids of run. More...
 
 parseUserSpecificResults ($a_qres, int $a_user_id)
 
 getGrid ( $a_results, bool $a_abs=true, bool $a_perc=true)
 Get grid data. More...
 
 getTextAnswers ($a_results)
 Get text answers. More...
 
 getChart ($a_results)
 
 getSkippedValue ()
 Get caption for skipped value. More...
 
 exportResults ( $a_results, bool $a_do_title, bool $a_do_label)
 
 getExportGrid ($a_results)
 Get grid data. More...
 
 getUserSpecificVariableTitles (array &$a_title_row, array &$a_title_row2, bool $a_do_title, bool $a_do_label)
 Get title columns for user-specific export. More...
 
 addUserSpecificResults (array &$a_row, int $a_user_id, $a_results)
 

Protected Member Functions

 parseResults (ilSurveyEvaluationResults $a_results, array $a_answers, ?SurveyCategories $a_categories=null)
 Parse answer data into results instance. More...
 
 supportsSumScore ()
 
 isSumScoreValid (int $nr_answer_records)
 Is sum score ok (question needs to be fully answered) More...
 
- Protected Member Functions inherited from SurveyQuestionEvaluation
 isSumScoreValid (int $nr_answer_records)
 Is sum score ok (question needs to be fully answered) More...
 
 supportsSumScore ()
 
 parseResults (ilSurveyEvaluationResults $a_results, array $a_answers, ?SurveyCategories $a_categories=null)
 Parse answer data into results instance. More...
 
 getChartColors ()
 
 getSurveyId ()
 
 getNrOfParticipants ()
 Returns the number of participants for a survey. More...
 
 getAnswerData ()
 

Additional Inherited Members

- Protected Attributes inherited from SurveyQuestionEvaluation
ilLanguage $lng
 
ilDBInterface $db
 
SurveyQuestion $question
 
array $finished_ids
 
int $chart_width = 400
 
int $chart_height = 300
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Survey matrix evaluation

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 25 of file class.SurveyMatrixQuestionEvaluation.php.

Member Function Documentation

◆ addUserSpecificResults()

SurveyMatrixQuestionEvaluation::addUserSpecificResults ( array &  $a_row,
int  $a_user_id,
  $a_results 
)
Parameters
array | ilSurveyEvaluationResults$a_results

Reimplemented from SurveyQuestionEvaluation.

Definition at line 375 of file class.SurveyMatrixQuestionEvaluation.php.

379 : void {
380 $answer_map = array();
381 foreach ($a_results as $row_results) {
382 $row_title = $row_results[0];
383 $row_result = $row_results[1];
384
385 $answers = $row_result->getUserResults($a_user_id);
386 if ($answers !== null) {
387 foreach ($answers as $answer) {
388 // mc
389 if ($this->question->getSubtype() === 1) {
390 $answer_map[$row_title . "|" . $answer[2]] = $answer[2];
391 } else {
392 $answer_map[$row_title] = $answer[3];
393 $answer_map[$row_title . "|scale"] = $answer[2]; // see #20646
394 }
395 if ($answer[1]) {
396 $answer_map[$row_title . "|txt"] = $answer[1];
397 }
398 }
399 }
400 }
401
402 if (!count($answer_map)) {
403 $a_row[] = $this->getSkippedValue();
404 } else {
405 $a_row[] = "";
406 }
407
408 for ($i = 0; $i < $this->question->getRowCount(); $i++) {
409 $row = $this->question->getRow($i);
410 $row_title = $row->title;
411
412 $a_row[] = $answer_map[$row_title] ?? null;
413 if ($this->question->getSubtype() === 0) {
414 $a_row[] = $answer_map[$row_title . "|scale"] ?? null; // see #20646
415 }
416
417 if ($row->other) {
418 $a_row[] = $answer_map[$row_title . "|txt"] ?? null;
419 }
420
421 // mc
422 if ($this->question->getSubtype() === 1) {
423 for ($index = 0; $index < $this->question->getColumnCount(); $index++) {
424 $col = $this->question->getColumn($index);
425 $a_row[] = $answer_map[$row_title . "|" . $col->scale] ?? null;
426 }
427 }
428 }
429 }
getSkippedValue()
Get caption for skipped value.

◆ exportResults()

SurveyMatrixQuestionEvaluation::exportResults (   $a_results,
bool  $a_do_title,
bool  $a_do_label 
)
Parameters
array | ilSurveyEvaluationResults$a_results

Reimplemented from SurveyQuestionEvaluation.

Definition at line 240 of file class.SurveyMatrixQuestionEvaluation.php.

244 : array {
245 $question = $a_results[0][1]->getQuestion();
246
247 $rows = array();
248 $row = array();
249
250 if ($a_do_title) {
251 $row[] = $question->getTitle();
252 }
253 if ($a_do_label) {
254 $row[] = $question->label;
255 }
256
257 $row[] = $question->getQuestiontext();
259
260 $row[] = (int) $a_results[0][1]->getUsersAnswered();
261 $row[] = (int) $a_results[0][1]->getUsersSkipped();
262 $row[] = null;
263 $row[] = null;
264 $row[] = null;
265 $row[] = null;
266 $row[] = null;
267
268 $rows[] = $row;
269
270 foreach ($a_results as $row_result) {
271 $row_title = $row_result[0];
272 $row_res = $row_result[1];
273
274 $row = array();
275
276 if ($a_do_title) {
277 $row[] = null;
278 }
279 if ($a_do_label) {
280 $row[] = null;
281 }
282
283 $row[] = $row_title;
284 $row[] = null;
285
286 $row[] = null;
287 $row[] = null;
288
289 // :TODO:
290 $row[] = is_array($row_res->getModeValue())
291 ? implode(", ", $row_res->getModeValue())
292 : $row_res->getModeValue();
293
294 $row[] = $row_res->getModeValueAsText();
295 $row[] = (int) $row_res->getModeNrOfSelections();
296
297 // :TODO:
298 $row[] = $row_res->getMedianAsText();
299
300 $row[] = $row_res->getMean();
301
302 $rows[] = $row;
303 }
304 return $rows;
305 }
static _getQuestionTypeName(string $type_tag)
Return the translation for a given question type.

◆ getChart()

SurveyMatrixQuestionEvaluation::getChart (   $a_results)
Parameters
array | ilSurveyEvaluationResults$a_results

Reimplemented from SurveyQuestionEvaluation.

Definition at line 156 of file class.SurveyMatrixQuestionEvaluation.php.

156 : ?array
157 {
160 (string) $a_results[0][1]->getQuestion()->getId()
161 );
162 $chart->setXAxisToInteger(true);
163 $chart->setStacked(true);
164
165 $colors = $this->getChartColors();
166 $chart->setColors($colors);
167
168 // :TODO:
169 //$chart->setsize($this->chart_width, $this->chart_height);
170
171 $data = $labels = $legend = array();
172
173 $row_idx = count($a_results);
174
175 $row_counter = 0;
176 $text_shortened = false;
177 foreach ($a_results as $row) {
178 $row_idx--;
179
180 $row_title = $row[0];
181 $row_results = $row[1];
182
183 #20363
184 $row_title = ++$row_counter . ". " . $row_title;
185 $labels[$row_idx] = ilStr::shortenTextExtended($row_title, 50, true);
186 if ($labels[$row_idx] != $row_title) {
187 $text_shortened = true;
188 }
189 //$labels[$row_idx] = wordwrap(ilUtil::shortenText($row_title, 50, true), 30, "<br />");
190
191 $vars = $row_results->getVariables();
192 if ($vars) {
193 foreach ($vars as $idx => $var) {
194 if (!array_key_exists($idx, $data)) {
195 $data[$idx] = $chart->getDataInstance(ilChartGrid::DATA_BARS);
196 $data[$idx]->setLabel((string) $var->cat->title);
197 $data[$idx]->setBarOptions(0.5, "center", true);
198 $data[$idx]->setFill(1);
199
200 $legend[] = array(
201 $var->cat->title,
202 $colors[$idx]
203 );
204 }
205
206 $data[$idx]->addPoint((float) $var->abs, $row_idx);
207 }
208 }
209 }
210
211 //Chart height depending on the number of questions. Not fixed anymore.
212 $this->chart_height = count($a_results) * 40;
213 //Chart width 500px if one or + question string are longer than 60 char. Otherwise the default width still aplied.
214 if ($text_shortened) {
215 $this->chart_width = 500;
216 }
217 $chart->setSize((string) $this->chart_width, (string) $this->chart_height);
218
219 foreach ($data as $var) {
220 $chart->addData($var);
221 }
222
223 $chart->setTicks(false, $labels, true);
224
225 return array(
226 $chart->getHTML(),
227 $legend
228 );
229 }
static getInstanceByType(int $a_type, string $a_id)
const TYPE_GRID
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
$data
Definition: storeScorm.php:45

References $data, ilChartGrid\DATA_BARS, ILIAS\Survey\Mode\getId(), ilChart\getInstanceByType(), ilStr\shortenTextExtended(), and ilChart\TYPE_GRID.

+ Here is the call graph for this function:

◆ getGrid()

SurveyMatrixQuestionEvaluation::getGrid (   $a_results,
bool  $a_abs = true,
bool  $a_perc = true 
)
Parameters
array | ilSurveyEvaluationResults$a_results

Reimplemented from SurveyQuestionEvaluation.

Definition at line 84 of file class.SurveyMatrixQuestionEvaluation.php.

88 : array {
89 $res = array(
90 "cols" => array(),
91 "rows" => array()
92 );
93
94 $tmp = $a_results;
95 $tmp = array_shift($tmp);
96 $vars = $tmp[1]->getVariables();
97 if ($vars) {
98 foreach ($vars as $var) {
99 $res["cols"][] = $var->cat->title;
100 }
101 }
102 $q_counter = 0;
103 foreach ($a_results as $results_row) {
104 #20363
105 $parsed_row = array(
106 ++$q_counter . ". " . $results_row[0]
107 );
108
109 $vars = $results_row[1]->getVariables();
110 if ($vars) {
111 foreach ($vars as $var) {
112 $perc = $var->perc
113 ? sprintf("%.2f", $var->perc * 100) . "%"
114 : "0%";
115
116 if ($a_abs && $a_perc) {
117 $parsed_row[] = $var->abs . " / " . $perc;
118 } elseif ($a_abs) {
119 $parsed_row[] = $var->abs;
120 } else {
121 $parsed_row[] = $perc;
122 }
123 }
124 }
125
126 $res["rows"][] = $parsed_row;
127 }
128 return $res;
129 }
foreach($_POST as $key=> $value) $res

◆ getResults()

SurveyMatrixQuestionEvaluation::getResults ( )
Returns
ilSurveyEvaluationResults|array

Reimplemented from SurveyQuestionEvaluation.

Definition at line 51 of file class.SurveyMatrixQuestionEvaluation.php.

52 {
53 $results = array();
54
55 $answers = $this->getAnswerData();
56
57 // parse rows
58 for ($r = 0; $r < $this->question->getRowCount(); $r++) {
59 $row_results = new ilSurveyEvaluationResults($this->question);
60
61 $this->parseResults(
62 $row_results,
63 (array) ($answers[$r] ?? []),
64 $this->question->getColumns()
65 );
66
67 $results[] = array(
68 $this->question->getRow($r)->title,
69 $row_results
70 );
71 }
72
73 return $results;
74 }
parseResults(ilSurveyEvaluationResults $a_results, array $a_answers, ?SurveyCategories $a_categories=null)
Parse answer data into results instance.
$results

References $results.

◆ getTextAnswers()

SurveyMatrixQuestionEvaluation::getTextAnswers (   $a_results)
Parameters
array | ilSurveyEvaluationResults$a_results

Reimplemented from SurveyQuestionEvaluation.

Definition at line 134 of file class.SurveyMatrixQuestionEvaluation.php.

134 : array
135 {
136 $res = array();
137
138 foreach ($a_results as $results_row) {
139 $texts = $results_row[1]->getMappedTextAnswers();
140 if ($texts) {
141 $idx = $results_row[0];
142 foreach ($texts as $answers) {
143 foreach ($answers as $answer) {
144 $res[$idx][] = $answer;
145 }
146 }
147 }
148 }
149
150 return $res;
151 }

References $res.

◆ getUserSpecificVariableTitles()

SurveyMatrixQuestionEvaluation::getUserSpecificVariableTitles ( array &  $a_title_row,
array &  $a_title_row2,
bool  $a_do_title,
bool  $a_do_label 
)

Get title columns for user-specific export.

Parameters
array$a_title_row(called by reference)
array$a_title_row2(called by reference)
bool$a_do_title
bool$a_do_label

Reimplemented from SurveyQuestionEvaluation.

Definition at line 307 of file class.SurveyMatrixQuestionEvaluation.php.

312 : void {
314
315 for ($i = 0; $i < $this->question->getRowCount(); $i++) {
316 // create row title according label, add 'other column'
317 $row = $this->question->getRow($i);
318
319 if ($a_do_title && $a_do_label) {
320 $a_title_row[] = $row->title;
321 $a_title_row2[] = $row->label;
322
323 if ($this->question->getSubtype() == 0) {
324 $a_title_row[] = $row->title; // see #20646
325 $a_title_row2[] = $row->label; // see #20646
326 }
327
328 if ($row->other) {
329 $a_title_row[] = $row->title;
330 $a_title_row2[] = $lng->txt('other');
331 }
332 } elseif ($a_do_title) {
333 $a_title_row[] = $row->title;
334 $a_title_row2[] = "";
335
336 if ($this->question->getSubtype() == 0) {
337 $a_title_row[] = $row->title; // see #20646
338 $a_title_row2[] = ""; // see #20646
339 }
340
341 if ($row->other) {
342 $a_title_row[] = $row->title;
343 $a_title_row2[] = $lng->txt('other');
344 }
345 } else {
346 $a_title_row[] = $row->label;
347 $a_title_row2[] = "";
348
349 if ($this->question->getSubtype() == 0) {
350 $a_title_row[] = $row->label; // see #20646
351 $a_title_row2[] = ""; // see #20646
352 }
353
354 if ($row->other) {
355 $a_title_row[] = $row->label;
356 $a_title_row2[] = $lng->txt('other');
357 }
358 }
359
360 // mc
361 if ($this->question->getSubtype() === 1) {
362 for ($index = 0; $index < $this->question->getColumnCount(); $index++) {
363 $col = $this->question->getColumn($index);
364
365 $a_title_row[] = $col->title . " [" . $col->scale . "]";
366 $a_title_row2[] = "";
367 }
368 }
369 }
370 }
txt(string|LanguageIdentifier $a_topic, ?int $n=null)
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...

References $lng.

◆ isSumScoreValid()

SurveyMatrixQuestionEvaluation::isSumScoreValid ( int  $nr_answer_records)
protected

Is sum score ok (question needs to be fully answered)

Reimplemented from SurveyQuestionEvaluation.

Definition at line 436 of file class.SurveyMatrixQuestionEvaluation.php.

436 : bool
437 {
438 if ($nr_answer_records === $this->question->getRowCount()) {
439 return true;
440 }
441 return false;
442 }

◆ parseResults()

SurveyMatrixQuestionEvaluation::parseResults ( ilSurveyEvaluationResults  $a_results,
array  $a_answers,
?SurveyCategories  $a_categories = null 
)
protected

Parse answer data into results instance.

Reimplemented from SurveyQuestionEvaluation.

Definition at line 27 of file class.SurveyMatrixQuestionEvaluation.php.

31 : void {
32 parent::parseResults($a_results, $a_answers, $a_categories);
33
34 $total = $sum = 0;
35 foreach ($a_results->getAnswers() as $answer) {
36 $total++;
37 $sum += $answer->value;
38 }
39 if ($total > 0) {
40 $a_results->setMean($sum / $total);
41 }
42 }

References $total.

◆ supportsSumScore()

SurveyMatrixQuestionEvaluation::supportsSumScore ( )
protected

Reimplemented from SurveyQuestionEvaluation.

Definition at line 431 of file class.SurveyMatrixQuestionEvaluation.php.

431 : bool
432 {
433 return true;
434 }

The documentation for this class was generated from the following file: