ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilEvaluationAllTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 {
32  public function __construct(
34  string $parent_cmd,
35  private ilSetting $settings,
36  private bool $anonymity = false,
37  private bool $offeringQuestionHintsEnabled = false
38  ) {
39  $this->setId('tst_eval_all');
40 
41  parent::__construct($parent_obj, $parent_cmd);
42 
43  $this->setFormName('evaluation_all');
44  $this->setStyle('table', 'fullwidth');
45  $this->addColumn($this->lng->txt("name"), "name", "");
46  $this->addColumn($this->lng->txt("login"), "login", "");
47 
48  if (!$this->anonymity) {
49  foreach ($this->getSelectedColumns() as $c) {
50  if (strcmp($c, 'email') == 0) {
51  $this->addColumn($this->lng->txt("email"), 'email', '');
52  }
53  if (strcmp($c, 'exam_id') == 0 && $this->parent_obj->getObject()->isShowExamIdInTestResultsEnabled()) {
54  $this->addColumn($this->lng->txt("exam_id_label"), 'exam_id', '');
55  }
56  if (strcmp($c, 'institution') == 0) {
57  $this->addColumn($this->lng->txt("institution"), 'institution', '');
58  }
59  if (strcmp($c, 'street') == 0) {
60  $this->addColumn($this->lng->txt("street"), 'street', '');
61  }
62  if (strcmp($c, 'city') == 0) {
63  $this->addColumn($this->lng->txt("city"), 'city', '');
64  }
65  if (strcmp($c, 'zipcode') == 0) {
66  $this->addColumn($this->lng->txt("zipcode"), 'zipcode', '');
67  }
68 
69  if ($this->isFieldEnabledEnoughByAdministration('country') && $c == 'country') {
70  $this->addColumn($this->lng->txt("country"), 'country', '');
71  }
72 
73  if ($this->isFieldEnabledEnoughByAdministration('sel_country') && $c == 'sel_country') {
74  $this->addColumn($this->lng->txt("country"), 'sel_country', '');
75  }
76 
77  if (strcmp($c, 'department') == 0) {
78  $this->addColumn($this->lng->txt("department"), 'department', '');
79  }
80  if (strcmp($c, 'matriculation') == 0) {
81  $this->addColumn($this->lng->txt("matriculation"), 'matriculation', '');
82  }
83  }
84  }
85 
86  $this->addColumn($this->lng->txt("tst_reached_points"), "reached", "");
87 
88  if ($this->offeringQuestionHintsEnabled) {
89  $this->addColumn($this->lng->txt("tst_question_hints_requested_hint_count_header"), "hint_count", "");
90  }
91 
92  $this->addColumn($this->lng->txt("tst_mark"), "mark", "");
93 
94  $this->addColumn($this->lng->txt("tst_answered_questions"), "answered", "");
95  $this->addColumn($this->lng->txt("working_time"), "working_time", "");
96  $this->addColumn($this->lng->txt("detailed_evaluation"), "", "");
97 
98  $this->setFormAction($this->ctrl->getFormAction($parent_obj, $parent_cmd));
99  $this->setRowTemplate("tpl.table_evaluation_all.html", "Modules/Test");
100  $this->setDefaultOrderField("name");
101  $this->setDefaultOrderDirection("asc");
102  $this->enable('sort');
103  $this->enable('header');
104 
105  $this->setFilterCommand('filterEvaluation');
106  $this->setResetCommand('resetfilterEvaluation');
107  $this->initFilter();
108 
109  if ($this->isFieldEnabledEnoughByAdministration('sel_country')) {
110  $this->lng->loadLanguageModule('meta');
111  }
112  }
113 
118  public function numericOrdering(string $a_field): bool
119  {
120  switch ($a_field) {
121  case 'name':
122  if ($this->anonymity) {
123  return true;
124  } else {
125  return false;
126  }
127  break;
128  case 'reached':
129  case 'hint_count':
130  case 'exam_id':
131  case 'answered':
132  return true;
133  break;
134  default:
135  return false;
136  break;
137  }
138  }
139 
140  public function getSelectableColumns(): array
141  {
142  $cols = [];
143  if (!$this->anonymity) {
144  $cols["email"] = array(
145  "txt" => $this->lng->txt("email"),
146  "default" => false
147  );
148  $cols["institution"] = array(
149  "txt" => $this->lng->txt("institution"),
150  "default" => false
151  );
152  $cols["street"] = array(
153  "txt" => $this->lng->txt("street"),
154  "default" => false
155  );
156  $cols["city"] = array(
157  "txt" => $this->lng->txt("city"),
158  "default" => false
159  );
160  $cols["zipcode"] = array(
161  "txt" => $this->lng->txt("zipcode"),
162  "default" => false
163  );
164  if ($this->isFieldEnabledEnoughByAdministration('country')) {
165  $cols["country"] = array(
166  "txt" => $this->lng->txt("country"),
167  "default" => false
168  );
169  }
170  if ($this->isFieldEnabledEnoughByAdministration('sel_country')) {
171  $cols["sel_country"] = array(
172  "txt" => $this->lng->txt("country"),
173  "default" => false
174  );
175  }
176  $cols["department"] = array(
177  "txt" => $this->lng->txt("department"),
178  "default" => false
179  );
180  $cols["matriculation"] = array(
181  "txt" => $this->lng->txt("matriculation"),
182  "default" => false
183  );
184  if ($this->parent_obj->getObject()->isShowExamIdInTestResultsEnabled()) {
185  $cols["exam_id"] = array(
186  "txt" => $this->lng->txt("exam_id_label"),
187  "default" => false
188  );
189  }
190  }
191  return $cols;
192  }
193 
197  public function initFilter(): void
198  {
199  $ti = new ilTextInputGUI($this->lng->txt("name"), "name");
200  $ti->setMaxLength(64);
201  $ti->setValidationRegexp('/^[^%]*$/is');
202  $ti->setSize(20);
203  $this->addFilterItem($ti);
204  $ti->readFromSession();
205 
206  // group
207  $ti = new ilTextInputGUI($this->lng->txt("grp"), "group");
208  $ti->setMaxLength(64);
209  $ti->setValidationRegexp('/^[^%]*$/is');
210  $ti->setSize(20);
211  $this->addFilterItem($ti);
212  $ti->readFromSession();
213 
214  // course
215  $ti = new ilTextInputGUI($this->lng->txt("course"), "course");
216  $ti->setMaxLength(64);
217  $ti->setSize(20);
218  $ti->setValidationRegexp('/^[^%]*$/is');
219  $this->addFilterItem($ti);
220  $ti->readFromSession();
221 
222  $si = new ilCheckboxInputGUI($this->lng->txt("passed_only"), "passed_only");
223  $this->addFilterItem($si);
224  $si->readFromSession();
225  }
226 
231  protected function fillRow(array $a_set): void
232  {
233  $this->tpl->setVariable("NAME", $a_set['name']);
234  $this->tpl->setVariable("LOGIN", $a_set['login']);
235  foreach ($this->getSelectedColumns() as $c) {
236  if (!$this->anonymity) {
237  if (strcmp($c, 'email') == 0) {
238  $this->tpl->setCurrentBlock('email');
239  $this->tpl->setVariable("EMAIL", strlen($a_set['email']) ? $a_set['email'] : '&nbsp;');
240  $this->tpl->parseCurrentBlock();
241  }
242  if (strcmp($c, 'institution') == 0) {
243  $this->tpl->setCurrentBlock('institution');
244  $this->tpl->setVariable("INSTITUTION", strlen($a_set['institution']) ? $a_set['institution'] : '&nbsp;');
245  $this->tpl->parseCurrentBlock();
246  }
247  if (strcmp($c, 'street') == 0) {
248  $this->tpl->setCurrentBlock('street');
249  $this->tpl->setVariable("STREET", strlen($a_set['street']) ? $a_set['street'] : '&nbsp;');
250  $this->tpl->parseCurrentBlock();
251  }
252  if (strcmp($c, 'city') == 0) {
253  $this->tpl->setCurrentBlock('city');
254  $this->tpl->setVariable("CITY", strlen($a_set['city']) ? $a_set['city'] : '&nbsp;');
255  $this->tpl->parseCurrentBlock();
256  }
257  if (strcmp($c, 'zipcode') == 0) {
258  $this->tpl->setCurrentBlock('zipcode');
259  $this->tpl->setVariable("ZIPCODE", strlen($a_set['zipcode']) ? $a_set['zipcode'] : '&nbsp;');
260  $this->tpl->parseCurrentBlock();
261  }
262  if ($this->isFieldEnabledEnoughByAdministration('country') && $c == 'country') {
263  $this->tpl->setCurrentBlock('country');
264  $this->tpl->setVariable("COUNTRY", strlen($a_set['country']) ? $a_set['country'] : '&nbsp;');
265  $this->tpl->parseCurrentBlock();
266  }
267  if ($this->isFieldEnabledEnoughByAdministration('sel_country') && $c == 'sel_country') {
268  $this->tpl->setCurrentBlock('country');
269  $this->tpl->setVariable("COUNTRY", strlen($a_set['sel_country']) ? $this->getCountryTranslation($a_set['sel_country']) : '&nbsp;');
270  $this->tpl->parseCurrentBlock();
271  }
272  if (strcmp($c, 'department') == 0) {
273  $this->tpl->setCurrentBlock('department');
274  $this->tpl->setVariable("DEPARTMENT", strlen($a_set['department']) ? $a_set['department'] : '&nbsp;');
275  $this->tpl->parseCurrentBlock();
276  }
277  if (strcmp($c, 'matriculation') == 0) {
278  $this->tpl->setCurrentBlock('matriculation');
279  $this->tpl->setVariable("MATRICULATION", strlen($a_set['matriculation']) ? $a_set['matriculation'] : '&nbsp;');
280  $this->tpl->parseCurrentBlock();
281  }
282  if (strcmp($c, 'exam_id') == 0 && $this->parent_obj->getObject()->isShowExamIdInTestResultsEnabled()) {
283  $this->tpl->setCurrentBlock('exam_id');
284  $examId = is_string($a_set['exam_id']) && strlen($a_set['exam_id']) ? $a_set['exam_id'] : '&nbsp;';
285  $this->tpl->setVariable('EXAM_ID', $examId);
286  $this->tpl->parseCurrentBlock();
287  }
288  }
289  }
290  $reachedPercent = !$a_set['max'] ? 0 : $a_set['reached'] / $a_set['max'] * 100;
291  $reached = $a_set['reached'] . " " . strtolower($this->lng->txt("of")) . " " . $a_set['max'] . " (" . sprintf("%2.2f", $reachedPercent) . " %)";
292  $this->tpl->setVariable("REACHED", $reached);
293 
294  if ($this->offeringQuestionHintsEnabled) {
295  $this->tpl->setVariable("HINT_COUNT", $a_set['hint_count']);
296  }
297 
298  $a_set['answered'] = $a_set['questions_worked_through'] . " " . strtolower($this->lng->txt("of")) . " " . $a_set['number_of_questions'] . " (" . sprintf("%2.2f", $a_set['answered']) . " %" . ")";
299 
300  $this->tpl->setVariable("MARK", $a_set['mark']);
301  $this->tpl->setVariable("ANSWERED", $a_set['answered']);
302  $this->tpl->setVariable("WORKING_TIME", $a_set['working_time']);
303  $this->tpl->setVariable("DETAILED", $a_set['details']);
304  }
305 
306  public function getSelectedColumns(): array
307  {
308  $scol = parent::getSelectedColumns();
309 
310  $cols = $this->getSelectableColumns();
311  if (!is_array($cols)) {
312  $cols = array();
313  }
314 
315  $fields_to_unset = array_diff(array_keys($scol), array_keys($cols));
316 
317  foreach ($fields_to_unset as $key) {
318  unset($scol[$key]);
319  }
320 
321  return $scol;
322  }
323 
324  protected function getCountryTranslation($countryCode)
325  {
326  return $this->lng->txt('meta_c_' . $countryCode);
327  }
328 
329  protected function isFieldEnabledEnoughByAdministration($fieldIdentifier): bool
330  {
331  if ($this->settings->get("usr_settings_hide_" . $fieldIdentifier)) { // visible
332  return false;
333  }
334 
335  if (!$this->settings->get('usr_settings_visib_reg_' . $fieldIdentifier)) { // visib_reg
336  return false;
337  }
338 
339  if (!$this->settings->get('usr_settings_visib_lua_' . $fieldIdentifier)) { // visib_lua
340  return false;
341  }
342 
343  if ($this->settings->get("usr_settings_disable_" . $fieldIdentifier)) { // changeable
344  return false;
345  }
346 
347  if (!$this->settings->get('usr_settings_changeable_lua_' . $fieldIdentifier)) { // changeable_lua
348  return false;
349  }
350 
351  return true;
352  }
353 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
enable(string $a_module_name)
Class ilObjTestGUI.
setFormAction(string $a_form_action, bool $a_multipart=false)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setResetCommand(string $a_val, string $a_caption="")
TableGUI class for evaluation of all users.
setFormName(string $a_name="")
setId(string $a_val)
setStyle(string $a_element, string $a_style)
__construct(VocabulariesInterface $vocabularies)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setFilterCommand(string $a_val, string $a_caption="")
isFieldEnabledEnoughByAdministration($fieldIdentifier)
string $key
Consumer key/client ID value.
Definition: System.php:193
Output class for assessment test evaluation.
setDefaultOrderDirection(string $a_defaultorderdirection)
fillRow(array $a_set)
Standard Version of Fill Row.
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)
__construct(ilObjTestGUI|ilTestEvaluationGUI $parent_obj, string $parent_cmd, private ilSetting $settings, private bool $anonymity=false, private bool $offeringQuestionHintsEnabled=false)
numericOrdering(string $a_field)
Should this field be sorted numeric?