ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SurveyMatrixQuestionEvaluation Class Reference

Survey matrix evaluation. More...

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

Public Member Functions

 getResults ()
 
 getGrid ($a_results, $a_abs=true, $a_perc=true)
 
 getTextAnswers ($a_results)
 
 getChart ($a_results)
 
 exportResults ($a_results, $a_do_title, $a_do_label)
 
 getUserSpecificVariableTitles (array &$a_title_row, array &$a_title_row2, $a_do_title, $a_do_label)
 
 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...
 
 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)
 

Additional Inherited Members

- Protected Member Functions inherited from SurveyQuestionEvaluation
 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 ()
 
- 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 12 of file class.SurveyMatrixQuestionEvaluation.php.

Member Function Documentation

◆ addUserSpecificResults()

SurveyMatrixQuestionEvaluation::addUserSpecificResults ( array $a_row,
  $a_user_id,
  $a_results 
)

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

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

321  {
322  $answer_map = array();
323  foreach ($a_results as $row_results) {
324  $row_title = $row_results[0];
325  $row_result = $row_results[1];
326 
327  $answers = $row_result->getUserResults($a_user_id);
328  if ($answers !== null) {
329  foreach ($answers as $answer) {
330  // mc
331  if ($this->question->getSubtype() == 1) {
332  $answer_map[$row_title . "|" . $answer[2]] = $answer[2];
333  } else {
334  $answer_map[$row_title] = $answer[3];
335  $answer_map[$row_title . "|scale"] = $answer[2]; // see #20646
336  }
337  if ($answer[1]) {
338  $answer_map[$row_title . "|txt"] = $answer[1];
339  }
340  }
341  }
342  }
343 
344  if (!sizeof($answer_map)) {
345  $a_row[] = $this->getSkippedValue();
346  } else {
347  $a_row[] = "";
348  }
349 
350  for ($i = 0; $i < $this->question->getRowCount(); $i++) {
351  $row = $this->question->getRow($i);
352  $row_title = $row->title;
353 
354  $a_row[] = $answer_map[$row_title];
355  if ($this->question->getSubtype() == 0) {
356  $a_row[] = $answer_map[$row_title . "|scale"]; // see #20646
357  }
358 
359  if ($row->other) {
360  $a_row[] = $answer_map[$row_title . "|txt"];
361  }
362 
363  // mc
364  if ($this->question->getSubtype() == 1) {
365  for ($index = 0; $index < $this->question->getColumnCount(); $index++) {
366  $col = $this->question->getColumn($index);
367  $a_row[] = $answer_map[$row_title . "|" . $col->scale];
368  }
369  }
370  }
371  }
$index
Definition: metadata.php:60
Create styles array
The data for the language used.
getSkippedValue()
Get caption for skipped value.
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:

◆ exportResults()

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

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

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

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

◆ getChart()

SurveyMatrixQuestionEvaluation::getChart (   $a_results)

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

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

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

◆ getGrid()

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

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

References SurveyQuestionEvaluation\$lng, $res, and array.

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

◆ getResults()

SurveyMatrixQuestionEvaluation::getResults ( )

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

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

19  {
20  $results = array();
21 
22  $answers = $this->getAnswerData();
23 
24  // parse rows
25  for ($r = 0; $r < $this->question->getRowCount(); $r++) {
26  $row_results = new ilSurveyEvaluationResults($this->question);
27 
28  $this->parseResults(
29  $row_results,
30  (array) $answers[$r],
31  $this->question->getColumns()
32  );
33 
34  $results[] = array(
35  $this->question->getRow($r)->title,
36  $row_results
37  );
38  }
39 
40  return $results;
41  }
$r
Definition: example_031.php:79
Create styles array
The data for the language used.
parseResults(ilSurveyEvaluationResults $a_results, array $a_answers, SurveyCategories $a_categories=null)
Parse answer data into results instance.
$results
Definition: svg-scanner.php:47
+ Here is the call graph for this function:

◆ getTextAnswers()

SurveyMatrixQuestionEvaluation::getTextAnswers (   $a_results)

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

References $res, and array.

96  {
97  $res = array();
98 
99  foreach ($a_results as $results_row) {
100  $texts = $results_row[1]->getMappedTextAnswers();
101  if ($texts) {
102  $idx = $results_row[0];
103  foreach ($texts as $answers) {
104  foreach ($answers as $answer) {
105  $res[$idx][] = $answer;
106  }
107  }
108  }
109  }
110 
111  return $res;
112  }
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.

◆ getUserSpecificVariableTitles()

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

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

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

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

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