ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCSectionGUI.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.ilPCSection.php");
5 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
6 
18 {
19 
24  function ilPCSectionGUI(&$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 
29  }
30 
34  static function _getStandardCharacteristics()
35  {
36  global $lng;
37 
38  return array("Block" => $lng->txt("cont_Block"),
39  "Mnemonic" => $lng->txt("cont_Mnemonic"),
40  "Remark" => $lng->txt("cont_Remark"),
41  "Example" => $lng->txt("cont_Example"),
42  "Additional" => $lng->txt("cont_Additional"),
43  "Special" => $lng->txt("cont_Special"),
44  "Excursus" => $lng->txt("cont_Excursus"));
45  }
46 
50  static function _getCharacteristics($a_style_id)
51  {
53 
54  if ($a_style_id > 0 &&
55  ilObject::_lookupType($a_style_id) == "sty")
56  {
57  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
58  $style = new ilObjStyleSheet($a_style_id);
59  $chars = $style->getCharacteristics("section");
60  $new_chars = array();
61  foreach ($chars as $char)
62  {
63  if ($chars[$char] != "") // keep lang vars for standard chars
64  {
65  $new_chars[$char] = $chars[$char];
66  }
67  else
68  {
69  $new_chars[$char] = $char;
70  }
71  asort($new_chars);
72  }
73  $chars = $new_chars;
74  }
75  return $chars;
76  }
77 
81  function &executeCommand()
82  {
83  $this->getCharacteristicsOfCurrentStyle("section"); // scorm-2004
84 
85  // get next class that processes or forwards current command
86  $next_class = $this->ctrl->getNextClass($this);
87 
88  // get current command
89  $cmd = $this->ctrl->getCmd();
90 
91  switch($next_class)
92  {
93  default:
94  $ret =& $this->$cmd();
95  break;
96  }
97 
98  return $ret;
99  }
100 
104  function insert()
105  {
106  $this->edit(true);
107  }
108 
112  function edit($a_insert = false)
113  {
114  global $ilCtrl, $tpl, $lng;
115 
116  $this->displayValidationError();
117 
118  // edit form
119  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
120  $form = new ilPropertyFormGUI();
121  $form->setFormAction($ilCtrl->getFormAction($this));
122  if ($a_insert)
123  {
124  $form->setTitle($this->lng->txt("cont_insert_section"));
125  }
126  else
127  {
128  $form->setTitle($this->lng->txt("cont_update_section"));
129  }
130 
131  // characteristic selection
132  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
133  $char_prop = new ilAdvSelectInputGUI($this->lng->txt("cont_characteristic"),
134  "characteristic");
135 
136  $chars = $this->getCharacteristics();
137  if (is_object($this->content_obj))
138  {
139  if ($chars[$a_seleted_value] == "" && ($this->content_obj->getCharacteristic() != ""))
140  {
141  $chars = array_merge(
142  array($this->content_obj->getCharacteristic() => $this->content_obj->getCharacteristic()),
143  $chars);
144  }
145  }
146 
147  $selected = ($a_insert)
148  ? "Block"
149  : $this->content_obj->getCharacteristic();
150 
151  foreach($chars as $k => $char)
152  {
153  $html = '<div class="ilc_section_'.$k.'">'.
154  $char.'</div>';
155  $char_prop->addOption($k, $char, $html);
156  }
157 
158  $char_prop->setValue($selected);
159  $form->addItem($char_prop);
160 
161  // save/cancel buttons
162  if ($a_insert)
163  {
164  $form->addCommandButton("create_section", $lng->txt("save"));
165  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
166  }
167  else
168  {
169  $form->addCommandButton("update", $lng->txt("save"));
170  $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
171  }
172  $html = $form->getHTML();
173  $tpl->setContent($html);
174  return $ret;
175 
176  }
177 
178 
182  function create()
183  {
184  $this->content_obj = new ilPCSection($this->dom);
185  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
186  $this->content_obj->setCharacteristic($_POST["characteristic"]);
187  $this->updated = $this->pg_obj->update();
188  if ($this->updated === true)
189  {
190  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
191  }
192  else
193  {
194  $this->insert();
195  }
196  }
197 
201  function update()
202  {
203  $this->content_obj->setCharacteristic($_POST["characteristic"]);
204  $this->updated = $this->pg_obj->update();
205  if ($this->updated === true)
206  {
207  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
208  }
209  else
210  {
211  $this->pg_obj->addHierIDs();
212  $this->edit();
213  }
214  }
215 }
216 ?>