ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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  $form = $this->initForm($a_insert);
120 
121  $html = $form->getHTML();
122  $tpl->setContent($html);
123  }
124 
128  public function initForm($a_insert = false)
129  {
130  global $lng, $ilCtrl;
131 
132  // edit form
133  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
134  $form = new ilPropertyFormGUI();
135  $form->setFormAction($ilCtrl->getFormAction($this));
136  if ($a_insert)
137  {
138  $form->setTitle($this->lng->txt("cont_insert_section"));
139  }
140  else
141  {
142  $form->setTitle($this->lng->txt("cont_update_section"));
143  }
144 
145  // characteristic selection
146  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
147  $char_prop = new ilAdvSelectInputGUI($this->lng->txt("cont_characteristic"),
148  "characteristic");
149 
150  $chars = $this->getCharacteristics();
151  if (is_object($this->content_obj))
152  {
153  if ($chars[$a_seleted_value] == "" && ($this->content_obj->getCharacteristic() != ""))
154  {
155  $chars = array_merge(
156  array($this->content_obj->getCharacteristic() => $this->content_obj->getCharacteristic()),
157  $chars);
158  }
159  }
160 
161  $selected = ($a_insert)
162  ? "Block"
163  : $this->content_obj->getCharacteristic();
164 
165  foreach($chars as $k => $char)
166  {
167  $html = '<div class="ilCOPgEditStyleSelectionItem"><div class="ilc_section_'.$k.'" style="'.self::$style_selector_reset.'">'.
168  $char.'</div></div>';
169  $char_prop->addOption($k, $char, $html);
170  }
171 
172  $char_prop->setValue($selected);
173  $form->addItem($char_prop);
174 
175  // active from
176  $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_from"), "active_from");
177  if (!$a_insert && ($from = $this->content_obj->getActiveFrom()) != "")
178  {
179  $dt_prop->setDate(new ilDateTime($from, IL_CAL_UNIX));
180  }
181  $dt_prop->setMode(ilDateTimeInputGUI::MODE_INPUT);
182  $dt_prop->setShowTime(true);
183  $form->addItem($dt_prop);
184 
185  // active to
186  $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_to"), "active_to");
187  if (!$a_insert && ($to = $this->content_obj->getActiveTo()) != "")
188  {
189  $dt_prop->setDate(new ilDateTime($to, IL_CAL_UNIX));
190  }
191  $dt_prop->setMode(ilDateTimeInputGUI::MODE_INPUT);
192  $dt_prop->setShowTime(true);
193  $form->addItem($dt_prop);
194 
195  // save/cancel buttons
196  if ($a_insert)
197  {
198  $form->addCommandButton("create_section", $lng->txt("save"));
199  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
200  }
201  else
202  {
203  $form->addCommandButton("update", $lng->txt("save"));
204  $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
205  }
206 
207  return $form;
208  }
209 
210 
214  function create()
215  {
216  $form = $this->initForm(true);
217  $form->checkInput();
218 
219  $this->content_obj = new ilPCSection($this->getPage());
220  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
221 
222  $this->setValuesFromForm($form);
223 
224 
225  $this->updated = $this->pg_obj->update();
226  if ($this->updated === true)
227  {
228  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
229  }
230  else
231  {
232  $this->insert();
233  }
234  }
235 
239  function update()
240  {
241  $form = $this->initForm(false);
242  $form->checkInput();
243 
244  $this->setValuesFromForm($form);
245 
246  $this->updated = $this->pg_obj->update();
247  if ($this->updated === true)
248  {
249  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
250  }
251  else
252  {
253  $this->pg_obj->addHierIDs();
254  $this->edit();
255  }
256  }
257 
263  function setValuesFromForm($form)
264  {
265  $this->content_obj->setCharacteristic($_POST["characteristic"]);
266 
267  if ($_POST["active_from"]["date"] != "" &&
268  $from = $form->getItemByPostVar("active_from")->getDate())
269  {
270  $this->content_obj->setActiveFrom($from->get(IL_CAL_UNIX));
271  }
272  else
273  {
274  $this->content_obj->setActiveFrom(0);
275  }
276 
277  if ($_POST["active_to"]["date"] != "" &&
278  $to = $form->getItemByPostVar("active_to")->getDate())
279  {
280  $this->content_obj->setActiveTo($to->get(IL_CAL_UNIX));
281  }
282  else
283  {
284  $this->content_obj->setActiveTo(0);
285  }
286 
287  }
288 
289 }
290 ?>
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
insert()
Insert new section form.
$style
Definition: example_012.php:70
$_POST['username']
Definition: cron.php:12
This class represents a property form user interface.
setValuesFromForm($form)
Set values from form.
create()
Create new Section.
ilPCSectionGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
initForm($a_insert=false)
Init editing form.
$cmd
Definition: sahs_server.php:35
static _getStandardCharacteristics()
Get standard characteristics.
const IL_CAL_UNIX
setDate(ilDateTime $a_date=NULL)
set date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilDateTim...
Class ilPCSection.
This class represents a date/time property in a property form.
global $ilCtrl
Definition: ilias.php:18
setCharacteristics($a_chars)
Set Characteristics.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
static _getCharacteristics($a_style_id)
Get characteristics.
update()
Update Section.
displayValidationError()
display validation errors
Date and time handling
edit($a_insert=false)
Edit section form.
getCharacteristics()
Get characteristics.
static _lookupType($a_id, $a_reference=false)
lookup object type
& executeCommand()
execute command
Class ilPCSectionGUI.
Class ilObjStyleSheet.
This class represents an advanced selection list property in a property form.
$html
Definition: example_001.php:87