ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilConfirmationGUI.php
Go to the documentation of this file.
1<?php
2
27{
28 protected ilLanguage $lng;
30 private array $hidden_item = [];
32 private array $item = [];
34 private array $buttons = [];
35 private bool $use_images = false;
36 private string $form_name = '';
37 protected string $form_action = '';
38 protected string $headertext = '';
39 protected string $cancel_txt = '';
40 protected string $cancel_cmd = '';
41 protected string $cancel_id = '';
42 protected string $confirm_txt = '';
43 protected string $confirm_cmd = '';
44 protected string $confirm_id = '';
45 private \ilGlobalTemplateInterface $main_tpl;
46
47 public function __construct()
48 {
50 global $DIC;
51 $this->main_tpl = $DIC->ui()->mainTemplate();
52
53 $this->lng = $DIC->language();
54 }
55
56 final public function setFormAction(string $a_form_action): void
57 {
58 $this->form_action = $a_form_action;
59 }
60
61 final public function getFormAction(): string
62 {
63 return $this->form_action;
64 }
65
66 public function setHeaderText(string $a_headertext): void
67 {
68 $this->headertext = $a_headertext;
69 }
70
71 public function getHeaderText(): string
72 {
73 return $this->headertext;
74 }
75
76 public function setFormName(string $a_name): void
77 {
78 $this->form_name = $a_name;
79 }
80
81 final public function addButton(string $a_txt, string $a_cmd): void
82 {
83 $this->buttons[] = [
84 'txt' => $a_txt,
85 'cmd' => $a_cmd
86 ];
87 }
88
89 final public function setCancel(
90 string $a_txt,
91 string $a_cmd,
92 string $a_id = ''
93 ): void {
94 $this->cancel_txt = $a_txt;
95 $this->cancel_cmd = $a_cmd;
96 $this->cancel_id = $a_id;
97 }
98
99 final public function setConfirm(
100 string $a_txt,
101 string $a_cmd,
102 string $a_id = ''
103 ): void {
104 $this->confirm_txt = $a_txt;
105 $this->confirm_cmd = $a_cmd;
106 $this->confirm_id = $a_id;
107 }
108
109 public function addItem(
110 string $a_post_var,
111 string $a_id,
112 string $a_text,
113 string $a_img = '',
114 string $a_alt = ''
115 ): void {
116 $this->item[] = [
117 'var' => $a_post_var,
118 'id' => $a_id,
119 'text' => $a_text,
120 'img' => $a_img,
121 'alt' => $a_alt
122 ];
123
124 if ($a_img !== '') {
125 $this->use_images = true;
126 }
127 }
128
129 public function addHiddenItem(
130 string $a_post_var,
131 string $a_value
132 ): void {
133 $this->hidden_item[] = [
134 'var' => $a_post_var,
135 'value' => $a_value
136 ];
137 }
138
139 final public function getHTML(): string
140 {
141 if ($this->headertext === '') {
142 throw new RuntimeException('Please provide a header text before rendering the confirmation dialogue');
143 }
144
145 if ($this->form_action === '') {
146 throw new RuntimeException('Please provide a form action before rendering the confirmation dialogue');
147 }
148
149 if ($this->confirm_txt === '' || $this->confirm_cmd === '') {
150 throw new RuntimeException('Please provide a confirmation button label and command before rendering the confirmation dialogue');
151 }
152
153 if ($this->cancel_txt === '' || $this->cancel_cmd === '') {
154 throw new RuntimeException('Please provide a cancel button label and command before rendering the confirmation dialogue');
155 }
156
157 $this->main_tpl->setOnScreenMessage('question', $this->getHeaderText());
158
159 // delete/handle items
160 if (count($this->item) > 0) {
161 $ctab = new ilConfirmationTableGUI($this->use_images);
162 $ctab->setData($this->item);
163
164 foreach ($this->buttons as $b) {
165 $ctab->addCommandButton($b["cmd"], $b["txt"]);
166 }
167 $ctab->addCommandButton($this->confirm_cmd, $this->confirm_txt);
168 $ctab->addCommandButton($this->cancel_cmd, $this->cancel_txt);
169 $ctab->setFormAction($this->getFormAction());
170 foreach ($this->hidden_item as $hidden_item) {
171 $ctab->addHiddenInput($hidden_item["var"], $hidden_item["value"]);
172 }
173
174 if ($this->form_name !== '') {
175 $ctab->setFormName($this->form_name);
176 }
177
178 return $ctab->getHTML();
179 }
180
181 // simple version, just ask for confirmation
182 $tb = new ilToolbarGUI();
183 $tb->setPreventDoubleSubmission(true);
184 $tb->setFormAction($this->getFormAction());
185 if ($this->hidden_item) {
186 foreach ($this->hidden_item as $hidden_item) {
187 $hiddenInput = new ilHiddenInputGUI($hidden_item['var']);
188 $hiddenInput->setValue($hidden_item['value']);
189 $tb->addInputItem($hiddenInput);
190 }
191 }
192 $confirm = ilSubmitButton::getInstance();
193 $confirm->setCommand($this->confirm_cmd);
194 $confirm->setCaption($this->confirm_txt, false);
195 $confirm->setId($this->confirm_id);
196
197 $cancel = ilSubmitButton::getInstance();
198 $cancel->setCommand($this->cancel_cmd);
199 $cancel->setCaption($this->cancel_txt, false);
200
201 if ($this->cancel_id !== '') {
202 $cancel->setId($this->cancel_id);
203 }
204
205 $tb->addStickyItem($confirm);
206 $tb->addStickyItem($cancel);
207
208 return $tb->getHTML();
209 }
210}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_form_action)
addItem(string $a_post_var, string $a_id, string $a_text, string $a_img='', string $a_alt='')
ilGlobalTemplateInterface $main_tpl
setCancel(string $a_txt, string $a_cmd, string $a_id='')
setHeaderText(string $a_headertext)
addButton(string $a_txt, string $a_cmd)
setConfirm(string $a_txt, string $a_cmd, string $a_id='')
addHiddenItem(string $a_post_var, string $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a hidden form property in a property form.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26