ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  function ilPCListGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
25  {
26  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
27  }
28 
32  function &executeCommand()
33  {
34  // get next class that processes or forwards current command
35  $next_class = $this->ctrl->getNextClass($this);
36 
37  // get current command
38  $cmd = $this->ctrl->getCmd();
39 
40  switch($next_class)
41  {
42  default:
43  $ret =& $this->$cmd();
44  break;
45  }
46 
47  return $ret;
48  }
49 
50 
54  function insert()
55  {
56  $this->displayValidationError();
57 
58  $this->initListForm("create");
59  $this->tpl->setContent($this->form->getHTML());
60  }
61 
62 
66  public function create()
67  {
68  global $tpl, $lng, $ilCtrl;
69 
70  $this->initListForm("create");
71  if ($this->form->checkInput())
72  {
73  $this->content_obj = new ilPCList($this->dom);
74  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
75  $this->content_obj->addItems($_POST["nr_items"]);
76  $this->content_obj->setStartValue($_POST["start_value"]);
77  $this->content_obj->setListType($_POST["list_type"]);
78  if ($_POST["list_type"] == "Unordered")
79  {
80  $this->content_obj->setNumberingType("");
81  $this->content_obj->setStyleClass($_POST["bullet_style"]);
82  }
83  else
84  {
85  $this->content_obj->setNumberingType($_POST["numbering_type"]);
86  $this->content_obj->setStyleClass($_POST["number_style"]);
87  }
88  $this->updated = $this->pg_obj->update();
89  if ($this->updated === true)
90  {
91  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
92  }
93  }
94  $this->form->setValuesByPost();
95  $tpl->setContent($this->form->getHtml());
96  }
97 
101  function edit()
102  {
103  $this->displayValidationError();
104 
105  $this->initListForm("edit");
106  $this->getValues();
107  $this->tpl->setContent($this->form->getHTML());
108  }
109 
113  function saveProperties()
114  {
115  global $lng, $ilCtrl, $tpl;
116 
117  $this->initListForm("edit");
118  if ($this->form->checkInput())
119  {
120  $this->content_obj->setStartValue($_POST["start_value"]);
121  $this->content_obj->setListType($_POST["list_type"]);
122  if ($_POST["list_type"] == "Unordered")
123  {
124  $this->content_obj->setNumberingType("");
125  $this->content_obj->setStyleClass($_POST["bullet_style"]);
126  }
127  else
128  {
129  $this->content_obj->setNumberingType($_POST["numbering_type"]);
130  $this->content_obj->setStyleClass($_POST["number_style"]);
131  }
132 
133  $this->updated = $this->pg_obj->update();
134  if ($this->updated === true)
135  {
136  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
137  }
138  }
139  $this->form->setValuesByPost();
140  $tpl->setContent($this->form->getHtml());
141  }
142 
148  public function initListForm($a_mode = "edit")
149  {
150  global $lng;
151  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
152  $this->form = new ilPropertyFormGUI();
153 
154  // type
155  $radg = new ilRadioGroupInputGUI($lng->txt("type"), "list_type");
156  $op1 = new ilRadioOption($lng->txt("cont_bullet_list"), "Unordered");
157 
158  // style of bullet list
159  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
160  $style = new ilAdvSelectInputGUI($this->lng->txt("cont_style"),
161  "bullet_style");
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  {
168  $options[$this->content_obj->getStyleClass()] =
169  $this->content_obj->getStyleClass();
170  }
171  if (count($options) > 1)
172  {
173  foreach($options as $k => $option)
174  {
175  $html = '<ul class="ilc_list_u_'.$k.'"><li class="ilc_list_item_StandardListItem">'.
176  $option.'</li></ul>';
177  if ($k == "BulletedList")
178  {
179  $k = "";
180  }
181  $style->addOption($k, $option, $html);
182  }
183  $style->setValue("");
184  $op1->addSubItem($style);
185  }
186 
187  $radg->addOption($op1);
188 
189 
190  $op2 = new ilRadioOption($lng->txt("cont_numbered_list"), "Ordered");
191 
192  // style of numbered list
193  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
194  $style = new ilAdvSelectInputGUI($this->lng->txt("cont_style"),
195  "number_style");
196  $this->getCharacteristicsOfCurrentStyle("list_o");
197  $options = $this->getCharacteristics();
198  if ($a_mode == "edit" && $this->content_obj->getListType() == "Ordered"
199  && $this->content_obj->getStyleClass() != ""
200  && !in_array($this->content_obj->getStyleClass(), $options))
201  {
202  $options[$this->content_obj->getStyleClass()] =
203  $this->content_obj->getStyleClass();
204  }
205  if (count($options) > 1)
206  {
207  foreach($options as $k => $option)
208  {
209  $html = '<ol class="ilc_list_o_'.$k.'"><li class="ilc_list_item_StandardListItem">'.
210  $option.'</li></ol>';
211  if ($k == "NumberedList")
212  {
213  $k = "";
214  }
215  $style->addOption($k, $option, $html);
216  }
217  $style->setValue("");
218  $op2->addSubItem($style);
219  }
220 
221  // numeric type
222  $options = array(
223  "Number" => $this->lng->txt("cont_number_std"),
224  "Decimal" => $this->lng->txt("cont_decimal"),
225  "Roman" => $this->lng->txt("cont_roman"),
226  "roman" => $this->lng->txt("cont_roman_s"),
227  "Alphabetic" => $this->lng->txt("cont_alphabetic"),
228  "alphabetic" => $this->lng->txt("cont_alphabetic_s")
229  );
230  $si = new ilSelectInputGUI($this->lng->txt("cont_number_type"), "numbering_type");
231  $si->setOptions($options);
232  $op2->addSubItem($si);
233 
234  // starting value
235  $ni = new ilNumberInputGUI($this->lng->txt("cont_start_value"), "start_value");
236  $ni->setMaxLength(3);
237  $ni->setSize(3);
238  $ni->setInfo($lng->txt("cont_start_value_info"));
239  $op2->addSubItem($ni);
240 
241  $radg->addOption($op2);
242  $radg->setValue("Unordered");
243  $this->form->addItem($radg);
244 
245  // nr of items
246  $options = array();
247  if ($a_mode == "create")
248  {
249  for ($i=1; $i<=10; $i++)
250  {
251  $options[$i] = $i;
252  }
253  $si = new ilSelectInputGUI($this->lng->txt("cont_nr_items"), "nr_items");
254  $si->setOptions($options);
255  $si->setValue(2);
256  $this->form->addItem($si);
257  }
258 
259  // save and cancel commands
260  if ($a_mode == "create")
261  {
262  $this->form->addCommandButton("create_list", $lng->txt("save"));
263  $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
264  $this->form->setTitle($lng->txt("cont_insert_list"));
265  }
266  else
267  {
268  $this->form->addCommandButton("saveProperties", $lng->txt("save"));
269  $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
270  $this->form->setTitle($lng->txt("cont_list_properties"));
271  }
272 
273  $this->form->setFormAction($this->ctrl->getFormAction($this));
274  }
275 
280  public function getValues()
281  {
282  global $tpl;
283 
284  $values = array();
285 
286  $values["start_value"] = $this->content_obj->getStartValue();
287  $values["list_type"] = $this->content_obj->getListType();
288  $values["numbering_type"] = $this->content_obj->getNumberingType();
289  if ($values["list_type"] == "Ordered")
290  {
291  $values["number_style"] = $this->content_obj->getStyleClass();
292  $values["bullet_style"] = "";
293  }
294  else
295  {
296  $values["bullet_style"] = $this->content_obj->getStyleClass();
297  $values["number_style"] = "";
298  }
299  $this->form->setValuesByArray($values);
300  }
301 
302 }
303 ?>