ILIAS  release_8 Revision v8.24
class.ilParticipantsTestResultsTableGUI.php
Go to the documentation of this file.
1<?php
2
20
30{
31 private UIServices $ui;
32
33 protected bool $accessResultsCommandsEnabled = false;
34 protected bool $manageResultsCommandsEnabled = false;
35
36 protected $anonymity;
37
38 public function __construct($a_parent_obj, $a_parent_cmd)
39 {
40 $this->setId('tst_participants_' . $a_parent_obj->getTestObj()->getRefId());
41 parent::__construct($a_parent_obj, $a_parent_cmd);
42
43 global $DIC;
44 $this->ui = $DIC->ui();
45
46 $this->setStyle('table', 'fullwidth');
47
48 $this->setFormName('partResultsForm');
49 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
50
51 $this->setRowTemplate("tpl.il_as_tst_scorings_row.html", "Modules/Test");
52
53 $this->enable('header');
54 $this->enable('sort');
55
56 $this->setSelectAllCheckbox('chbUser');
57
58 $this->setDefaultOrderField('name');
59 $this->setDefaultOrderDirection('asc');
60 }
61
62 public function isAccessResultsCommandsEnabled(): bool
63 {
65 }
66
68 {
69 $this->accessResultsCommandsEnabled = $accessResultsCommandsEnabled;
70 }
71
72 public function isManageResultsCommandsEnabled(): bool
73 {
75 }
76
78 {
79 $this->manageResultsCommandsEnabled = $manageResultsCommandsEnabled;
80 }
81
82 public function getAnonymity()
83 {
84 return $this->anonymity;
85 }
86
87 public function setAnonymity($anonymity)
88 {
89 $this->anonymity = $anonymity;
90 }
91
92 public function numericOrdering(string $a_field): bool
93 {
94 return in_array($a_field, array(
95 'scored_pass', 'answered_questions', 'points', 'percent_result'
96 ));
97 }
98
99 public function init(): void
100 {
101 if ($this->isMultiRowSelectionRequired()) {
102 $this->setShowRowsSelector(true);
103 }
104
105 $this->initColumns();
106 $this->initCommands();
107 $this->initFilter();
108 }
109
110 public function initColumns(): void
111 {
112 if ($this->isMultiRowSelectionRequired()) {
113 $this->addColumn('', '', '1%', true);
114 }
115
116 $this->addColumn($this->lng->txt("name"), 'name');
117 $this->addColumn($this->lng->txt("login"), 'login');
118
119 $this->addColumn($this->lng->txt("tst_tbl_col_scored_pass"), 'scored_pass');
120 $this->addColumn($this->lng->txt("tst_tbl_col_pass_finished"), 'scored_pass_finished_timestamp');
121
122 $this->addColumn($this->lng->txt("tst_tbl_col_answered_questions"), 'answered_questions');
123 $this->addColumn($this->lng->txt("tst_tbl_col_reached_points"), 'reached_points');
124 $this->addColumn($this->lng->txt("tst_tbl_col_percent_result"), 'percent_result');
125
126 $this->addColumn($this->lng->txt("tst_tbl_col_passed_status"), 'passed_status');
127 $this->addColumn($this->lng->txt("tst_tbl_col_final_mark"), 'final_mark');
128
129 if ($this->isActionsColumnRequired()) {
130 $this->addColumn($this->lng->txt('actions'), '', '');
131 }
132 }
133
134 public function initCommands(): void
135 {
136 if ($this->isAccessResultsCommandsEnabled() && !$this->getAnonymity()) {
137 $this->addMultiCommand('showPassOverview', $this->lng->txt('show_pass_overview'));
138 $this->addMultiCommand('showUserAnswers', $this->lng->txt('show_user_answers'));
139 $this->addMultiCommand('showDetailedResults', $this->lng->txt('show_detailed_results'));
140 }
141
142 if ($this->isManageResultsCommandsEnabled()) {
143 $this->addMultiCommand('deleteSingleUserResults', $this->lng->txt('delete_user_data'));
144 }
145 }
146
147 public function fillRow(array $a_set): void
148 {
149 if ($this->isMultiRowSelectionRequired()) {
150 $this->tpl->setCurrentBlock('checkbox_column');
151 $this->tpl->setVariable("CHB_ROW_KEY", $a_set['active_id']);
152 $this->tpl->parseCurrentBlock();
153 }
154
155 if ($this->isActionsColumnRequired()) {
156 $this->tpl->setCurrentBlock('actions_column');
157 $this->tpl->setVariable('ACTIONS', $this->buildActionsMenu($a_set)->getHTML());
158 $this->tpl->parseCurrentBlock();
159 }
160
161 $this->tpl->setVariable("ROW_KEY", $a_set['active_id']);
162 $this->tpl->setVariable("LOGIN", $a_set['login']);
163 $this->tpl->setVariable("FULLNAME", $a_set['name']);
164
165 $this->tpl->setVariable("SCORED_PASS", $this->buildScoredPassString($a_set));
166 $this->tpl->setVariable("SCORED_PASS_FINISHED", $this->buildScoredPassFinishedString($a_set));
167
168 $this->tpl->setVariable("ANSWERED_QUESTIONS", $this->buildAnsweredQuestionsString($a_set));
169 $this->tpl->setVariable("REACHED_POINTS", $this->buildReachedPointsString($a_set));
170 $this->tpl->setVariable("PERCENT_RESULT", $this->buildPercentResultString($a_set));
171
172 $this->tpl->setVariable("PASSED_STATUS", $this->buildPassedStatusString($a_set));
173 $this->tpl->setVariable("FINAL_MARK", $a_set['final_mark']);
174 }
175
177 {
178 $asl = new ilAdvancedSelectionListGUI();
179
180 $this->ctrl->setParameterByClass('iltestevaluationgui', 'active_id', $data['active_id']);
181
182 if ($this->isAccessResultsCommandsEnabled()) {
183 $resultsHref = $this->ctrl->getLinkTargetByClass([ilTestResultsGUI::class, ilParticipantsTestResultsGUI::class, ilTestEvaluationGUI::class], 'outParticipantsResultsOverview');
184 $asl->addItem($this->lng->txt('tst_show_results'), $resultsHref, $resultsHref);
185 }
186
187 return $asl;
188 }
189
190 protected function isActionsColumnRequired(): bool
191 {
192 if ($this->isAccessResultsCommandsEnabled()) {
193 return true;
194 }
195
196 return false;
197 }
198
199 protected function isMultiRowSelectionRequired(): bool
200 {
201 if ($this->isAccessResultsCommandsEnabled() && !$this->getAnonymity()) {
202 return true;
203 }
204
205 if ($this->isManageResultsCommandsEnabled()) {
206 return true;
207 }
208
209 return false;
210 }
211
212 protected function buildPassedStatusString(array $data): string
213 {
214 if ($data['passed_status']) {
215 return $this->buildPassedIcon() . ' ' . $this->lng->txt('tst_passed');
216 }
217
218 return $this->buildFailedIcon() . ' ' . $this->lng->txt('tst_failed');
219 }
220
221 protected function buildPassedIcon(): string
222 {
223 return $this->buildImageIcon(ilUtil::getImagePath("icon_ok.svg"), $this->lng->txt("passed"));
224 }
225
226 protected function buildFailedIcon(): string
227 {
228 return $this->buildImageIcon(ilUtil::getImagePath("icon_not_ok.svg"), $this->lng->txt("failed"));
229 }
230
231 protected function buildImageIcon(string $icon_name, string $label): string
232 {
233 $icon = $this->ui->factory()->symbol()->icon()->custom(
234 $icon_name,
235 $label
236 );
237 return $this->ui->renderer()->render($icon);
238 }
239
240 protected function buildFormattedAccessDate(array $data): string
241 {
243 }
244
245 protected function buildScoredPassString(array $data): string
246 {
247 return $this->lng->txt('pass') . ' ' . ($data['scored_pass'] + 1);
248 }
249
250 protected function buildScoredPassFinishedString(array $data): string
251 {
252 if (isset($data['scored_pass_finished_timestamp'])) {
253 return ilDatePresentation::formatDate(new ilDateTime($data['scored_pass_finished_timestamp'], IL_CAL_UNIX));
254 }
255 return '';
256 }
257
258 protected function buildAnsweredQuestionsString(array $data): string
259 {
260 return sprintf(
261 $this->lng->txt('tst_answered_questions_of_total'),
262 $data['answered_questions'],
263 $data['total_questions']
264 );
265 }
266
267 protected function buildReachedPointsString(array $data): string
268 {
269 return sprintf(
270 $this->lng->txt('tst_reached_points_of_max'),
271 $data['reached_points'],
272 $data['max_points']
273 );
274 }
275
276 protected function buildPercentResultString(array $data): string
277 {
278 return sprintf('%0.2f %%', $data['percent_result'] * 100);
279 }
280}
Provides fluid interface to RBAC services.
Definition: UIServices.php:24
const IL_CAL_UNIX
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
numericOrdering(string $a_field)
Should this field be sorted numeric?
setAccessResultsCommandsEnabled(bool $accessResultsCommandsEnabled)
setManageResultsCommandsEnabled(bool $manageResultsCommandsEnabled)
fillRow(array $a_set)
Standard Version of Fill Row.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
getHTML()
Get HTML.
setFormName(string $a_name="")
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
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)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
enable(string $a_module_name)
setStyle(string $a_element, string $a_style)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc