ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPCListGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Services/COPage/classes/class.ilPCList.php");
5 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
6 
18 {
19 
24  public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
25  {
26  global $DIC;
27 
28  $this->tpl = $DIC["tpl"];
29  $this->lng = $DIC->language();
30  $this->ctrl = $DIC->ctrl();
31  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
32  }
33 
37  public function executeCommand()
38  {
39  // get next class that processes or forwards current command
40  $next_class = $this->ctrl->getNextClass($this);
41 
42  // get current command
43  $cmd = $this->ctrl->getCmd();
44 
45  switch ($next_class) {
46  default:
47  $ret = $this->$cmd();
48  break;
49  }
50 
51  return $ret;
52  }
53 
54 
58  public function insert()
59  {
60  $this->displayValidationError();
61 
62  $this->initListForm("create");
63  $this->tpl->setContent($this->form->getHTML());
64  }
65 
66 
70  public function create()
71  {
72  $tpl = $this->tpl;
73  $lng = $this->lng;
75 
76  $this->initListForm("create");
77  if ($this->form->checkInput()) {
78  $this->content_obj = new ilPCList($this->getPage());
79  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
80  $this->content_obj->addItems($_POST["nr_items"]);
81  $this->content_obj->setStartValue($_POST["start_value"]);
82  $this->content_obj->setListType($_POST["list_type"]);
83  if ($_POST["list_type"] == "Unordered") {
84  $this->content_obj->setNumberingType("");
85  $this->content_obj->setStyleClass($_POST["bullet_style"]);
86  } else {
87  $this->content_obj->setNumberingType($_POST["numbering_type"]);
88  $this->content_obj->setStyleClass($_POST["number_style"]);
89  }
90  $this->updated = $this->pg_obj->update();
91  if ($this->updated === true) {
92  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
93  }
94  }
95  $this->form->setValuesByPost();
96  $tpl->setContent($this->form->getHtml());
97  }
98 
102  public function edit()
103  {
104  $this->displayValidationError();
105 
106  $this->initListForm("edit");
107  $this->getValues();
108  $this->tpl->setContent($this->form->getHTML());
109  }
110 
114  public function saveProperties()
115  {
116  $lng = $this->lng;
118  $tpl = $this->tpl;
119 
120  $this->initListForm("edit");
121  if ($this->form->checkInput()) {
122  $this->content_obj->setStartValue($_POST["start_value"]);
123  $this->content_obj->setListType($_POST["list_type"]);
124  if ($_POST["list_type"] == "Unordered") {
125  $this->content_obj->setNumberingType("");
126  $this->content_obj->setStyleClass($_POST["bullet_style"]);
127  } else {
128  $this->content_obj->setNumberingType($_POST["numbering_type"]);
129  $this->content_obj->setStyleClass($_POST["number_style"]);
130  }
131 
132  $this->updated = $this->pg_obj->update();
133  if ($this->updated === true) {
134  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
135  }
136  }
137  $this->form->setValuesByPost();
138  $tpl->setContent($this->form->getHtml());
139  }
140 
146  public function initListForm($a_mode = "edit")
147  {
148  $lng = $this->lng;
149  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
150  $this->form = new ilPropertyFormGUI();
151 
152  // type
153  $radg = new ilRadioGroupInputGUI($lng->txt("type"), "list_type");
154  $op1 = new ilRadioOption($lng->txt("cont_bullet_list"), "Unordered");
155 
156  // style of bullet list
157  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
159  $this->lng->txt("cont_style"),
160  "bullet_style"
161  );
162  $this->getCharacteristicsOfCurrentStyle("list_u");
163  $options = $this->getCharacteristics();
164  if ($a_mode == "edit" && $this->content_obj->getListType() == "Unordered"
165  && $this->content_obj->getStyleClass() != ""
166  && !in_array($this->content_obj->getStyleClass(), $options)) {
167  $options[$this->content_obj->getStyleClass()] =
168  $this->content_obj->getStyleClass();
169  }
170  if (count($options) > 1) {
171  foreach ($options as $k => $option) {
172  $html = '<ul class="ilc_list_u_' . $k . '"><li class="ilc_list_item_StandardListItem">' .
173  $option . '</li></ul>';
174  if ($k == "BulletedList") {
175  $k = "";
176  }
177  $style->addOption($k, $option, $html);
178  }
179  $style->setValue("");
180  $op1->addSubItem($style);
181  }
182 
183  $radg->addOption($op1);
184 
185 
186  $op2 = new ilRadioOption($lng->txt("cont_numbered_list"), "Ordered");
187 
188  // style of numbered list
189  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
191  $this->lng->txt("cont_style"),
192  "number_style"
193  );
194  $this->getCharacteristicsOfCurrentStyle("list_o");
195  $options = $this->getCharacteristics();
196  if ($a_mode == "edit" && $this->content_obj->getListType() == "Ordered"
197  && $this->content_obj->getStyleClass() != ""
198  && !in_array($this->content_obj->getStyleClass(), $options)) {
199  $options[$this->content_obj->getStyleClass()] =
200  $this->content_obj->getStyleClass();
201  }
202  if (count($options) > 1) {
203  foreach ($options as $k => $option) {
204  $html = '<ol class="ilc_list_o_' . $k . '"><li class="ilc_list_item_StandardListItem">' .
205  $option . '</li></ol>';
206  if ($k == "NumberedList") {
207  $k = "";
208  }
209  $style->addOption($k, $option, $html);
210  }
211  $style->setValue("");
212  $op2->addSubItem($style);
213  }
214 
215  // numeric type
216  $options = array(
217  "Number" => $this->lng->txt("cont_number_std"),
218  "Decimal" => $this->lng->txt("cont_decimal"),
219  "Roman" => $this->lng->txt("cont_roman"),
220  "roman" => $this->lng->txt("cont_roman_s"),
221  "Alphabetic" => $this->lng->txt("cont_alphabetic"),
222  "alphabetic" => $this->lng->txt("cont_alphabetic_s")
223  );
224  $si = new ilSelectInputGUI($this->lng->txt("cont_number_type"), "numbering_type");
225  $si->setOptions($options);
226  $op2->addSubItem($si);
227 
228  // starting value
229  $ni = new ilNumberInputGUI($this->lng->txt("cont_start_value"), "start_value");
230  $ni->setMaxLength(3);
231  $ni->setSize(3);
232  $ni->setInfo($lng->txt("cont_start_value_info"));
233  $op2->addSubItem($ni);
234 
235  $radg->addOption($op2);
236  $radg->setValue("Unordered");
237  $this->form->addItem($radg);
238 
239  // nr of items
240  $options = array();
241  if ($a_mode == "create") {
242  for ($i = 1; $i <= 10; $i++) {
243  $options[$i] = $i;
244  }
245  $si = new ilSelectInputGUI($this->lng->txt("cont_nr_items"), "nr_items");
246  $si->setOptions($options);
247  $si->setValue(2);
248  $this->form->addItem($si);
249  }
250 
251  // save and cancel commands
252  if ($a_mode == "create") {
253  $this->form->addCommandButton("create_list", $lng->txt("save"));
254  $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
255  $this->form->setTitle($lng->txt("cont_insert_list"));
256  } else {
257  $this->form->addCommandButton("saveProperties", $lng->txt("save"));
258  $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
259  $this->form->setTitle($lng->txt("cont_list_properties"));
260  }
261 
262  $this->form->setFormAction($this->ctrl->getFormAction($this));
263  }
264 
269  public function getValues()
270  {
271  $tpl = $this->tpl;
272 
273  $values = array();
274 
275  $values["start_value"] = $this->content_obj->getStartValue();
276  $values["list_type"] = $this->content_obj->getListType();
277  $values["numbering_type"] = $this->content_obj->getNumberingType();
278  if ($values["list_type"] == "Ordered") {
279  $values["number_style"] = $this->content_obj->getStyleClass();
280  $values["bullet_style"] = "";
281  } else {
282  $values["bullet_style"] = $this->content_obj->getStyleClass();
283  $values["number_style"] = "";
284  }
285  $this->form->setValuesByArray($values);
286  }
287 }
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
This class represents an option in a radio group.
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
$style
Definition: example_012.php:70
insert()
insert new list form
This class represents a selection list property in a property form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
Class ilPCListGUI.
global $ilCtrl
Definition: ilias.php:18
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
create()
Save list.
This class represents a property in a property form.
This class represents a number property in a property form.
$values
displayValidationError()
display validation errors
getValues()
Get current values for list from.
saveProperties()
Save properties.
setOptions($a_options)
Set Options.
getCharacteristics()
Get characteristics.
Class ilPCList.
executeCommand()
execute command
setMaxLength($a_maxlength)
Set Max Length.
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
edit()
edit properties form
This class represents an advanced selection list property in a property form.
$_POST["username"]
$html
Definition: example_001.php:87
initListForm($a_mode="edit")
Init list form.