ILIAS  release_8 Revision v8.24
class.ilPCListGUI.php
Go to the documentation of this file.
1<?php
2
27{
29
30 public function __construct(
31 ilPageObject $a_pg_obj,
32 ?ilPageContent $a_content_obj,
33 string $a_hier_id,
34 string $a_pc_id = ""
35 ) {
36 global $DIC;
37
38 $this->tpl = $DIC["tpl"];
39 $this->lng = $DIC->language();
40 $this->ctrl = $DIC->ctrl();
41 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
42 }
43
44 public function executeCommand(): void
45 {
46 // get next class that processes or forwards current command
47 $next_class = $this->ctrl->getNextClass($this);
48
49 // get current command
50 $cmd = $this->ctrl->getCmd();
51
52 switch ($next_class) {
53 default:
54 $this->$cmd();
55 break;
56 }
57 }
58
59
63 public function insert(): void
64 {
66 $this->initListForm("create");
67 $this->tpl->setContent($this->form->getHTML());
68 }
69
70
74 public function create(): void
75 {
77
78 $this->initListForm("create");
79 if ($this->form->checkInput()) {
80 $this->content_obj = new ilPCList($this->getPage());
81 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
82 $this->content_obj->addItems($this->form->getInput("nr_items"));
83 $this->content_obj->setStartValue(
84 (int) $this->form->getInput("start_value")
85 );
86 $list_type = $this->form->getInput("list_type");
87 $this->content_obj->setListType(
88 $list_type
89 );
90 if ($list_type == "Unordered") {
91 $this->content_obj->setNumberingType("");
92 $this->content_obj->setStyleClass(
93 $this->form->getInput("bullet_style")
94 );
95 } else {
96 $this->content_obj->setNumberingType(
97 $this->form->getInput("numbering_type")
98 );
99 $this->content_obj->setStyleClass(
100 $this->form->getInput("number_style")
101 );
102 }
103 $this->updated = $this->pg_obj->update();
104 if ($this->updated === true) {
105 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
106 }
107 }
108 $this->form->setValuesByPost();
109 $tpl->setContent($this->form->getHTML());
110 }
111
115 public function edit(): void
116 {
117 $this->displayValidationError();
118 $this->initListForm("edit");
119 $this->getValues();
120 $this->tpl->setContent($this->form->getHTML());
121 }
122
126 public function saveProperties(): void
127 {
129
130 $this->initListForm("edit");
131 if ($this->form->checkInput()) {
132 $this->content_obj->setStartValue(
133 $this->form->getInput("start_value")
134 );
135 $list_type = $this->form->getInput("list_type");
136 $this->content_obj->setListType(
137 $list_type
138 );
139 if ($list_type == "Unordered") {
140 $this->content_obj->setNumberingType("");
141 $this->content_obj->setStyleClass(
142 $this->form->getInput("bullet_style")
143 );
144 } else {
145 $this->content_obj->setNumberingType(
146 $this->form->getInput("numbering_type")
147 );
148 $this->content_obj->setStyleClass(
149 $this->form->getInput("number_style")
150 );
151 }
152
153 $this->updated = $this->pg_obj->update();
154 if ($this->updated === true) {
155 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
156 }
157 }
158 $this->form->setValuesByPost();
159 $tpl->setContent($this->form->getHTML());
160 }
161
162 public function initListForm(
163 string $a_mode = "edit"
164 ): void {
165 $lng = $this->lng;
166 $this->form = new ilPropertyFormGUI();
167
168 // type
169 $radg = new ilRadioGroupInputGUI($lng->txt("type"), "list_type");
170 $op1 = new ilRadioOption($lng->txt("cont_bullet_list"), "Unordered");
171
172 // style of bullet list
174 $this->lng->txt("cont_style"),
175 "bullet_style"
176 );
177 $this->getCharacteristicsOfCurrentStyle(["list_u"]);
178 $options = $this->getCharacteristics();
179 if ($a_mode == "edit" && $this->content_obj->getListType() == "Unordered"
180 && $this->content_obj->getStyleClass() != ""
181 && !in_array($this->content_obj->getStyleClass(), $options)) {
182 $options[$this->content_obj->getStyleClass()] =
183 $this->content_obj->getStyleClass();
184 }
185 if (count($options) > 1) {
186 foreach ($options as $k => $option) {
187 $html = '<ul class="ilc_list_u_' . $k . '"><li class="ilc_list_item_StandardListItem">' .
188 $option . '</li></ul>';
189 if ($k == "BulletedList") {
190 $k = "";
191 }
192 $style->addOption($k, $option, $html);
193 }
194 $style->setValue("");
195 $op1->addSubItem($style);
196 }
197
198 $radg->addOption($op1);
199
200
201 $op2 = new ilRadioOption($lng->txt("cont_numbered_list"), "Ordered");
202
203 // style of numbered list
205 $this->lng->txt("cont_style"),
206 "number_style"
207 );
208 $this->getCharacteristicsOfCurrentStyle(["list_o"]);
209 $options = $this->getCharacteristics();
210 if ($a_mode == "edit" && $this->content_obj->getListType() == "Ordered"
211 && $this->content_obj->getStyleClass() != ""
212 && !in_array($this->content_obj->getStyleClass(), $options)) {
213 $options[$this->content_obj->getStyleClass()] =
214 $this->content_obj->getStyleClass();
215 }
216 if (count($options) > 1) {
217 foreach ($options as $k => $option) {
218 $html = '<ol class="ilc_list_o_' . $k . '"><li class="ilc_list_item_StandardListItem">' .
219 $option . '</li></ol>';
220 if ($k == "NumberedList") {
221 $k = "";
222 }
223 $style->addOption($k, $option, $html);
224 }
225 $style->setValue("");
226 $op2->addSubItem($style);
227 }
228
229 // numeric type
230 $options = array(
231 "Number" => $this->lng->txt("cont_number_std"),
232 "Decimal" => $this->lng->txt("cont_decimal"),
233 "Roman" => $this->lng->txt("cont_roman"),
234 "roman" => $this->lng->txt("cont_roman_s"),
235 "Alphabetic" => $this->lng->txt("cont_alphabetic"),
236 "alphabetic" => $this->lng->txt("cont_alphabetic_s")
237 );
238 $si = new ilSelectInputGUI($this->lng->txt("cont_number_type"), "numbering_type");
239 $si->setOptions($options);
240 $op2->addSubItem($si);
241
242 // starting value
243 $ni = new ilNumberInputGUI($this->lng->txt("cont_start_value"), "start_value");
244 $ni->setMaxLength(3);
245 $ni->setSize(3);
246 $ni->setInfo($lng->txt("cont_start_value_info"));
247 $op2->addSubItem($ni);
248
249 $radg->addOption($op2);
250 $radg->setValue("Unordered");
251 $this->form->addItem($radg);
252
253 // nr of items
254 $options = array();
255 if ($a_mode == "create") {
256 for ($i = 1; $i <= 10; $i++) {
257 $options[$i] = $i;
258 }
259 $si = new ilSelectInputGUI($this->lng->txt("cont_nr_items"), "nr_items");
260 $si->setOptions($options);
261 $si->setValue(2);
262 $this->form->addItem($si);
263 }
264
265 // save and cancel commands
266 if ($a_mode == "create") {
267 $this->form->addCommandButton("create_list", $lng->txt("save"));
268 $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
269 $this->form->setTitle($lng->txt("cont_insert_list"));
270 } else {
271 $this->form->addCommandButton("saveProperties", $lng->txt("save"));
272 $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
273 $this->form->setTitle($lng->txt("cont_list_properties"));
274 }
275
276 $this->form->setFormAction($this->ctrl->getFormAction($this));
277 }
278
279 public function getValues(): void
280 {
281 $values = array();
282
283 $values["start_value"] = $this->content_obj->getStartValue();
284 $values["list_type"] = $this->content_obj->getListType();
285 $values["numbering_type"] = $this->content_obj->getNumberingType();
286 if ($values["list_type"] == "Ordered") {
287 $values["number_style"] = $this->content_obj->getStyleClass();
288 $values["bullet_style"] = "";
289 } else {
290 $values["bullet_style"] = $this->content_obj->getStyleClass();
291 $values["number_style"] = "";
292 }
293 $this->form->setValuesByArray($values);
294 }
295}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This class represents a number property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initListForm(string $a_mode="edit")
edit()
edit properties form
create()
Save list.
saveProperties()
Save properties.
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
ilPropertyFormGUI $form
insert()
insert new list form
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getCharacteristicsOfCurrentStyle(array $a_type)
Get characteristics of current style and call setCharacteristics, if style is given.
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
global $DIC
Definition: feed.php:28
setContent(string $a_html)
Sets content for standard template.
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd)