ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
20 {
21 
26  function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
27  {
28  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
29 
31  }
32 
36  static function _getStandardCharacteristics()
37  {
38  global $lng;
39 
40  return array("Block" => $lng->txt("cont_Block"),
41  "Mnemonic" => $lng->txt("cont_Mnemonic"),
42  "Remark" => $lng->txt("cont_Remark"),
43  "Example" => $lng->txt("cont_Example"),
44  "Additional" => $lng->txt("cont_Additional"),
45  "Special" => $lng->txt("cont_Special"),
46  "Excursus" => $lng->txt("cont_Excursus"),
47  "AdvancedKnowledge" => $lng->txt("cont_AdvancedKnowledge"));
48  }
49 
53  static function _getCharacteristics($a_style_id)
54  {
56 
57  if ($a_style_id > 0 &&
58  ilObject::_lookupType($a_style_id) == "sty")
59  {
60  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
61  $style = new ilObjStyleSheet($a_style_id);
62  $chars = $style->getCharacteristics("section");
63  $new_chars = array();
64  foreach ($chars as $char)
65  {
66  if ($chars[$char] != "") // keep lang vars for standard chars
67  {
68  $new_chars[$char] = $chars[$char];
69  }
70  else
71  {
72  $new_chars[$char] = $char;
73  }
74  asort($new_chars);
75  }
76  $chars = $new_chars;
77  }
78  return $chars;
79  }
80 
84  function executeCommand()
85  {
86  $this->getCharacteristicsOfCurrentStyle("section"); // scorm-2004
87 
88  // get next class that processes or forwards current command
89  $next_class = $this->ctrl->getNextClass($this);
90 
91  // get current command
92  $cmd = $this->ctrl->getCmd();
93 
94  switch($next_class)
95  {
96  case "ilpropertyformgui":
97  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
98  $form = $this->initForm(true);
99  $this->ctrl->forwardCommand($form);
100  break;
101 
102  default:
103  $ret = $this->$cmd();
104  break;
105  }
106 
107  return $ret;
108  }
109 
113  function insert(ilPropertyFormGUI $a_form = null)
114  {
115  $this->edit(true, $a_form);
116  }
117 
121  function edit($a_insert = false, ilPropertyFormGUI $a_form = null)
122  {
123  global $tpl;
124 
125  $this->displayValidationError();
126 
127  if(!$a_form)
128  {
129  $a_form = $this->initForm($a_insert);
130  }
131 
132  $tpl->setContent($a_form->getHTML());
133  }
134 
138  public function initForm($a_insert = false)
139  {
140  global $lng, $ilCtrl;
141 
142  // edit form
143  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
144  $form = new ilPropertyFormGUI();
145  $form->setFormAction($ilCtrl->getFormAction($this));
146  if ($a_insert)
147  {
148  $form->setTitle($this->lng->txt("cont_insert_section"));
149  }
150  else
151  {
152  $form->setTitle($this->lng->txt("cont_update_section"));
153  }
154 
155  // characteristic selection
156  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
157  $char_prop = new ilAdvSelectInputGUI($this->lng->txt("cont_characteristic"),
158  "characteristic");
159 
160  $chars = $this->getCharacteristics();
161  if (is_object($this->content_obj))
162  {
163  if ($chars[$a_seleted_value] == "" && ($this->content_obj->getCharacteristic() != ""))
164  {
165  $chars = array_merge(
166  array($this->content_obj->getCharacteristic() => $this->content_obj->getCharacteristic()),
167  $chars);
168  }
169  }
170 
171  $selected = ($a_insert)
172  ? "Block"
173  : $this->content_obj->getCharacteristic();
174 
175  foreach($chars as $k => $char)
176  {
177  $html = '<div class="ilCOPgEditStyleSelectionItem"><div class="ilc_section_'.$k.'" style="'.self::$style_selector_reset.'">'.
178  $char.'</div></div>';
179  $char_prop->addOption($k, $char, $html);
180  }
181 
182  $char_prop->setValue($selected);
183  $form->addItem($char_prop);
184 
185  // link input
186  include_once 'Services/Form/classes/class.ilLinkInputGUI.php';
187  $ac = new ilLinkInputGUI($this->lng->txt('cont_link'), 'link');
189  $ac->setRequired(false);
190  $ac->setInfo($this->lng->txt("copg_sec_link_info"));
191  $ac->setInternalLinkDefault($this->getPageConfig()->getIntLinkHelpDefaultType(),
192  $this->getPageConfig()->getIntLinkHelpDefaultId());
193  $link_types = array();
194  foreach ($this->getPageConfig()->getIntLinkFilters() as $f)
195  {
196  $link_types[] = $f;
197  }
198  $ac->setInternalLinkFilterTypes($link_types);
199  $ac->setFilterWhiteList(
200  $this->getPageConfig()->getIntLinkFilterWhiteList());
201 
202  if (!$a_insert)
203  {
204  $l = $this->content_obj->getLink();
205  if ($l["LinkType"] == "IntLink")
206  {
207  $ac->setValueByIntLinkAttributes($l["Type"], $l["Target"], $l["TargetFrame"]);
208  }
209  if ($l["LinkType"] == "ExtLink")
210  {
211  $ac->setValue($l["Href"]);
212  }
213  }
214  $form->addItem($ac);
215 
216  // activation
217 
218  // active from
219  $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_from"), "active_from");
220  if (!$a_insert && ($from = $this->content_obj->getActiveFrom()) != "")
221  {
222  $dt_prop->setDate(new ilDateTime($from, IL_CAL_UNIX));
223  }
224  $dt_prop->setShowTime(true);
225  $form->addItem($dt_prop);
226 
227  // active to
228  $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_to"), "active_to");
229  if (!$a_insert && ($to = $this->content_obj->getActiveTo()) != "")
230  {
231  $dt_prop->setDate(new ilDateTime($to, IL_CAL_UNIX));
232  }
233  $dt_prop->setShowTime(true);
234  $form->addItem($dt_prop);
235 
236  // rep selector
237  if ($this->getPageConfig()->getEnablePermissionChecks())
238  {
239  include_once("./Services/Form/classes/class.ilRepositorySelector2InputGUI.php");
240  $rs = new ilRepositorySelector2InputGUI($lng->txt("cont_permission_object"), "permission_ref_id");
241  $rs->setParent($this);
242  $form->addItem($rs);
243 
244  // permission
245  $options = array(
246  "read" => $lng->txt("read"),
247  "write" => $lng->txt("write"),
248  "visible" => $lng->txt("visible"),
249  );
250  $si = new ilSelectInputGUI($lng->txt("permission"), "permission");
251  $si->setInfo($lng->txt("cont_permission_object_desc"));
252  $si->setOptions($options);
253  $form->addItem($si);
254 
255  if (!$a_insert)
256  {
257  $si->setValue($this->content_obj->getPermission());
258  $rs->setValue($this->content_obj->getPermissionRefId());
259  }
260  }
261 
262  // save/cancel buttons
263  if ($a_insert)
264  {
265  $form->addCommandButton("create_section", $lng->txt("save"));
266  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
267  }
268  else
269  {
270  $form->addCommandButton("update", $lng->txt("save"));
271  $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
272  }
273  return $form;
274  }
275 
276 
280  function create()
281  {
282  $form = $this->initForm(true);
283  if($form->checkInput())
284  {
285  $this->content_obj = new ilPCSection($this->getPage());
286  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
287 
288  $this->setValuesFromForm($form);
289 
290  $this->updated = $this->pg_obj->update();
291  if ($this->updated === true)
292  {
293  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
294  }
295  }
296 
297  $this->insert($form);
298  }
299 
303  function update()
304  {
305  $form = $this->initForm(false);
306  if($form->checkInput())
307  {
308  $this->setValuesFromForm($form);
309 
310  $this->updated = $this->pg_obj->update();
311  if ($this->updated === true)
312  {
313  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
314  }
315  }
316 
317  $this->pg_obj->addHierIDs();
318  $this->edit(false, $form);
319  }
320 
326  function setValuesFromForm($form)
327  {
328  $this->content_obj->setCharacteristic($_POST["characteristic"]);
329 
330  $from = $form->getItemByPostVar("active_from")->getDate();
331  if ($from)
332  {
333  $this->content_obj->setActiveFrom($from->get(IL_CAL_UNIX));
334  }
335  else
336  {
337  $this->content_obj->setActiveFrom(0);
338  }
339 
340  $to = $form->getItemByPostVar("active_to")->getDate();
341  if ($to)
342  {
343  $this->content_obj->setActiveTo($to->get(IL_CAL_UNIX));
344  }
345  else
346  {
347  $this->content_obj->setActiveTo(0);
348  }
349 
350  if ($this->getPageConfig()->getEnablePermissionChecks())
351  {
352  $this->content_obj->setPermissionRefId($_POST["permission_ref_id"]);
353  $this->content_obj->setPermission($_POST["permission"]);
354  }
355 
356  if ($_POST["link_mode"] == "ext" && $_POST["link"] != "")
357  {
358  $this->content_obj->setExtLink($_POST["link"]);
359  }
360  else if ($_POST["link_mode"] == "int" && $_POST["link"] != "")
361  {
362  // $_POST["link"] is "crs|96", "chap|2", "term|1", "wpage|1"
363 // var_dump($_POST);
364  $la = $form->getItemByPostVar("link")->getIntLinkAttributes();
365 // echo "<br>";
366 // var_dump($la); exit;
367  if ($la["Type"] != "")
368  {
369  $this->content_obj->setIntLink($la["Type"], $la["Target"], $la["TargetFrame"]);
370  }
371  }
372  else
373  {
374  $this->content_obj->setNoLink();
375  }
376  }
377 
378 }
379 ?>
executeCommand()
execute command
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
$style
Definition: example_012.php:70
edit($a_insert=false, ilPropertyFormGUI $a_form=null)
Edit section form.
This class represents a selection list property in a property form.
This class represents a property form user interface.
setValuesFromForm($form)
Set values from form.
create()
Create new Section.
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...
getPageConfig()
Get Page Config.
Class ilPCSection.
This class represents a date/time property in a property form.
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
setCharacteristics($a_chars)
Set Characteristics.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
setParent($a_val)
Set Parent GUI object.
static _getCharacteristics($a_style_id)
Get characteristics.
if(!is_array($argv)) $options
update()
Update Section.
displayValidationError()
display validation errors
Date and time handling
insert(ilPropertyFormGUI $a_form=null)
Insert new section form.
getCharacteristics()
Get characteristics.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilPCSectionGUI.
global $l
Definition: afr.php:30
Class ilObjStyleSheet.
$ret
Definition: parser.php:6
This class represents an advanced selection list property in a property form.
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
$_POST["username"]
$html
Definition: example_001.php:87
This class represents a external and/or internal link in a property form.
setAllowedLinkTypes($a_val)
Set allowed link types (BOTH, INT, EXT)