ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilListOfQuestionsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
35 {
36  private bool $user_has_attempts_left = true;
38  private array $command_buttons = [];
40  protected ?bool $showPointsEnabled = false;
41  protected ?bool $showMarkerEnabled = false;
42 
43  protected ?bool $showObligationsEnabled = false;
44  protected ?bool $obligationsFilterEnabled = false;
45 
46  protected ?bool $obligationsNotAnswered = false;
47 
48  protected ?bool $finishTestButtonEnabled = false;
49 
50  public function __construct(
52  string $parent_cmd,
53  private UIFactory $ui_factory,
54  private UIRenderer $ui_renderer
55  ) {
56  parent::__construct($parent_obj, $parent_cmd);
57 
58  $this->setFormName('listofquestions');
59  $this->setStyle('table', 'fullwidth');
60 
61  $this->setRowTemplate("tpl.il_as_tst_list_of_questions_row.html", "Modules/Test");
62 
63  $this->setLimit(999);
64 
65  $this->setFormAction($this->ctrl->getFormAction($parent_obj, $parent_cmd));
66 
67  $this->enable('header');
68  $this->disable('sort');
69  $this->disable('select_all');
70  }
71 
72  public function init(): void
73  {
74  // table title
75 
76  if ($this->isObligationsFilterEnabled()) {
77  $this->setTitle($this->lng->txt('obligations_summary'));
78  } else {
79  $this->setTitle($this->lng->txt('question_summary'));
80  }
81 
82  // columns
83 
84  $this->addColumn($this->lng->txt("tst_qst_order"), 'order', '');
85  $this->addColumn($this->lng->txt("tst_question_title"), 'title', '');
86 
87  if ($this->isShowObligationsEnabled()) {
88  $this->addColumn($this->lng->txt("obligatory"), 'obligatory', '');
89  }
90 
91  $this->addColumn('', 'postponed', '');
92 
93  if ($this->isShowPointsEnabled()) {
94  $this->addColumn($this->lng->txt("tst_maximum_points"), 'points', '');
95  }
96 
97  #$this->addColumn($this->lng->txt("worked_through"),'worked_through', '');
98  $this->addColumn($this->lng->txt("answered"), 'answered', '');
99 
100  if (false && $this->isShowObligationsEnabled()) {
101  $this->addColumn($this->lng->txt("answered"), 'answered', '');
102  }
103 
104  if ($this->isShowMarkerEnabled()) {
105  $this->addColumn($this->lng->txt("tst_question_marker"), 'marked', '');
106  }
107 
108  // command buttons
109  $this->command_buttons[] = $this->ui_factory->button()->standard(
110  $this->lng->txt('tst_resume_test'),
111  $this->ctrl->getLinkTarget($this->parent_obj, ilTestPlayerCommands::SHOW_QUESTION)
112  );
113 
114  if (!$this->areObligationsNotAnswered() && $this->isFinishTestButtonEnabled()) {
115  $this->addFinishTestButton();
116  }
117  }
118 
119  public function userHasAttemptsLeft(): bool
120  {
122  }
123 
124  public function setUserHasAttemptsLeft(bool $user_has_attempts_left): void
125  {
126  $this->user_has_attempts_left = $user_has_attempts_left;
127  }
128 
129  private function addFinishTestButton(): void
130  {
131 
132  // Examview enabled & !reviewed & requires_confirmation? test_submission_overview (review gui)
133  if ($this->parent_obj->getObject()->getMainSettings()->getFinishingSettings()->getShowAnswerOverview()) {
134  $this->command_buttons[] = $this->ui_factory->button()->standard(
135  $this->lng->txt('finish_test'),
136  $this->ctrl->getLinkTargetByClass('ilTestSubmissionReviewGUI', 'show')
137  );
138  return;
139  }
140 
141  $message = $this->lng->txt('tst_finish_confirmation_question_no_attempts_left');
142  if ($this->userHasAttemptsLeft()) {
143  $message = $this->lng->txt('tst_finish_confirmation_question');
144  }
145 
146  $this->finish_test_modal = $this->parent_obj->buildFinishTestModal();
147 
148  $this->command_buttons[] = $this->ui_factory->button()->standard($this->lng->txt('finish_test'), '')
149  ->withOnClick($this->finish_test_modal->getShowSignal());
150  }
151 
152  public function getHTML(): string
153  {
154  foreach ($this->command_buttons as $top_item) {
155  $this->tpl->setCurrentBlock('tbl_header_html');
156  $this->tpl->setVariable(
157  "HEADER_HTML",
158  $this->ui_renderer->render($top_item)
159  );
160  $this->tpl->parseCurrentBlock();
161  }
162 
163  $finish_test_modal = isset($this->finish_test_modal)
164  ? $this->ui_renderer->render($this->finish_test_modal) : '';
165 
166  return parent::getHTML() . $finish_test_modal;
167  }
168 
169  public function fillRow(array $a_set): void
170  {
171  if ($this->isShowPointsEnabled()) {
172  $this->tpl->setCurrentBlock('points');
173  $this->tpl->setVariable("POINTS", $a_set['points'] . '&nbsp;' . $this->lng->txt("points_short"));
174  $this->tpl->parseCurrentBlock();
175  }
176  if (strlen($a_set['description'])) {
177  $this->tpl->setCurrentBlock('description');
178  $this->tpl->setVariable("DESCRIPTION", ilLegacyFormElementsUtil::prepareFormOutput($a_set['description']));
179  $this->tpl->parseCurrentBlock();
180  }
181  if ($this->isShowMarkerEnabled()) {
182  if ($a_set['marked']) {
183  $this->tpl->setCurrentBlock('marked_img');
184  $this->tpl->setVariable(
185  "HREF_MARKED",
186  ilUtil::img(
187  ilUtil::getImagePath('object/marked.svg'),
188  $this->lng->txt("tst_question_marked"),
189  '24px',
190  '24px'
191  )
192  );
193  $this->tpl->parseCurrentBlock();
194  } else {
195  $this->tpl->touchBlock('marker');
196  }
197  }
198  if ($this->isShowObligationsEnabled()) {
199  // obligatory answer status
200  if (false) {
201  $value = '&nbsp;';
202  if ($a_set['isAnswered']) {
203  $value = $this->lng->txt("yes");
204  }
205  $this->tpl->setCurrentBlock('answered_col');
206  $this->tpl->setVariable('ANSWERED', $value);
207  $this->tpl->parseCurrentBlock();
208  }
209 
210  // obligatory icon
211  if ($a_set["obligatory"]) {
212  $obligatory = $this->ui_renderer->render(
213  $this->ui_factory->symbol()->icon()->custom(
214  ilUtil::getImagePath('standard/icon_alert.svg'),
215  $this->lng->txt('question_obligatory')
216  )
217  );
218  } else {
219  $obligatory = '';
220  }
221  $this->tpl->setVariable("QUESTION_OBLIGATORY", $obligatory);
222  }
223 
224  $postponed = (
225  $a_set['postponed'] ? $this->lng->txt('postponed') : ''
226  );
227 
228  if ($a_set['disabled']) {
229  $this->tpl->setCurrentBlock('static_title');
230  $this->tpl->setVariable("STATIC_TITLE", ilLegacyFormElementsUtil::prepareFormOutput($a_set['title']));
231  $this->tpl->parseCurrentBlock();
232  } else {
233  $this->ctrl->setParameter($this->parent_obj, 'sequence', $a_set['sequence']);
234  $this->ctrl->setParameter($this->parent_obj, 'pmode', '');
235  $href = $this->ctrl->getLinkTarget($this->parent_obj, ilTestPlayerCommands::SHOW_QUESTION);
236 
237  $this->tpl->setCurrentBlock('linked_title');
238  $this->tpl->setVariable("LINKED_TITLE", ilLegacyFormElementsUtil::prepareFormOutput($a_set['title']));
239  $this->tpl->setVariable("HREF", $href);
240  $this->tpl->parseCurrentBlock();
241  }
242 
243  $this->tpl->setVariable("ORDER", $a_set['order']);
244  $this->tpl->setVariable("POSTPONED", $postponed);
245  if ($a_set["worked_through"]) {
246  $this->tpl->setVariable("WORKED_THROUGH", $this->lng->txt("yes"));
247  } else {
248  $this->tpl->setVariable("WORKED_THROUGH", '&nbsp;');
249  }
250  }
251 
252  public function isShowPointsEnabled(): bool
253  {
255  }
256 
257  public function setShowPointsEnabled($showPointsEnabled): void
258  {
259  $this->showPointsEnabled = $showPointsEnabled;
260  }
261 
262  public function isShowMarkerEnabled(): bool
263  {
265  }
266 
267  public function setShowMarkerEnabled($showMarkerEnabled): void
268  {
269  $this->showMarkerEnabled = $showMarkerEnabled;
270  }
271 
272  public function isShowObligationsEnabled(): bool
273  {
275  }
276 
277  public function setShowObligationsEnabled($showObligationsEnabled): void
278  {
279  $this->showObligationsEnabled = $showObligationsEnabled;
280  }
281 
282  public function isObligationsFilterEnabled(): bool
283  {
285  }
286 
287  public function setObligationsFilterEnabled($obligationsFilterEnabled): void
288  {
289  $this->obligationsFilterEnabled = $obligationsFilterEnabled;
290  }
291 
292  public function areObligationsNotAnswered(): bool
293  {
295  }
296 
297  public function setObligationsNotAnswered($obligationsNotAnswered): void
298  {
299  $this->obligationsNotAnswered = $obligationsNotAnswered;
300  }
301 
302  public function isFinishTestButtonEnabled(): bool
303  {
305  }
306 
307  public function setFinishTestButtonEnabled(bool $finishTestButtonEnabled): void
308  {
309  $this->finishTestButtonEnabled = $finishTestButtonEnabled;
310  }
311 }
enable(string $a_module_name)
setFormAction(string $a_form_action, bool $a_multipart=false)
setUserHasAttemptsLeft(bool $user_has_attempts_left)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
setFinishTestButtonEnabled(bool $finishTestButtonEnabled)
static prepareFormOutput($a_str, bool $a_strip=false)
setFormName(string $a_name="")
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
__construct(ilTestPlayerAbstractGUI $parent_obj, string $parent_cmd, private UIFactory $ui_factory, private UIRenderer $ui_renderer)
setStyle(string $a_element, string $a_style)
setObligationsNotAnswered($obligationsNotAnswered)
__construct(VocabulariesInterface $vocabularies)
setShowObligationsEnabled($showObligationsEnabled)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setLimit(int $a_limit=0, int $a_default_limit=0)
setObligationsFilterEnabled($obligationsFilterEnabled)
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)
$message
Definition: xapiexit.php:32
disable(string $a_module_name)
Output class for assessment test execution.