ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $this->content_obj->setItemStyleClass(
145 $this->form->getInput("item_style_1")
146 );
147 } else {
148 $this->content_obj->setNumberingType(
149 $this->form->getInput("numbering_type")
150 );
151 $this->content_obj->setStyleClass(
152 $this->form->getInput("number_style")
153 );
154 $this->content_obj->setItemStyleClass(
155 $this->form->getInput("item_style_2")
156 );
157 }
158
159 $this->updated = $this->pg_obj->update();
160 if ($this->updated === true) {
161 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
162 }
163 }
164 $this->form->setValuesByPost();
165 $tpl->setContent($this->form->getHTML());
166 }
167
168 public static function _getListCharacteristics(
169 int $a_style_id,
170 string $type
171 ): array {
172 $chars = [];
173
174 if ($a_style_id > 0 &&
175 ilObject::_lookupType($a_style_id) == "sty") {
176 $style = new ilObjStyleSheet($a_style_id);
177 $types = [$type];
178 foreach ($types as $t) {
179 $chars = array_merge($chars, $style->getCharacteristics($t, false, true));
180 }
181 }
182
183 return $chars;
184 }
185
186 public function initListForm(
187 string $a_mode = "edit"
188 ): void {
189 $lng = $this->lng;
190 $this->form = new ilPropertyFormGUI();
191
192 // type
193 $radg = new ilRadioGroupInputGUI($lng->txt("type"), "list_type");
194 $op1 = new ilRadioOption($lng->txt("cont_bullet_list"), "Unordered");
195
196 // style of bullet list
197 $style = new ilSelectInputGUI(
198 $this->lng->txt("cont_style"),
199 "bullet_style"
200 );
201 $this->getCharacteristicsOfCurrentStyle(["list_u"]);
202 $options = $this->getCharacteristics();
203 if ($a_mode == "edit" && $this->content_obj->getListType() == "Unordered"
204 && $this->content_obj->getStyleClass() != ""
205 && !in_array($this->content_obj->getStyleClass(), $options)) {
206 $options[$this->content_obj->getStyleClass()] =
207 $this->content_obj->getStyleClass();
208 }
209 if (count($options) > 1) {
210 $style->setValue("");
211 $style->setOptions($options);
212 $op1->addSubItem($style);
213 }
214
215 $radg->addOption($op1);
216
217
218 $op2 = new ilRadioOption($lng->txt("cont_numbered_list"), "Ordered");
219
220 // style of numbered list
221 $style = new ilSelectInputGUI(
222 $this->lng->txt("cont_style"),
223 "number_style"
224 );
225 $this->getCharacteristicsOfCurrentStyle(["list_o"]);
226 $options = $this->getCharacteristics();
227 if ($a_mode == "edit" && $this->content_obj->getListType() == "Ordered"
228 && $this->content_obj->getStyleClass() != ""
229 && !in_array($this->content_obj->getStyleClass(), $options)) {
230 $options[$this->content_obj->getStyleClass()] =
231 $this->content_obj->getStyleClass();
232 }
233 if (count($options) > 1) {
234 foreach ($options as $k => $option) {
235 $html = '<ol class="ilc_list_o_' . $k . '"><li class="ilc_list_item_StandardListItem">' .
236 $option . '</li></ol>';
237 if ($k == "NumberedList") {
238 $k = "";
239 }
240 //$style->addOption($k, $option, $html);
241 }
242 $style->setValue("");
243 $style->setOptions($options);
244 $op2->addSubItem($style);
245 }
246
247 // numeric type
248 $options = array(
249 "Number" => $this->lng->txt("cont_number_std"),
250 "Decimal" => $this->lng->txt("cont_decimal"),
251 "Roman" => $this->lng->txt("cont_roman"),
252 "roman" => $this->lng->txt("cont_roman_s"),
253 "Alphabetic" => $this->lng->txt("cont_alphabetic"),
254 "alphabetic" => $this->lng->txt("cont_alphabetic_s")
255 );
256 $si = new ilSelectInputGUI($this->lng->txt("cont_number_type"), "numbering_type");
257 $si->setOptions($options);
258 $op2->addSubItem($si);
259
260 // starting value
261 $ni = new ilNumberInputGUI($this->lng->txt("cont_start_value"), "start_value");
262 $ni->setMaxLength(3);
263 $ni->setSize(3);
264 $ni->setInfo($lng->txt("cont_start_value_info"));
265 $op2->addSubItem($ni);
266
267 $radg->addOption($op2);
268 $radg->setValue("Unordered");
269 $this->form->addItem($radg);
270
271 // list item type
272 $this->getCharacteristicsOfCurrentStyle(["list_item"]);
273 $options = $this->getCharacteristics();
274 if (count($options) > 1) {
275 $style1 = new ilSelectInputGUI(
276 $this->lng->txt("cont_list_item_style"),
277 "item_style_1"
278 );
279 $style2 = new ilSelectInputGUI(
280 $this->lng->txt("cont_list_item_style"),
281 "item_style_2"
282 );
283 foreach ($options as $k => $option) {
284 $html = '<ul style="list-style-type:none;"><li class="ilc_list_item_' . $option . '">' .
285 $option . '</li></ul>';
286 if ($k == "BulletedList") {
287 $k = "";
288 }
289 //$style1->addOption($k, $option, $html);
290 //$style2->addOption($k, $option, $html);
291 }
292 $style1->setOptions($options);
293 $style2->setOptions($options);
294 $style1->setValue("StandardListItem");
295 $style2->setValue("StandardListItem");
296 $op1->addSubItem($style1);
297 $op2->addSubItem($style2);
298 }
299 $options = $this->getCharacteristicsOfCurrentStyle(["list_item"]);
300
301
302 // nr of items
303 $options = array();
304 if ($a_mode == "create") {
305 for ($i = 1; $i <= 10; $i++) {
306 $options[$i] = $i;
307 }
308 $si = new ilSelectInputGUI($this->lng->txt("cont_nr_items"), "nr_items");
309 $si->setOptions($options);
310 $si->setValue(2);
311 $this->form->addItem($si);
312 }
313
314 // save and cancel commands
315 if ($a_mode == "create") {
316 $this->form->addCommandButton("create", $lng->txt("save"));
317 $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
318 $this->form->setTitle($lng->txt("cont_insert_list"));
319 } else {
320 $this->form->addCommandButton("saveProperties", $lng->txt("save"));
321 $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
322 $this->form->setTitle($lng->txt("cont_list_properties"));
323 }
324
325 $this->form->setFormAction($this->ctrl->getFormAction($this));
326 }
327
328 public function getValues(): void
329 {
330 $values = array();
331
332 $values["start_value"] = $this->content_obj->getStartValue();
333 $values["list_type"] = $this->content_obj->getListType();
334 $values["numbering_type"] = $this->content_obj->getNumberingType();
335 if ($values["list_type"] == "Ordered") {
336 $values["number_style"] = $this->content_obj->getStyleClass();
337 $values["bullet_style"] = "";
338 } else {
339 $values["bullet_style"] = $this->content_obj->getStyleClass();
340 $values["number_style"] = "";
341 }
342 $values["item_style_1"] = $this->content_obj->getItemStyleClass();
343 $values["item_style_2"] = $this->content_obj->getItemStyleClass();
344 $this->form->setValuesByArray($values);
345 }
346}
This class represents a number property in a property form.
Class ilObjStyleSheet.
getCharacteristics(string $a_type="", bool $a_no_hidden=false, bool $a_include_core=true)
Get characteristics.
static _lookupType(int $id, bool $reference=false)
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.
static _getListCharacteristics(int $a_style_id, string $type)
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, ...)
ilGlobalTemplateInterface $tpl
Content object of ilPageObject (see ILIAS DTD).
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 class represents an option in a radio group.
This class represents a selection list property in a property form.
setContent(string $a_html)
Sets content for standard template.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd, string $submit_caption="")
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26