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