ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestPassOverviewTableGUI.php
Go to the documentation of this file.
1 <?php
2 
23 {
24  protected bool $resultPresentationEnabled = false;
25 
26  protected bool $pdfPresentationEnabled = false;
27 
28  protected bool $objectiveOrientedPresentationEnabled = false;
29 
30  protected ?int $activeId = null;
31 
32  protected string $passDetailsCommand = '';
33 
34  protected string $passDeletionCommand = '';
35 
36  public function __construct($parent, $cmd)
37  {
38  $this->setId('tst_pass_overview_' . $parent->getObject()->getId());
39  $this->setDefaultOrderField('pass');
40  $this->setDefaultOrderDirection('ASC');
41 
42  parent::__construct($parent, $cmd);
43 
44  // Don't set any limit because of print/pdf views. Furthermore, this view is part of different summary views, and no cmd ist passed to he calling method.
45  $this->setLimit(PHP_INT_MAX);
46  $this->disable('sort');
47 
48  $this->setRowTemplate('tpl.il_as_tst_pass_overview_row.html', 'Modules/Test');
49  }
50 
51  public function init(): void
52  {
53  global $DIC;
54  $ilCtrl = $DIC['ilCtrl'];
55 
56  $ilCtrl->setParameter($this->parent_obj, 'active_id', $this->getActiveId());
57 
58  $this->initColumns();
59 
60  if ($this->isPdfPresentationEnabled()) {
61  $this->disable('linkbar');
62  $this->disable('numinfo');
63  $this->disable('numinfo_header');
64  $this->disable('hits');
65  }
66  }
67 
68  public function numericOrdering(string $a_field): bool
69  {
70  switch ($a_field) {
71  case 'pass':
72  case 'date':
73  case 'percentage':
74  return true;
75  }
76 
77  return false;
78  }
79 
80  public function fillRow(array $a_set): void
81  {
82  if (array_key_exists('percentage', $a_set)) {
83  $a_set['percentage'] = sprintf('%.2f', $a_set['percentage']) . '%';
84  }
85 
86  // fill columns
87 
89  if ($this->isResultPresentationEnabled()) {
90  $this->tpl->setVariable('VAL_SCORED', $a_set['scored'] ? '&otimes;' : '');
91  }
92 
93  $this->tpl->setVariable('VAL_PASS', $this->getPassNumberPresentation($a_set['pass']));
94  }
95 
96  $this->tpl->setVariable('VAL_DATE', $this->formatDate($a_set['date']));
97 
99  $this->tpl->setVariable('VAL_LO_OBJECTIVES', $a_set['objectives']);
100 
101  $this->tpl->setVariable('VAL_LO_TRY', sprintf(
102  $this->lng->txt('tst_res_lo_try_n'),
103  $this->getPassNumberPresentation($a_set['pass'])
104  ));
105  }
106 
107  if ($this->isResultPresentationEnabled()) {
108  $this->tpl->setVariable('VAL_ANSWERED', $this->buildWorkedThroughQuestionsString(
109  $a_set['num_workedthrough_questions'],
110  $a_set['num_questions_total']
111  ));
112 
113  if ($this->getParentObject()->object->isOfferingQuestionHintsEnabled()) {
114  $this->tpl->setVariable('VAL_HINTS', $a_set['hints']);
115  }
116 
117  $this->tpl->setVariable('VAL_REACHED', $this->buildReachedPointsString(
118  $a_set['reached_points'],
119  $a_set['max_points']
120  ));
121 
122  $this->tpl->setVariable('VAL_PERCENTAGE', $a_set['percentage']);
123  }
124 
125  if (!$this->isPdfPresentationEnabled()) {
126  $actions = $this->getRequiredActions($a_set['scored']);
127  $this->tpl->setVariable('VAL_ACTIONS', $this->buildActionsHtml($actions, $a_set['pass']));
128  }
129  }
130 
131  protected function initColumns(): void
132  {
134  $this->addColumn($this->lng->txt('scored_pass'), '', '150');
135  }
136 
138  $this->addColumn($this->lng->txt('pass'), '', '1%');
139  }
140 
141  $this->addColumn($this->lng->txt('date'));
142 
144  $this->addColumn($this->lng->txt('tst_res_lo_objectives_header'), '');
145  $this->addColumn($this->lng->txt('tst_res_lo_try_header'), '');
146  }
147 
148  if ($this->isResultPresentationEnabled()) {
149  $this->addColumn($this->lng->txt('tst_answered_questions'));
150  if ($this->getParentObject()->object->isOfferingQuestionHintsEnabled()) {
151  $this->addColumn($this->lng->txt('tst_question_hints_requested_hint_count_header'));
152  }
153  $this->addColumn($this->lng->txt('tst_reached_points'));
154  $this->addColumn($this->lng->txt('tst_percent_solved'));
155  }
156 
157  // actions
158  if (!$this->isPdfPresentationEnabled()) {
159  $this->addColumn($this->lng->txt('actions'), '', '10%');
160  }
161  }
162 
163  public function isResultPresentationEnabled(): bool
164  {
166  }
167 
168  public function setResultPresentationEnabled(bool $resultPresentationEnabled): void
169  {
170  $this->resultPresentationEnabled = $resultPresentationEnabled;
171  }
172 
173  public function isPdfPresentationEnabled(): bool
174  {
176  }
177 
178  public function setPdfPresentationEnabled(bool $pdfPresentationEnabled): void
179  {
180  $this->pdfPresentationEnabled = $pdfPresentationEnabled;
181  }
182 
184  {
186  }
187 
188  public function setObjectiveOrientedPresentationEnabled(bool $objectiveOrientedPresentationEnabled): void
189  {
190  $this->objectiveOrientedPresentationEnabled = $objectiveOrientedPresentationEnabled;
191  }
192 
193  public function getActiveId(): ?int
194  {
195  return $this->activeId;
196  }
197 
198  public function setActiveId($activeId): void
199  {
200  $this->activeId = (int) $activeId;
201  }
202 
203  public function getPassDetailsCommand(): string
204  {
206  }
207 
208  public function setPassDetailsCommand(string $passDetailsCommand): void
209  {
210  $this->passDetailsCommand = $passDetailsCommand;
211  }
212 
213  public function getPassDeletionCommand(): string
214  {
216  }
217 
218  public function setPassDeletionCommand(string $passDeletionCommand): void
219  {
220  $this->passDeletionCommand = $passDeletionCommand;
221  }
222 
223  private function formatDate($date): string
224  {
229  return $date;
230  }
231 
232  private function buildWorkedThroughQuestionsString($numQuestionsWorkedThrough, $numQuestionsTotal): string
233  {
234  return "{$numQuestionsWorkedThrough} {$this->lng->txt('of')} {$numQuestionsTotal}";
235  }
236 
237  private function buildReachedPointsString($reachedPoints, $maxPoints): string
238  {
239  return "{$reachedPoints} {$this->lng->txt('of')} {$maxPoints}";
240  }
241 
242  private function getRequiredActions(?bool $isScoredPass): array
243  {
244  $actions = array();
245 
246  if ($this->getPassDetailsCommand()) {
247  $actions[$this->getPassDetailsCommand()] = $this->lng->txt('tst_pass_details');
248  }
249 
250  if (!is_null($isScoredPass) && !$isScoredPass && $this->getPassDeletionCommand()) {
251  $actions[$this->getPassDeletionCommand()] = $this->lng->txt('delete');
252  }
253 
254  return $actions;
255  }
256 
257  private function buildActionsHtml($actions, $pass): string
258  {
259  global $DIC;
260  $ilCtrl = $DIC['ilCtrl'];
261 
262  if (!count($actions)) {
263  return '';
264  }
265 
266  $ilCtrl->setParameter($this->parent_obj, 'pass', $pass);
267 
268  if (count($actions) > 1) {
269  $aslgui = new ilAdvancedSelectionListGUI();
270  $aslgui->setListTitle($this->lng->txt('actions'));
271  $aslgui->setId($pass);
272 
273  foreach ($actions as $cmd => $label) {
274  $aslgui->addItem($label, $cmd, $ilCtrl->getLinkTarget($this->parent_obj, $cmd));
275  }
276 
277  $html = $aslgui->getHTML();
278  } else {
279  $cmd = key($actions);
280  $label = current($actions);
281 
282  $href = $ilCtrl->getLinkTarget($this->parent_obj, $cmd);
283  $html = '<a href="' . $href . '">' . $label . '</a>';
284  }
285 
286  $ilCtrl->setParameter($this->parent_obj, 'pass', '');
287 
288  return $html;
289  }
290 
291  protected function getPassNumberPresentation($pass): int
292  {
293  return $pass + 1;
294  }
295 }
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
buildReachedPointsString($reachedPoints, $maxPoints)
setId(string $a_val)
global $DIC
Definition: feed.php:28
setDefaultOrderField(string $a_defaultorderfield)
setPdfPresentationEnabled(bool $pdfPresentationEnabled)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
setPassDetailsCommand(string $passDetailsCommand)
setResultPresentationEnabled(bool $resultPresentationEnabled)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setObjectiveOrientedPresentationEnabled(bool $objectiveOrientedPresentationEnabled)
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
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)
disable(string $a_module_name)
static setUseRelativeDates(bool $a_status)
set use relative dates
buildWorkedThroughQuestionsString($numQuestionsWorkedThrough, $numQuestionsTotal)
setPassDeletionCommand(string $passDeletionCommand)