ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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(): array
82  {
83  $components = [
84  $this->ui_factory->button()->standard(
85  $this->lng->txt('tst_resume_test'),
86  $this->ctrl->getLinkTarget($this->parent_gui, ilTestPlayerCommands::SHOW_QUESTION)
87  )
88  ];
89 
90  $button_text = $this->lng->txt('finish_test');
91  // Examview enabled & !reviewed & requires_confirmation? test_submission_overview (review gui)
92  if ($this->parent_gui->getObject()->getMainSettings()->getFinishingSettings()->getShowAnswerOverview()) {
93  $components[] = $this->ui_factory->button()->standard(
94  $button_text,
95  $this->ctrl->getLinkTargetByClass(ilTestSubmissionReviewGUI::class, 'show')
96  );
97  } else {
98  $finish_test_modal = $this->parent_gui->buildFinishTestModal();
99  $components[] = $this->ui_factory->button()->standard($button_text, '')
100  ->withOnClick($finish_test_modal->getShowSignal());
101  $components[] = $finish_test_modal;
102  }
103 
104  $components[] = $this->ui_factory->table()->data(
105  $this,
106  $this->lng->txt('question_summary'),
107  $this->getColumns(),
108  )
109  ->withRequest($this->http->request())
110  ->withId('listofquestions');
111 
112  return $components;
113  }
114 
115  protected function getData(Range $range, Order $order): array
116  {
117  // ignore order bc table is not sortable
118  return array_slice($this->data, $range->getStart(), $range->getLength());
119  }
120 
121  protected function createShowQuestionLink(int $sequence): string
122  {
123  $this->ctrl->setParameter($this->parent_gui, 'sequence', $sequence);
124  $this->ctrl->setParameter($this->parent_gui, 'pmode', '');
125  return $this->ctrl->getLinkTarget($this->parent_gui, ilTestPlayerCommands::SHOW_QUESTION);
126  }
127 
131  protected function getColumns(): array
132  {
133  $column_factory = $this->ui_factory->table()->column();
134  $icon_factory = $this->ui_factory->symbol()->icon();
135  $icon_checked = $icon_factory->custom('assets/images/standard/icon_checked.svg', $this->lng->txt('yes'));
136  $icon_unchecked = $icon_factory->custom('assets/images/standard/icon_unchecked.svg', $this->lng->txt('no'));
137  $icon_marked = $icon_factory->custom('assets/images/object/marked.svg', $this->lng->txt('tst_question_marked'));
138 
139  $columns = [
140  'order' => $column_factory->number($this->lng->txt('tst_qst_order')),
141  'title' => $column_factory->link($this->lng->txt('tst_question')),
142  'description' => $column_factory->text($this->lng->txt('description')),
143  'postponed' => $column_factory->boolean(ucfirst($this->lng->txt('postponed')), $this->lng->txt('yes'), ''),
144  'points' => $column_factory->number($this->lng->txt('tst_maximum_points'))->withUnit($this->lng->txt('points_short')),
145  'answered' => $column_factory->boolean($this->lng->txt('answered'), $icon_checked, $icon_unchecked),
146  'marked' => $column_factory->boolean($this->lng->txt('tst_question_marker'), $icon_marked, ''),
147  ];
148 
149  $optional_columns = [
150  'description' => $this->isShowDescriptionEnabled(),
151  'postponed' => $this->isPostponingEnabled(),
152  'points' => $this->isShowPointsEnabled(),
153  'marked' => $this->isShowMarkerEnabled(),
154  ];
155 
156  $list = [];
157  foreach ($columns as $key => $column) {
158  if (isset($optional_columns[$key]) && !$optional_columns[$key]) {
159  continue;
160  }
161  $list[$key] = $column->withIsOptional(false, true)->withIsSortable(false);
162  }
163  return $list;
164  }
165 
166  protected function isShowDescriptionEnabled(): bool
167  {
168  return $this->test->getListOfQuestionsDescription();
169  }
170 
171  protected function isPostponingEnabled(): bool
172  {
173  return $this->test->isPostponingEnabled();
174  }
175 
176  protected function isShowPointsEnabled(): bool
177  {
178  return !$this->test->getTitleOutput();
179  }
180 
181  protected function isShowMarkerEnabled(): bool
182  {
183  return $this->test->getShowMarker();
184  }
185 
186 }
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...