ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
QuestionsOfAttemptTable.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
34 
36 {
37  public function __construct(
38  protected readonly \ilLanguage $lng,
39  protected readonly \ilCtrlInterface $ctrl,
40  protected readonly UIFactory $ui_factory,
41  protected readonly DataFactory $data_factory,
42  protected readonly GlobalHttpState $http,
43  protected readonly \ilTestPlayerAbstractGUI $parent_gui,
44  protected readonly \ilObjTest $test,
45  protected readonly array $data
46  ) {
47  }
48 
49  public function getRows(
50  DataRowBuilder $row_builder,
51  array $visible_column_ids,
52  Range $range,
53  Order $order,
54  ?array $filter_data,
55  ?array $additional_parameters
56  ): \Generator {
57  foreach ($this->getData($range, $order) as $question) {
58  $title = $this->ui_factory->link()->standard($question['title'], $this->createShowQuestionLink($question['sequence']));
59  $record = [
60  'order' => (int) $question['order'],
61  'title' => $title->withDisabled($question['disabled']),
62  'description' => $question['description'],
63  'points' => $question['points'],
64  'postponed' => (bool) $question['postponed'],
65  'answered' => (bool) $question['isAnswered'],
66  'marked' => (bool) $question['marked'],
67  ];
68  yield $row_builder->buildDataRow((string) $question['order'], $record);
69  }
70  }
71 
72  public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
73  {
74  //ignore filter bc table is not filterable
75  return count($this->data);
76  }
77 
81  public function buildComponents(
82  bool $is_start_page
83  ): array {
84  $components = [
85  $this->ui_factory->button()->standard(
86  $is_start_page ? $this->lng->txt('goto_first_question') : $this->lng->txt('tst_resume_test'),
87  $this->ctrl->getLinkTarget($this->parent_gui, ilTestPlayerCommands::SHOW_QUESTION)
88  )
89  ];
90 
91  $button_text = $this->lng->txt('finish_test');
92  // Examview enabled & !reviewed & requires_confirmation? test_submission_overview (review gui)
93  if ($this->parent_gui->getObject()->getMainSettings()->getFinishingSettings()->getShowAnswerOverview()) {
94  $components[] = $this->ui_factory->button()->standard(
95  $button_text,
96  $this->ctrl->getLinkTargetByClass(ilTestSubmissionReviewGUI::class, 'show')
97  );
98  } else {
99  $finish_test_modal = $this->parent_gui->buildFinishTestModal();
100  $components[] = $this->ui_factory->button()->standard($button_text, '')
101  ->withOnClick($finish_test_modal->getShowSignal());
102  $components[] = $finish_test_modal;
103  }
104 
105  $components[] = $this->ui_factory->table()->data(
106  $this,
107  $this->lng->txt('question_summary'),
108  $this->getColumns(),
109  )
110  ->withRequest($this->http->request())
111  ->withId('listofquestions');
112 
113  return $components;
114  }
115 
116  protected function getData(Range $range, Order $order): array
117  {
118  // ignore order bc table is not sortable
119  return array_slice($this->data, $range->getStart(), $range->getLength());
120  }
121 
122  protected function createShowQuestionLink(int $sequence): string
123  {
124  $this->ctrl->setParameter($this->parent_gui, 'sequence', $sequence);
125  $this->ctrl->setParameter($this->parent_gui, 'pmode', '');
126  return $this->ctrl->getLinkTarget($this->parent_gui, ilTestPlayerCommands::SHOW_QUESTION);
127  }
128 
132  protected function getColumns(): array
133  {
134  $column_factory = $this->ui_factory->table()->column();
135  $icon_factory = $this->ui_factory->symbol()->icon();
136  $icon_checked = $icon_factory->custom('assets/images/standard/icon_checked.svg', $this->lng->txt('yes'));
137  $icon_unchecked = $icon_factory->custom('assets/images/standard/icon_unchecked.svg', $this->lng->txt('no'));
138  $icon_marked = $icon_factory->custom('assets/images/object/marked.svg', $this->lng->txt('tst_question_marked'));
139 
140  $columns = [
141  'order' => $column_factory->number($this->lng->txt('tst_qst_order')),
142  'title' => $column_factory->link($this->lng->txt('tst_question')),
143  'description' => $column_factory->text($this->lng->txt('description')),
144  'postponed' => $column_factory->boolean(ucfirst($this->lng->txt('postponed')), $this->lng->txt('yes'), ''),
145  'points' => $column_factory->number($this->lng->txt('tst_maximum_points'))->withUnit($this->lng->txt('points_short')),
146  'answered' => $column_factory->boolean($this->lng->txt('answered'), $icon_checked, $icon_unchecked),
147  'marked' => $column_factory->boolean($this->lng->txt('tst_question_marker'), $icon_marked, ''),
148  ];
149 
150  $optional_columns = [
151  'description' => $this->isShowDescriptionEnabled(),
152  'postponed' => $this->isPostponingEnabled(),
153  'points' => $this->isShowPointsEnabled(),
154  'marked' => $this->isShowMarkerEnabled(),
155  ];
156 
157  $list = [];
158  foreach ($columns as $key => $column) {
159  if (isset($optional_columns[$key]) && !$optional_columns[$key]) {
160  continue;
161  }
162  $list[$key] = $column->withIsOptional(false, true)->withIsSortable(false);
163  }
164  return $list;
165  }
166 
167  protected function isShowDescriptionEnabled(): bool
168  {
169  return $this->test->getListOfQuestionsDescription();
170  }
171 
172  protected function isPostponingEnabled(): bool
173  {
174  return $this->test->isPostponingEnabled();
175  }
176 
177  protected function isShowPointsEnabled(): bool
178  {
179  return !$this->test->getTitleOutput();
180  }
181 
182  protected function isShowMarkerEnabled(): bool
183  {
184  return $this->test->getShowMarker();
185  }
186 
187 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(protected readonly \ilLanguage $lng, protected readonly \ilCtrlInterface $ctrl, protected readonly UIFactory $ui_factory, protected readonly DataFactory $data_factory, protected readonly GlobalHttpState $http, protected readonly \ilTestPlayerAbstractGUI $parent_gui, protected readonly \ilObjTest $test, protected readonly array $data)
$http
Definition: deliver.php:30
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
$components
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:28
buildDataRow(string $id, array $record)
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e...