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