ILIAS  release_7 Revision v7.30-3-g800a261c036
SurveyMatrixQuestionEvaluation Class Reference

Survey matrix evaluation. More...

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

Public Member Functions

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

Protected Member Functions

 supportsSumScore ()
 @inheritDoc More...
 
 isSumScoreValid (int $nr_answer_records)
 @inheritDoc More...
 
- Protected Member Functions inherited from SurveyQuestionEvaluation
 isSumScoreValid (int $nr_answer_records)
 Is sum score ok (question needs to be fully answered) More...
 
 supportsSumScore ()
 Supports sum score? More...
 
 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
 $lng
 
 $db
 
 $question
 
 $finished_ids
 
 $chart_width = 400
 
 $chart_height = 300
 

Detailed Description

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 10 of file class.SurveyMatrixQuestionEvaluation.php.

Member Function Documentation

◆ addUserSpecificResults()

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

Reimplemented from SurveyQuestionEvaluation.

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

318 {
319 $answer_map = array();
320 foreach ($a_results as $row_results) {
321 $row_title = $row_results[0];
322 $row_result = $row_results[1];
323
324 $answers = $row_result->getUserResults($a_user_id);
325 if ($answers !== null) {
326 foreach ($answers as $answer) {
327 // mc
328 if ($this->question->getSubtype() == 1) {
329 $answer_map[$row_title . "|" . $answer[2]] = $answer[2];
330 } else {
331 $answer_map[$row_title] = $answer[3];
332 $answer_map[$row_title . "|scale"] = $answer[2]; // see #20646
333 }
334 if ($answer[1]) {
335 $answer_map[$row_title . "|txt"] = $answer[1];
336 }
337 }
338 }
339 }
340
341 if (!sizeof($answer_map)) {
342 $a_row[] = $this->getSkippedValue();
343 } else {
344 $a_row[] = "";
345 }
346
347 for ($i = 0; $i < $this->question->getRowCount(); $i++) {
348 $row = $this->question->getRow($i);
349 $row_title = $row->title;
350
351 $a_row[] = $answer_map[$row_title];
352 if ($this->question->getSubtype() == 0) {
353 $a_row[] = $answer_map[$row_title . "|scale"]; // see #20646
354 }
355
356 if ($row->other) {
357 $a_row[] = $answer_map[$row_title . "|txt"];
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 $a_row[] = $answer_map[$row_title . "|" . $col->scale];
365 }
366 }
367 }
368 }
getSkippedValue()
Get caption for skipped value.
$index
Definition: metadata.php:128
$i
Definition: metadata.php:24

References $i, $index, and SurveyQuestionEvaluation\getSkippedValue().

+ Here is the call graph for this function:

◆ exportResults()

SurveyMatrixQuestionEvaluation::exportResults (   $a_results,
  $a_do_title,
  $a_do_label 
)

Reimplemented from SurveyQuestionEvaluation.

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

193 {
194 $question = $a_results[0][1]->getQuestion();
195
196 $rows = array();
197 $row = array();
198
199 if ($a_do_title) {
200 $row[] = $question->getTitle();
201 }
202 if ($a_do_label) {
203 $row[] = $question->label;
204 }
205
206 $row[] = $question->getQuestiontext();
207 $row[] = SurveyQuestion::_getQuestionTypeName($question->getQuestionType());
208
209 $row[] = (int) $a_results[0][1]->getUsersAnswered();
210 $row[] = (int) $a_results[0][1]->getUsersSkipped();
211 $row[] = null;
212 $row[] = null;
213 $row[] = null;
214 $row[] = null;
215 $row[] = null;
216
217 $rows[] = $row;
218
219 foreach ($a_results as $row_result) {
220 $row_title = $row_result[0];
221 $row_res = $row_result[1];
222
223 $row = array();
224
225 if ($a_do_title) {
226 $row[] = null;
227 }
228 if ($a_do_label) {
229 $row[] = null;
230 }
231
232 $row[] = $row_title;
233 $row[] = null;
234
235 $row[] = null;
236 $row[] = null;
237
238 // :TODO:
239 $row[] = is_array($row_res->getModeValue())
240 ? implode(", ", $row_res->getModeValue())
241 : $row_res->getModeValue();
242
243 $row[] = $row_res->getModeValueAsText();
244 $row[] = (int) $row_res->getModeNrOfSelections();
245
246 // :TODO:
247 $row[] = $row_res->getMedianAsText();
248
249 $row[] = $row_res->getMean();
250
251 $rows[] = $row;
252 }
253 return $rows;
254 }
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
$rows
Definition: xhr_table.php:10

References SurveyQuestionEvaluation\$question, $rows, and SurveyQuestion\_getQuestionTypeName().

+ Here is the call graph for this function:

◆ getChart()

SurveyMatrixQuestionEvaluation::getChart (   $a_results)

Get chart.

Parameters
ilSurveyEvaluationResults | array$a_results
Returns
array

Reimplemented from SurveyQuestionEvaluation.

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

113 {
115
116 $chart = ilChart::getInstanceByType(ilChart::TYPE_GRID, $a_results[0][1]->getQuestion()->getId());
117 $chart->setXAxisToInteger(true);
118 $chart->setStacked(true);
119
120 $colors = $this->getChartColors();
121 $chart->setColors($colors);
122
123 // :TODO:
124 //$chart->setsize($this->chart_width, $this->chart_height);
125
126 $data = $labels = $legend = array();
127
128 $row_idx = sizeof($a_results);
129
130 $row_counter = 0;
131 $text_shortened = false;
132 foreach ($a_results as $row) {
133 $row_idx--;
134
135 $row_title = $row[0];
136 $row_results = $row[1];
137
138 #20363
139 $row_title = ++$row_counter . ". " . $row_title;
140 $labels[$row_idx] = ilUtil::shortenText($row_title, 50, true);
141 if ($labels[$row_idx] != $row_title) {
142 $text_shortened = true;
143 }
144 //$labels[$row_idx] = wordwrap(ilUtil::shortenText($row_title, 50, true), 30, "<br />");
145
146 $vars = $row_results->getVariables();
147 if ($vars) {
148 foreach ($vars as $idx => $var) {
149 if (!array_key_exists($idx, $data)) {
150 $data[$idx] = $chart->getDataInstance(ilChartGrid::DATA_BARS);
151 $data[$idx]->setLabel($var->cat->title);
152 $data[$idx]->setBarOptions(0.5, "center", true);
153 $data[$idx]->setFill(1);
154
155 $legend[] = array(
156 $var->cat->title,
157 $colors[$idx]
158 );
159 }
160
161 $data[$idx]->addPoint($var->abs, $row_idx);
162 }
163 }
164 }
165
166 //Chart height depending on the number of questions. Not fixed anymore.
167 $this->chart_height = count($a_results) * 40;
168 //Chart width 500px if one or + question string are longer than 60 char. Otherwise the default width still aplied.
169 if ($text_shortened) {
170 $this->chart_width = 500;
171 }
172 $chart->setSize($this->chart_width, $this->chart_height);
173
174 foreach ($data as $var) {
175 $chart->addData($var);
176 }
177
178 $chart->setTicks(false, $labels, true);
179
180 return array(
181 $chart->getHTML(),
182 $legend
183 );
184 }
static getInstanceByType($a_type, $a_id)
Get type instance.
const TYPE_GRID
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
$data
Definition: storeScorm.php:23

References $data, SurveyQuestionEvaluation\$lng, ilChartGrid\DATA_BARS, SurveyQuestionEvaluation\getChartColors(), ilChart\getInstanceByType(), ilUtil\shortenText(), and ilChart\TYPE_GRID.

+ Here is the call graph for this function:

◆ getGrid()

SurveyMatrixQuestionEvaluation::getGrid (   $a_results,
  $a_abs = true,
  $a_perc = true 
)

Get grid data.

Parameters
ilSurveyEvaluationResults | array$a_results
bool$a_abs
bool$a_perc
Returns
array

Reimplemented from SurveyQuestionEvaluation.

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

48 {
50
51 $res = array(
52 "cols" => array(),
53 "rows" => array()
54 );
55
56 $tmp = $a_results;
57 $tmp = array_shift($tmp);
58 $vars = $tmp[1]->getVariables();
59 if ($vars) {
60 foreach ($vars as $var) {
61 $res["cols"][] = $var->cat->title;
62 }
63 }
64 $q_counter = 0;
65 foreach ($a_results as $results_row) {
66 #20363
67 $parsed_row = array(
68 ++$q_counter . ". " . $results_row[0]
69 );
70
71 $vars = $results_row[1]->getVariables();
72 if ($vars) {
73 foreach ($vars as $var) {
74 $perc = $var->perc
75 ? sprintf("%.2f", $var->perc * 100) . "%"
76 : "0%";
77
78 if ((bool) $a_abs && (bool) $a_perc) {
79 $parsed_row[] = $var->abs . " / " . $perc;
80 } elseif ((bool) $a_abs) {
81 $parsed_row[] = $var->abs;
82 } else {
83 $parsed_row[] = $perc;
84 }
85 }
86 }
87
88 $res["rows"][] = $parsed_row;
89 }
90 return $res;
91 }
foreach($_POST as $key=> $value) $res

