ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSurveyResultsCumulatedTableGUI.php
Go to the documentation of this file.
1 <?php
2 
23 {
24  public function __construct(
25  object $a_parent_obj,
26  string $a_parent_cmd,
27  array $a_results
28  ) {
29  global $DIC;
30 
31  $lng = $DIC->language();
32  $ilCtrl = $DIC->ctrl();
33 
34  $this->setId("svy_cum");
35  parent::__construct($a_parent_obj, $a_parent_cmd);
36 
37  $this->lng = $lng;
38  $this->ctrl = $ilCtrl;
39 
40  $this->addColumn($this->lng->txt("title"));
41  foreach ($this->getSelectedColumns() as $c) {
42  if (strcmp($c, 'question') === 0) {
43  $this->addColumn($this->lng->txt("question"));
44  }
45  if (strcmp($c, 'question_type') === 0) {
46  $this->addColumn($this->lng->txt("question_type"));
47  }
48  if (strcmp($c, 'users_answered') === 0) {
49  $this->addColumn($this->lng->txt("users_answered"));
50  }
51  if (strcmp($c, 'users_skipped') === 0) {
52  $this->addColumn($this->lng->txt("users_skipped"));
53  }
54  if (strcmp($c, 'mode') === 0) {
55  $this->addColumn($this->lng->txt("mode"));
56  }
57  if (strcmp($c, 'mode_nr_of_selections') === 0) {
58  $this->addColumn($this->lng->txt("mode_nr_of_selections"));
59  }
60  if (strcmp($c, 'median') === 0) {
61  $this->addColumn($this->lng->txt("median"));
62  }
63  if (strcmp($c, 'arithmetic_mean') === 0) {
64  $this->addColumn($this->lng->txt("arithmetic_mean"));
65  }
66  }
67 
68  $this->setRowTemplate(
69  "tpl.il_svy_svy_results_cumulated_row.html",
70  "Modules/Survey/Evaluation"
71  );
72  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
73  $this->setShowRowsSelector(false);
74 
75  $this->getItems($a_results);
76  }
77 
78  public function getSelectableColumns(): array
79  {
80  $lng = $this->lng;
81  $cols["question"] = array(
82  "txt" => $lng->txt("question"),
83  "default" => true
84  );
85  $cols["question_type"] = array(
86  "txt" => $lng->txt("question_type"),
87  "default" => true
88  );
89  $cols["users_answered"] = array(
90  "txt" => $lng->txt("users_answered"),
91  "default" => true
92  );
93  $cols["users_skipped"] = array(
94  "txt" => $lng->txt("users_skipped"),
95  "default" => true
96  );
97  $cols["mode"] = array(
98  "txt" => $lng->txt("mode"),
99  "default" => false
100  );
101  $cols["mode_nr_of_selections"] = array(
102  "txt" => $lng->txt("mode_nr_of_selections"),
103  "default" => false
104  );
105  $cols["median"] = array(
106  "txt" => $lng->txt("median"),
107  "default" => true
108  );
109  $cols["arithmetic_mean"] = array(
110  "txt" => $lng->txt("arithmetic_mean"),
111  "default" => true
112  );
113  return $cols;
114  }
115 
116  protected function getItems(
117  array $a_results
118  ): void {
119  $data = array();
120 
121  foreach ($a_results as $question_res) {
122  if (!is_array($question_res)) {
123  $question = $question_res->getQuestion();
124 
125  $data[] = array(
126  "title" => $question->getTitle(),
127  "question" => strip_tags($question->getQuestiontext()),
128  "question_type" => SurveyQuestion::_getQuestionTypeName($question->getQuestionType()),
129  "users_answered" => $question_res->getUsersAnswered(),
130  "users_skipped" => $question_res->getUsersSkipped(),
131  "mode" => $question_res->getModeValueAsText(),
132  "mode_nr_of_selections" => $question_res->getModeNrOfSelections(),
133  "median" => $question_res->getMedianAsText(),
134  "arithmetic_mean" => $question_res->getMean()
135  );
136  }
137  // matrix
138  else {
139  // :TODO: $question->getQuestiontext() ?
140  // :TODO: should there be overall figures?
141 
142  foreach ($question_res as $idx => $item) {
143  $row_title = $item[0];
144  $row_res = $item[1];
145  $question = $row_res->getQuestion();
146 
147  $data[] = array(
148  "title" => $question->getTitle(),
149  "question" => $row_title,
150  "question_type" => SurveyQuestion::_getQuestionTypeName($question->getQuestionType()),
151  "users_answered" => $row_res->getUsersAnswered(),
152  "users_skipped" => $row_res->getUsersSkipped(),
153  "mode" => $row_res->getModeValueAsText(),
154  "mode_nr_of_selections" => $row_res->getModeNrOfSelections(),
155  "median" => $row_res->getMedianAsText(),
156  "arithmetic_mean" => $row_res->getMean()
157  );
158  }
159  }
160  }
161 
162  $this->setData($data);
163  }
164 
165  public function numericOrdering(string $a_field): bool
166  {
167  return !in_array($a_field, array("question", "question_type"));
168  }
169 
170  protected function fillRow(array $a_set): void
171  {
172  $this->tpl->setVariable("TITLE", $a_set['title']);
173 
174  foreach ($this->getSelectedColumns() as $c) {
175  if (strcmp($c, 'question') === 0) {
176  $this->tpl->setCurrentBlock('question');
177  $this->tpl->setVariable("QUESTION", $a_set['question']);
178  $this->tpl->parseCurrentBlock();
179  }
180  if (strcmp($c, 'question_type') === 0) {
181  $this->tpl->setCurrentBlock('question_type');
182  $this->tpl->setVariable("QUESTION_TYPE", trim($a_set['question_type']));
183  $this->tpl->parseCurrentBlock();
184  }
185  if (strcmp($c, 'users_answered') === 0) {
186  $this->tpl->setCurrentBlock('users_answered');
187  $this->tpl->setVariable("USERS_ANSWERED", trim($a_set['users_answered']));
188  $this->tpl->parseCurrentBlock();
189  }
190  if (strcmp($c, 'users_skipped') === 0) {
191  $this->tpl->setCurrentBlock('users_skipped');
192  $this->tpl->setVariable("USERS_SKIPPED", trim($a_set['users_skipped']));
193  $this->tpl->parseCurrentBlock();
194  }
195  if (strcmp($c, 'mode') === 0) {
196  $this->tpl->setCurrentBlock('mode');
197  $this->tpl->setVariable("MODE", trim($a_set['mode']));
198  // : $this->lng->txt("survey_not_available")
199  $this->tpl->parseCurrentBlock();
200  }
201  if (strcmp($c, 'mode_nr_of_selections') === 0) {
202  $this->tpl->setCurrentBlock('mode_nr_of_selections');
203  $this->tpl->setVariable("MODE_NR_OF_SELECTIONS", trim($a_set['mode_nr_of_selections']));
204  // : $this->lng->txt("survey_not_available")
205  $this->tpl->parseCurrentBlock();
206  }
207  if (strcmp($c, 'median') === 0) {
208  $this->tpl->setCurrentBlock('median');
209  $this->tpl->setVariable("MEDIAN", trim($a_set['median']));
210  // : $this->lng->txt("survey_not_available")
211  $this->tpl->parseCurrentBlock();
212  }
213  if (strcmp($c, 'arithmetic_mean') === 0) {
214  $this->tpl->setCurrentBlock('arithmetic_mean');
215  $this->tpl->setVariable("ARITHMETIC_MEAN", trim($a_set['arithmetic_mean']));
216  // : $this->lng->txt("survey_not_available");
217  $this->tpl->parseCurrentBlock();
218  }
219  }
220  }
221 }
setData(array $a_data)
$c
Definition: cli.php:38
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setFormAction(string $a_form_action, bool $a_multipart=false)
static _getQuestionTypeName(string $type_tag)
Return the translation for a given question type.
ilLanguage $lng
setId(string $a_val)
global $DIC
Definition: feed.php:28
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
__construct(object $a_parent_obj, string $a_parent_cmd, array $a_results)
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
$cols
Definition: xhr_table.php:11