ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestPlayerConfirmationModal.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
34 {
35  protected string $modal_id = '';
36  protected string $header_text = '';
37  protected string $confirmation_text = '';
38  protected string $confirmation_checkbox_name = '';
39  protected string $confirmation_checkbox_label = '';
40 
44  protected array $buttons = [];
45 
49  protected array $parameters = [];
50 
51  public function __construct(
52  protected UIRenderer $ui_renderer
53  ) {
54  }
55 
56  public function getModalId(): string
57  {
58  return $this->modal_id;
59  }
60 
61  public function setModalId(string $modal_id)
62  {
63  $this->modal_id = $modal_id;
64  }
65 
66  public function getHeaderText(): string
67  {
68  return $this->header_text;
69  }
70 
71  public function setHeaderText(string $header_text)
72  {
73  $this->header_text = $header_text;
74  }
75 
76  public function getConfirmationText(): string
77  {
79  }
80 
81  public function setConfirmationText(string $confirmation_text)
82  {
83  $this->confirmation_text = $confirmation_text;
84  }
85 
86  public function getConfirmationCheckboxName(): string
87  {
89  }
90 
91  public function setConfirmationCheckboxName(string $confirmation_checkbox_name)
92  {
93  $this->confirmation_checkbox_name = $confirmation_checkbox_name;
94  }
95 
96  public function getConfirmationCheckboxLabel(): string
97  {
99  }
100 
101  public function setConfirmationCheckboxLabel(string $confirmation_checkbox_label)
102  {
103  $this->confirmation_checkbox_label = $confirmation_checkbox_label;
104  }
105 
109  public function getButtons(): array
110  {
111  return $this->buttons;
112  }
113 
114  public function addButton(StandardButton|PrimaryButton|ilLinkButton $button)
115  {
116  $this->buttons[] = $button;
117  }
118 
122  public function getParameters(): array
123  {
124  return $this->parameters;
125  }
126 
127  public function addParameter(ilHiddenInputGUI $hidden_input_gui)
128  {
129  $this->parameters[] = $hidden_input_gui;
130  }
131 
132  public function isConfirmationCheckboxRequired(): bool
133  {
134  return strlen($this->getConfirmationCheckboxName()) && strlen($this->getConfirmationCheckboxLabel());
135  }
136 
137  public function buildBody(): string
138  {
139  $tpl = new ilTemplate('tpl.tst_player_confirmation_modal.html', true, true, 'Modules/Test');
140 
141  if ($this->isConfirmationCheckboxRequired()) {
142  $tpl->setCurrentBlock('checkbox');
143  $tpl->setVariable('CONFIRMATION_CHECKBOX_NAME', $this->getConfirmationCheckboxName());
144  $tpl->setVariable('CONFIRMATION_CHECKBOX_LABEL', $this->getConfirmationCheckboxLabel());
145  $tpl->parseCurrentBlock();
146  }
147 
148  foreach ($this->getParameters() as $parameter) {
149  $tpl->setCurrentBlock('hidden_inputs');
150  $tpl->setVariable('HIDDEN_INPUT', $parameter->getToolbarHTML());
151  $tpl->parseCurrentBlock();
152  }
153 
154  foreach ($this->getButtons() as $button) {
155  $tpl->setCurrentBlock('buttons');
156  if ($button instanceof StandardButton || $button instanceof PrimaryButton) {
157  $button_str = $this->ui_renderer->render($button);
158  } elseif ($button instanceof ilLinkButton) {
159  $button_str = $button->render();
160  }
161 
162  $tpl->setVariable('BUTTON', $button_str);
163  $tpl->parseCurrentBlock();
164  }
165 
166  $tpl->setVariable('CONFIRMATION_TEXT', $this->getConfirmationText());
167 
168  return $tpl->get();
169  }
170 
171  public function getHTML(): string
172  {
173  $modal = ilModalGUI::getInstance();
174  $modal->setId($this->getModalId());
175  $modal->setHeading($this->getHeaderText());
176  $modal->setBody($this->buildBody());
177  return $modal->getHTML();
178  }
179 }
__construct(protected UIRenderer $ui_renderer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setConfirmationCheckboxName(string $confirmation_checkbox_name)
addParameter(ilHiddenInputGUI $hidden_input_gui)
setConfirmationCheckboxLabel(string $confirmation_checkbox_label)
static getInstance()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addButton(StandardButton|PrimaryButton|ilLinkButton $button)