ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilTestPassOverviewTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
28 {
31  protected bool $resultPresentationEnabled = false;
32 
33  protected bool $pdfPresentationEnabled = false;
34 
35  protected bool $objectiveOrientedPresentationEnabled = false;
36 
37  protected ?int $activeId = null;
38 
39  protected string $passDetailsCommand = '';
40 
41  protected string $passDeletionCommand = '';
42 
43  public function __construct(ilTestEvaluationGUI $parent, string $cmd)
44  {
45  $this->setId('tst_pass_overview_' . $parent->getObject()->getId());
46  $this->setDefaultOrderField('pass');
47  $this->setDefaultOrderDirection('ASC');
48 
49  parent::__construct($parent, $cmd);
50 
51  // 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.
52  $this->setLimit(PHP_INT_MAX);
53  $this->disable('sort');
54 
55  global $DIC;
56  $this->ui_factory = $DIC->ui()->factory();
57  $this->ui_renderer = $DIC->ui()->renderer();
58 
59  $this->setRowTemplate('tpl.il_as_tst_pass_overview_row.html', 'components/ILIAS/Test');
60  }
61 
62  public function init(): void
63  {
64  $this->ctrl->setParameter($this->parent_obj, 'active_id', $this->getActiveId());
65 
66  $this->initColumns();
67 
68  if ($this->isPdfPresentationEnabled()) {
69  $this->disable('linkbar');
70  $this->disable('numinfo');
71  $this->disable('numinfo_header');
72  $this->disable('hits');
73  }
74  }
75 
76  public function numericOrdering(string $a_field): bool
77  {
78  switch ($a_field) {
79  case 'pass':
80  case 'date':
81  case 'percentage':
82  return true;
83  }
84 
85  return false;
86  }
87 
88  public function fillRow(array $a_set): void
89  {
90  if (array_key_exists('percentage', $a_set)) {
91  $a_set['percentage'] = sprintf('%.2f', $a_set['percentage']) . '%';
92  }
93 
94  // fill columns
95 
97  if ($this->isResultPresentationEnabled()) {
98  $this->tpl->setVariable('VAL_SCORED', $a_set['scored'] ? '&otimes;' : '');
99  }
100 
101  $this->tpl->setVariable('VAL_PASS', $this->getPassNumberPresentation($a_set['pass']));
102  }
103 
104  $this->tpl->setVariable('VAL_DATE', $this->formatDate($a_set['date']));
105 
107  $this->tpl->setVariable('VAL_LO_OBJECTIVES', $a_set['objectives']);
108 
109  $this->tpl->setVariable('VAL_LO_TRY', sprintf(
110  $this->lng->txt('tst_res_lo_try_n'),
111  $this->getPassNumberPresentation($a_set['pass'])
112  ));
113  }
114 
115  if ($this->isResultPresentationEnabled()) {
116  $this->tpl->setVariable('VAL_ANSWERED', $this->buildWorkedThroughQuestionsString(
117  $a_set['num_workedthrough_questions'],
118  $a_set['num_questions_total']
119  ));
120  $this->tpl->setVariable('VAL_REACHED', $this->buildReachedPointsString(
121  $a_set['reached_points'],
122  $a_set['max_points']
123  ));
124 
125  $this->tpl->setVariable('VAL_PERCENTAGE', $a_set['percentage']);
126  }
127 
128  if (!$this->isPdfPresentationEnabled()) {
129  $actions = $this->getRequiredActions($a_set['scored']);
130  $this->tpl->setVariable('VAL_ACTIONS', $this->buildActionsHtml($actions, $a_set['pass']));
131  }
132  }
133 
134  protected function initColumns(): void
135  {
137  $this->addColumn($this->lng->txt('scored_pass'), '', '150');
138  }
139 
141  $this->addColumn($this->lng->txt('pass'), '', '1%');
142  }
143 
144  $this->addColumn($this->lng->txt('date'));
145 
147  $this->addColumn($this->lng->txt('tst_res_lo_objectives_header'), '');
148  $this->addColumn($this->lng->txt('tst_res_lo_try_header'), '');
149  }
150 
151  if ($this->isResultPresentationEnabled()) {
152  $this->addColumn($this->lng->txt('tst_answered_questions'));
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 = [];
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  if (!count($actions)) {
260  return '';
261  }
262 
263  $this->ctrl->setParameter($this->parent_obj, 'pass', $pass);
264  $action_links = [];
265  if (count($actions) > 1) {
266  foreach ($actions as $cmd => $label) {
267  $action_links[] = $this->ui_factory->link()->standard($label, $this->ctrl->getLinkTarget($this->parent_obj, $cmd));
268  }
269  $dropdown = $this->ui_factory->dropdown()->standard($action_links)->withLabel($this->lng->txt('actions'));
270  $html = $this->ui_renderer->render($dropdown);
271  } else {
272  $cmd = key($actions);
273  $label = current($actions);
274 
275  $href = $this->ctrl->getLinkTarget($this->parent_obj, $cmd);
276  $html = '<a href="' . $href . '">' . $label . '</a>';
277  }
278 
279  $this->ctrl->setParameter($this->parent_obj, 'pass', '');
280 
281  return $html;
282  }
283 
284  protected function getPassNumberPresentation($pass): int
285  {
286  return $pass + 1;
287  }
288 }
static array static setUseRelativeDates(bool $a_status)
set use relative dates
const IL_CAL_UNIX
buildReachedPointsString($reachedPoints, $maxPoints)
setId(string $a_val)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setDefaultOrderField(string $a_defaultorderfield)
setPdfPresentationEnabled(bool $pdfPresentationEnabled)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
global $DIC
Definition: shib_login.php:26
Output class for assessment test evaluation.
setDefaultOrderDirection(string $a_defaultorderdirection)
setPassDetailsCommand(string $passDetailsCommand)
setResultPresentationEnabled(bool $resultPresentationEnabled)
Class ilTestPassOverviewTableGUI.
__construct(ilTestEvaluationGUI $parent, string $cmd)
setObjectiveOrientedPresentationEnabled(bool $objectiveOrientedPresentationEnabled)
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
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)
buildWorkedThroughQuestionsString($numQuestionsWorkedThrough, $numQuestionsTotal)
setPassDeletionCommand(string $passDeletionCommand)