ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestNavigationToolbarGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
31 {
32  private bool $suspendTestButtonEnabled = false;
33  private bool $questionTreeVisible = false;
34  private bool $questionSelectionButtonEnabled = false;
35  private bool $finishTestButtonEnabled = false;
36  private string $finishTestCommand = '';
37  private bool $finishTestButtonPrimary = false;
38  private bool $disabledStateEnabled = false;
40  protected bool $user_pass_overview_button_enabled = false;
41 
42  public function __construct(
43  protected ilCtrl $ctrl,
44  protected ilTestPlayerAbstractGUI $player_gui
45  ) {
47  }
48 
52  public function isSuspendTestButtonEnabled(): bool
53  {
55  }
56 
60  public function setSuspendTestButtonEnabled($suspendTestButtonEnabled)
61  {
62  $this->suspendTestButtonEnabled = $suspendTestButtonEnabled;
63  }
64 
68  public function isUserPassOverviewEnabled(): bool
69  {
71  }
72 
76  public function setUserPassOverviewEnabled(bool $user_pass_overview_button_enabled)
77  {
78  $this->user_pass_overview_button_enabled = $user_pass_overview_button_enabled;
79  }
80 
84  public function isQuestionTreeVisible(): bool
85  {
87  }
88 
89  public function setQuestionTreeVisible(bool $questionTreeVisible): void
90  {
91  $this->questionTreeVisible = $questionTreeVisible;
92  }
93 
97  public function isFinishTestButtonEnabled(): bool
98  {
100  }
101 
105  public function setFinishTestButtonEnabled($finishTestButtonEnabled)
106  {
107  $this->finishTestButtonEnabled = $finishTestButtonEnabled;
108  }
109 
113  public function getFinishTestCommand(): string
114  {
116  }
117 
121  public function setFinishTestCommand($finishTestCommand)
122  {
123  $this->finishTestCommand = $finishTestCommand;
124  }
125 
129  public function isFinishTestButtonPrimary(): bool
130  {
132  }
133 
137  public function setFinishTestButtonPrimary($finishTestButtonPrimary)
138  {
139  $this->finishTestButtonPrimary = $finishTestButtonPrimary;
140  }
141 
145  public function isDisabledStateEnabled(): bool
146  {
148  }
149 
153  public function setDisabledStateEnabled($disabledStateEnabled)
154  {
155  $this->disabledStateEnabled = $disabledStateEnabled;
156  }
157 
158  public function build()
159  {
160  if ($this->isUserPassOverviewEnabled()) {
161  $this->addPassOverviewButton();
162  }
163 
164  if ($this->isSuspendTestButtonEnabled()) {
165  $this->addSuspendTestButton();
166  }
167 
168  if ($this->isFinishTestButtonEnabled()) {
169  $this->addStickyItem($this->retrieveFinishTestButton());
170  }
171  }
172 
173  private function addSuspendTestButton()
174  {
175  $button = $this->ui->factory()->button()->standard(
176  $this->lng->txt('cancel_test'),
177  ''
178  )->withUnavailableAction(true)->withAdditionalOnLoadCode(
180  $this->ctrl->getLinkTarget($this->player_gui, ilTestPlayerCommands::SUSPEND_TEST)
181  )
182  );
183 
184  $this->addComponent($button);
185  }
186 
187  private function addPassOverviewButton()
188  {
189  $button = $this->ui->factory()->button()->standard(
190  $this->lng->txt('question_summary_btn'),
191  ''
192  )->withUnavailableAction(true)->withAdditionalOnLoadCode(
194  $this->ctrl->getLinkTarget($this->player_gui, ilTestPlayerCommands::QUESTION_SUMMARY)
195  )
196  );
197 
198  $this->addComponent($button);
199  }
200 
201  private function retrieveFinishTestButton(): Button
202  {
203  $target = $this->ctrl->getLinkTarget($this->player_gui, $this->getFinishTestCommand());
204  if ($this->player_gui->getObject()->getMainSettings()->getFinishingSettings()->getShowAnswerOverview()
206  $target = $this->ctrl->getLinkTargetByClass('ilTestSubmissionReviewGUI', 'show');
207  }
208 
209  $button = $this->getStandardOrPrimaryFinishButtonInstance();
210  return $button->withUnavailableAction(true)->withAdditionalOnLoadCode(
211  $this->buildCheckNavigationClosure($target)
212  );
213  }
214 
216  {
217  if ($this->isFinishTestButtonPrimary()) {
218  return $this->ui->factory()->button()->primary($this->lng->txt('finish_test'), '');
219  }
220 
221  return $this->ui->factory()->button()->standard($this->lng->txt('finish_test'), '');
222  }
223 
224  private function buildCheckNavigationClosure(string $target): Closure
225  {
226  return static function (string $id) use ($target): string {
227  return "document.getElementById('{$id}').addEventListener('click', "
228  . '(e) => {'
229  . " il.TestPlayerQuestionEditControl.checkNavigation('{$target}', 'show', e);"
230  . '}); '
231  . "document.getElementById('{$id}').removeAttribute('disabled');";
232  };
233  }
234 }
setFinishTestButtonEnabled($finishTestButtonEnabled)
addComponent(\ILIAS\UI\Component\Component $a_comp)
setSuspendTestButtonEnabled($suspendTestButtonEnabled)
__construct(protected ilCtrl $ctrl, protected ilTestPlayerAbstractGUI $player_gui)
setQuestionTreeVisible(bool $questionTreeVisible)
__construct(VocabulariesInterface $vocabularies)
setUserPassOverviewEnabled(bool $user_pass_overview_button_enabled)
setFinishTestButtonPrimary($finishTestButtonPrimary)
addStickyItem( $a_item, bool $a_output_label=false)
Add a sticky item.
Output class for assessment test execution.