References SurveyQuestionEvaluation\$lng, and $res.

◆ getResults()

SurveyMatrixQuestionEvaluation::getResults ( )

Get results.

Returns
ilSurveyEvaluationResults|array

Reimplemented from SurveyQuestionEvaluation.

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

17 {
18 $results = array();
19
20 $answers = $this->getAnswerData();
21
22 // parse rows
23 for ($r = 0; $r < $this->question->getRowCount(); $r++) {
24 $row_results = new ilSurveyEvaluationResults($this->question);
25
26 $this->parseResults(
27 $row_results,
28 (array) $answers[$r],
29 $this->question->getColumns()
30 );
31
32 $results[] = array(
33 $this->question->getRow($r)->title,
34 $row_results
35 );
36 }
37
38 return $results;
39 }
parseResults(ilSurveyEvaluationResults $a_results, array $a_answers, SurveyCategories $a_categories=null)
Parse answer data into results instance.
$results

References $results, SurveyQuestionEvaluation\getAnswerData(), and SurveyQuestionEvaluation\parseResults().

+ Here is the call graph for this function:

◆ getTextAnswers()

SurveyMatrixQuestionEvaluation::getTextAnswers (   $a_results)

Get text answers.

Parameters
ilSurveyEvaluationResults | array$a_results
Returns
array

Reimplemented from SurveyQuestionEvaluation.

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

94 {
95 $res = array();
96
97 foreach ($a_results as $results_row) {
98 $texts = $results_row[1]->getMappedTextAnswers();
99 if ($texts) {
100 $idx = $results_row[0];
101 foreach ($texts as $answers) {
102 foreach ($answers as $answer) {
103 $res[$idx][] = $answer;
104 }
105 }
106 }
107 }
108
109 return $res;
110 }

References $res.

◆ getUserSpecificVariableTitles()

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

Get title columns for user-specific export.

Parameters
array$a_title_row
array$a_title_row2
bool$a_do_title
bool$a_do_label

Reimplemented from SurveyQuestionEvaluation.

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

257 {
259
260 for ($i = 0; $i < $this->question->getRowCount(); $i++) {
261 // create row title according label, add 'other column'
262 $row = $this->question->getRow($i);
263
264 if ($a_do_title && $a_do_label) {
265 $a_title_row[] = $row->title;
266 $a_title_row2[] = $row->label;
267
268 if ($this->question->getSubtype() == 0) {
269 $a_title_row[] = $row->title; // see #20646
270 $a_title_row2[] = $row->label; // see #20646
271 }
272
273 if ($row->other) {
274 $a_title_row[] = $row->title;
275 $a_title_row2[] = $lng->txt('other');
276 }
277 } elseif ($a_do_title) {
278 $a_title_row[] = $row->title;
279 $a_title_row2[] = "";
280
281 if ($this->question->getSubtype() == 0) {
282 $a_title_row[] = $row->title; // see #20646
283 $a_title_row2[] = ""; // see #20646
284 }
285
286 if ($row->other) {
287 $a_title_row[] = $row->title;
288 $a_title_row2[] = $lng->txt('other');
289 }
290 } else {
291 $a_title_row[] = $row->label;
292 $a_title_row2[] = "";
293
294 if ($this->question->getSubtype() == 0) {
295 $a_title_row[] = $row->label; // see #20646
296 $a_title_row2[] = ""; // see #20646
297 }
298
299 if ($row->other) {
300 $a_title_row[] = $row->label;
301 $a_title_row2[] = $lng->txt('other');
302 }
303 }
304
305 // mc
306 if ($this->question->getSubtype() == 1) {
307 for ($index = 0; $index < $this->question->getColumnCount(); $index++) {
308 $col = $this->question->getColumn($index);
309
310 $a_title_row[] = $col->title . " [" . $col->scale . "]";
311 $a_title_row2[] = "";
312 }
313 }
314 }
315 }

References $i, $index, and SurveyQuestionEvaluation\$lng.

◆ isSumScoreValid()

SurveyMatrixQuestionEvaluation::isSumScoreValid ( int  $nr_answer_records)
protected

@inheritDoc

Reimplemented from SurveyQuestionEvaluation.

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

381 : bool
382 {
383 if ($nr_answer_records == $this->question->getRowCount()) {
384 return true;
385 }
386 return false;
387 }

◆ supportsSumScore()

SurveyMatrixQuestionEvaluation::supportsSumScore ( )
protected

@inheritDoc

Reimplemented from SurveyQuestionEvaluation.

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

373 : bool
374 {
375 return true;
376 }

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