ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestParticipantsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
33 {
34  protected bool $manageResultsCommandsEnabled = false;
35  protected bool $manageInviteesCommandsEnabled = false;
36 
37  protected ?string $rowKeyDataField;
38 
39  protected bool $anonymity;
40  protected array $filter;
41 
42  protected bool $participantHasSolutionsFilterEnabled = false;
43 
44  public function __construct(
46  string $parent_cmd,
47  protected UIFactory $ui_factory,
48  protected UIRenderer $ui_renderer
49  ) {
50  $this->setId('tst_participants_' . $parent_obj->getTestObj()->getRefId());
51 
52  parent::__construct($parent_obj, $parent_cmd);
53 
54  $this->setStyle('table', 'fullwidth');
55 
56  $this->setFormName('participantsForm');
57  $this->setFormAction($this->ctrl->getFormAction($parent_obj, $parent_cmd));
58 
59  $this->setRowTemplate("tpl.il_as_tst_participants_row.html", "Modules/Test");
60 
61  $this->enable('header');
62  $this->enable('sort');
63 
64  $this->setShowRowsSelector(true);
65  }
66 
67  public function isManageResultsCommandsEnabled(): bool
68  {
70  }
71 
72  public function setManageResultsCommandsEnabled(bool $manageResultsCommandsEnabled): void
73  {
74  $this->manageResultsCommandsEnabled = $manageResultsCommandsEnabled;
75  }
76 
77  public function isManageInviteesCommandsEnabled(): bool
78  {
80  }
81 
82  public function setManageInviteesCommandsEnabled(bool $manageInviteesCommandsEnabled): void
83  {
84  $this->manageInviteesCommandsEnabled = $manageInviteesCommandsEnabled;
85 
86  if ($manageInviteesCommandsEnabled) {
87  $this->setSelectAllCheckbox('chbUser');
88  } else {
89  $this->setSelectAllCheckbox('');
90  }
91  }
92 
93  public function getRowKeyDataField(): string
94  {
96  }
97 
98  public function setRowKeyDataField(string $rowKeyDataField): void
99  {
100  $this->rowKeyDataField = $rowKeyDataField;
101  }
102 
103  public function getAnonymity()
104  {
105  return $this->anonymity;
106  }
107 
108  public function setAnonymity($anonymity): void
109  {
110  $this->anonymity = $anonymity;
111  }
112 
114  {
116  }
117 
118 
119  public function setParticipantHasSolutionsFilterEnabled(bool $participantHasSolutionsFilterEnabled): void
120  {
121  $this->participantHasSolutionsFilterEnabled = $participantHasSolutionsFilterEnabled;
122  }
123 
124  public function numericOrdering(string $a_field): bool
125  {
126  return in_array($a_field, array(
127  'access', 'tries'
128  ));
129  }
130 
131  protected function needsCheckboxColumn(): bool
132  {
133  return $this->isManageInviteesCommandsEnabled();
134  }
135 
136  public function initColumns(): void
137  {
138  if ($this->needsCheckboxColumn()) {
139  $this->addColumn('', '', '1%');
140  }
141 
142  $this->addColumn($this->lng->txt("name"), 'name', '');
143  $this->addColumn($this->lng->txt("login"), 'login', '');
144 
145  if ($this->isManageInviteesCommandsEnabled()) {
146  $this->addColumn($this->lng->txt("clientip"), 'clientip', '');
147  }
148 
149  $this->addColumn($this->lng->txt("tst_started"), 'started', '');
150  $this->addColumn($this->lng->txt("tst_nr_of_tries_of_user"), 'tries', '');
151 
152  $this->addColumn($this->lng->txt("unfinished_passes"), 'unfinished', '');
153  $this->addColumn($this->lng->txt("tst_finished"), 'finished', '');
154 
155  $this->addColumn($this->lng->txt("last_access"), 'access', '');
156 
157  if ($this->isActionsColumnRequired()) {
158  $this->addColumn('', '', '');
159  }
160  }
161 
162  public function initCommands(): void
163  {
164  if ($this->isManageInviteesCommandsEnabled()) {
165  $this->addMultiCommand('saveClientIp', $this->lng->txt('save'));
166  $this->addMultiCommand('removeParticipants', $this->lng->txt('remove_as_participant'));
167  }
168  }
169 
170  public function initFilter(): void
171  {
173  $ti = new ilSelectInputGUI($this->lng->txt("selection"), "selection");
174  $ti->setOptions(
175  array(
176  'all' => $this->lng->txt('all_participants'),
177  'withSolutions' => $this->lng->txt('with_solutions_participants'),
178  'withoutSolutions' => $this->lng->txt('without_solutions_participants')
179  )
180  );
181  $this->addFilterItem($ti);
182  $ti->readFromSession(); // get currenty value from session (always after addFilterItem())
183  $this->filter['title'] = $ti->getValue();
184  }
185  }
186 
187  public function fillRow(array $a_set): void
188  {
189  if ($this->needsCheckboxColumn()) {
190  $this->tpl->setCurrentBlock('checkbox_column');
191  $this->tpl->setVariable("CHB_ROW_KEY", $this->fetchRowKey($a_set));
192  $this->tpl->parseCurrentBlock();
193  }
194 
195  if ($this->isManageInviteesCommandsEnabled()) {
196  $this->tpl->setCurrentBlock('client_ip_column');
197  $this->tpl->setVariable("CLIENT_IP", $a_set['clientip']);
198  $this->tpl->setVariable("CIP_ROW_KEY", $this->fetchRowKey($a_set));
199  $this->tpl->parseCurrentBlock();
200  }
201 
202  if ($this->isActionsColumnRequired()) {
203  $this->tpl->setCurrentBlock('actions_column');
204 
205  if ($a_set['active_id'] > 0) {
206  $this->tpl->setVariable('ACTIONS', $this->buildActionsMenu($a_set));
207  } else {
208  $this->tpl->touchBlock('actions_column');
209  }
210 
211  $this->tpl->parseCurrentBlock();
212  }
213 
214  $this->tpl->setVariable("ROW_KEY", $this->fetchRowKey($a_set));
215  $this->tpl->setVariable("LOGIN", $a_set['login']);
216  $this->tpl->setVariable("FULLNAME", $a_set['name']);
217 
218  $this->tpl->setVariable("STARTED", ($a_set['started']) ? $this->buildOkIcon() : '');
219  $this->tpl->setVariable("TRIES", $this->fetchTriesValue($a_set));
220  $this->tpl->setVariable("UNFINISHED_PASSES", $this->buildUnfinishedPassesStatusString($a_set));
221 
222  $this->tpl->setVariable("FINISHED", ($a_set['finished']) ? $this->buildOkIcon() : '');
223  $this->tpl->setVariable("ACCESS", $this->buildFormattedAccessDate($a_set));
224  }
225 
226  protected function buildActionsMenu(array $data): string
227  {
228  $this->ctrl->setParameterByClass('iltestevaluationgui', 'active_id', $data['active_id']);
229  $actions = [];
230  if ($this->isManageResultsCommandsEnabled() && $data['unfinished']) {
231  $finishHref = $this->ctrl->getLinkTargetByClass('ilTestEvaluationGUI', 'finishTestPassForSingleUser');
232  $actions[] = $this->ui_factory->link()->standard($this->lng->txt('finish_test'), $finishHref);
233  }
234  $dropdown = $this->ui_factory->dropdown()->standard($actions);
235  return $this->ui_renderer->render($dropdown);
236  }
237 
238  protected function isActionsColumnRequired(): bool
239  {
240  if ($this->isManageResultsCommandsEnabled()) {
241  return true;
242  }
243 
244  return false;
245  }
246 
247  protected function fetchRowKey(array $data): string
248  {
249  return (string) $data[$this->getRowKeyDataField()];
250  }
251 
252  protected function fetchTriesValue(array $data): string
253  {
254  if ($data['tries'] < 1) {
255  return '';
256  }
257 
258  if ($data['tries'] > 1) {
259  return sprintf($this->lng->txt("passes_finished"), $data['tries']);
260  }
261 
262  return sprintf($this->lng->txt("pass_finished"), $data['tries']);
263  }
264 
265  protected function buildUnfinishedPassesStatusString(array $data): string
266  {
267  if ($data['unfinished']) {
268  return $this->lng->txt('yes');
269  }
270 
271  return $this->lng->txt('no');
272  }
273 
274  protected function buildOkIcon(): string
275  {
276  return $this->ui_renderer->render($this->ui_factory->symbol()->icon()->custom(
277  ilUtil::getImagePath("standard/icon_ok.svg"),
278  $this->lng->txt("ok")
279  ));
280  }
281 
282  protected function buildFormattedAccessDate(array $data): string
283  {
284  return ilDatePresentation::formatDate(new ilDateTime($data['access'], IL_CAL_DATETIME));
285  }
286 }
enable(string $a_module_name)
const IL_CAL_DATETIME
This class represents a selection list property in a property form.
setFormAction(string $a_form_action, bool $a_multipart=false)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
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)
setOptions(array $a_options)
setManageResultsCommandsEnabled(bool $manageResultsCommandsEnabled)
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)
setParticipantHasSolutionsFilterEnabled(bool $participantHasSolutionsFilterEnabled)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setManageInviteesCommandsEnabled(bool $manageInviteesCommandsEnabled)
__construct(ilTestParticipantsGUI $parent_obj, string $parent_cmd, protected UIFactory $ui_factory, protected 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)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
addMultiCommand(string $a_cmd, string $a_text)