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