ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
27  {
28  global $DIC;
29 
30  $this->tpl = $DIC["tpl"];
31  $this->lng = $DIC->language();
32  $this->ctrl = $DIC->ctrl();
33  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
34 
36  }
37 
41  public static function _getStandardCharacteristics()
42  {
43  global $DIC;
44 
45  $lng = $DIC->language();
46 
47  return array("Block" => $lng->txt("cont_Block"),
48  "Mnemonic" => $lng->txt("cont_Mnemonic"),
49  "Remark" => $lng->txt("cont_Remark"),
50  "Example" => $lng->txt("cont_Example"),
51  "Additional" => $lng->txt("cont_Additional"),
52  "Special" => $lng->txt("cont_Special"),
53 
54  "Attention" => $lng->txt("cont_Attention"),
55  "Background" => $lng->txt("cont_Background"),
56  "Confirmation" => $lng->txt("cont_Confirmation"),
57  "Information" => $lng->txt("cont_Information"),
58  "Interaction" => $lng->txt("cont_Interaction"),
59  "Link" => $lng->txt("cont_Link"),
60  "Literature" => $lng->txt("cont_Literature"),
61  "Separator" => $lng->txt("cont_Separator"),
62  "StandardCenter" => $lng->txt("cont_StandardCenter"),
63 
64  "Excursus" => $lng->txt("cont_Excursus"),
65  "AdvancedKnowledge" => $lng->txt("cont_AdvancedKnowledge"));
66  }
67 
71  public static function _getCharacteristics($a_style_id)
72  {
74 
75  if ($a_style_id > 0 &&
76  ilObject::_lookupType($a_style_id) == "sty") {
77  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
78  $style = new ilObjStyleSheet($a_style_id);
79  $chars = $style->getCharacteristics("section");
80  $new_chars = array();
81  foreach ($chars as $char) {
82  if ($chars[$char] != "") { // keep lang vars for standard chars
83  $new_chars[$char] = $chars[$char];
84  } else {
85  $new_chars[$char] = $char;
86  }
87  asort($new_chars);
88  }
89  $chars = $new_chars;
90  }
91  return $chars;
92  }
93 
97  public function executeCommand()
98  {
99  $this->getCharacteristicsOfCurrentStyle("section"); // scorm-2004
100 
101  // get next class that processes or forwards current command
102  $next_class = $this->ctrl->getNextClass($this);
103 
104  // get current command
105  $cmd = $this->ctrl->getCmd();
106 
107  switch ($next_class) {
108  case "ilpropertyformgui":
109  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
110  $form = $this->initForm(true);
111  $this->ctrl->forwardCommand($form);
112  break;
113 
114  default:
115  $ret = $this->$cmd();
116  break;
117  }
118 
119  return $ret;
120  }
121 
125  public function insert(ilPropertyFormGUI $a_form = null)
126  {
127  $this->edit(true, $a_form);
128  }
129 
133  public function edit($a_insert = false, ilPropertyFormGUI $a_form = null)
134  {
135  $tpl = $this->tpl;
136 
137  $this->displayValidationError();
138 
139  if (!$a_form) {
140  $a_form = $this->initForm($a_insert);
141  }
142 
143  $tpl->setContent($a_form->getHTML());
144  }
145 
149  public function initForm($a_insert = false)
150  {
151  $lng = $this->lng;
153 
154  // edit form
155  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
156  $form = new ilPropertyFormGUI();
157  $form->setFormAction($ilCtrl->getFormAction($this));
158  if ($a_insert) {
159  $form->setTitle($this->lng->txt("cont_insert_section"));
160  } else {
161  $form->setTitle($this->lng->txt("cont_update_section"));
162  }
163 
164  // characteristic selection
165  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
166  $char_prop = new ilAdvSelectInputGUI(
167  $this->lng->txt("cont_characteristic"),
168  "characteristic"
169  );
170 
171  $chars = $this->getCharacteristics();
172  if (is_object($this->content_obj)) {
173  if ($chars[$a_seleted_value] == "" && ($this->content_obj->getCharacteristic() != "")) {
174  $chars = array_merge(
175  array($this->content_obj->getCharacteristic() => $this->content_obj->getCharacteristic()),
176  $chars
177  );
178  }
179  }
180 
181  $selected = ($a_insert)
182  ? "Block"
183  : $this->content_obj->getCharacteristic();
184 
185  foreach ($chars as $k => $char) {
186  $html = '<div class="ilCOPgEditStyleSelectionItem"><div class="ilc_section_' . $k . '" style="' . self::$style_selector_reset . '">' .
187  $char . '</div></div>';
188  $char_prop->addOption($k, $char, $html);
189  }
190 
191  $char_prop->setValue($selected);
192  $form->addItem($char_prop);
193 
194  // link input
195  include_once 'Services/Form/classes/class.ilLinkInputGUI.php';
196  $ac = new ilLinkInputGUI($this->lng->txt('cont_link'), 'link');
198  $ac->setRequired(false);
199  $ac->setInfo($this->lng->txt("copg_sec_link_info"));
200  $ac->setInternalLinkDefault(
201  $this->getPageConfig()->getIntLinkHelpDefaultType(),
202  $this->getPageConfig()->getIntLinkHelpDefaultId()
203  );
204  $link_types = array();
205  foreach ($this->getPageConfig()->getIntLinkFilters() as $f) {
206  $link_types[] = $f;
207  }
208  $ac->setInternalLinkFilterTypes($link_types);
209  $ac->setFilterWhiteList(
210  $this->getPageConfig()->getIntLinkFilterWhiteList()
211  );
212 
213  if (!$a_insert) {
214  $l = $this->content_obj->getLink();
215  if ($l["LinkType"] == "IntLink") {
216  $ac->setValueByIntLinkAttributes($l["Type"], $l["Target"], $l["TargetFrame"]);
217  }
218  if ($l["LinkType"] == "ExtLink") {
219  $ac->setValue($l["Href"]);
220  }
221  }
222  $form->addItem($ac);
223 
224  // activation
225 
226  // active from
227  $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_from"), "active_from");
228  if (!$a_insert && ($from = $this->content_obj->getActiveFrom()) != "") {
229  $dt_prop->setDate(new ilDateTime($from, IL_CAL_UNIX));
230  }
231  $dt_prop->setShowTime(true);
232  $form->addItem($dt_prop);
233 
234  // active to
235  $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_to"), "active_to");
236  if (!$a_insert && ($to = $this->content_obj->getActiveTo()) != "") {
237  $dt_prop->setDate(new ilDateTime($to, IL_CAL_UNIX));
238  }
239  $dt_prop->setShowTime(true);
240  $form->addItem($dt_prop);
241 
242  // rep selector
243  if ($this->getPageConfig()->getEnablePermissionChecks()) {
244  include_once("./Services/Form/classes/class.ilRepositorySelector2InputGUI.php");
245  $rs = new ilRepositorySelector2InputGUI($lng->txt("cont_permission_object"), "permission_ref_id");
246  $rs->setParent($this);
247  $form->addItem($rs);
248 
249  // permission
250  $options = array(
251  "read" => $lng->txt("read"),
252  "write" => $lng->txt("write"),
253  "visible" => $lng->txt("visible"),
254  );
255  $si = new ilSelectInputGUI($lng->txt("permission"), "permission");
256  $si->setInfo($lng->txt("cont_permission_object_desc"));
257  $si->setOptions($options);
258  $form->addItem($si);
259 
260  if (!$a_insert) {
261  $si->setValue($this->content_obj->getPermission());
262  $rs->setValue($this->content_obj->getPermissionRefId());
263  }
264  }
265 
266  // save/cancel buttons
267  if ($a_insert) {
268  $form->addCommandButton("create_section", $lng->txt("save"));
269  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
270  } else {
271  $form->addCommandButton("update", $lng->txt("save"));
272  $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
273  }
274  return $form;
275  }
276 
277 
281  public function create()
282  {
283  $form = $this->initForm(true);
284  if ($form->checkInput()) {
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  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
293  }
294  }
295 
296  $this->insert($form);
297  }
298 
302  public function update()
303  {
304  $form = $this->initForm(false);
305  if ($form->checkInput()) {
306  $this->setValuesFromForm($form);
307 
308  $this->updated = $this->pg_obj->update();
309  if ($this->updated === true) {
310  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
311  }
312  }
313 
314  $this->pg_obj->addHierIDs();
315  $this->edit(false, $form);
316  }
317 
323  public function setValuesFromForm($form)
324  {
325  $this->content_obj->setCharacteristic($_POST["characteristic"]);
326 
327  $from = $form->getItemByPostVar("active_from")->getDate();
328  if ($from) {
329  $this->content_obj->setActiveFrom($from->get(IL_CAL_UNIX));
330  } else {
331  $this->content_obj->setActiveFrom(0);
332  }
333 
334  $to = $form->getItemByPostVar("active_to")->getDate();
335  if ($to) {
336  $this->content_obj->setActiveTo($to->get(IL_CAL_UNIX));
337  } else {
338  $this->content_obj->setActiveTo(0);
339  }
340 
341  if ($this->getPageConfig()->getEnablePermissionChecks()) {
342  $this->content_obj->setPermissionRefId($_POST["permission_ref_id"]);
343  $this->content_obj->setPermission($_POST["permission"]);
344  }
345 
346  if ($_POST["link_mode"] == "ext" && $_POST["link"] != "") {
347  $this->content_obj->setExtLink($_POST["link"]);
348  } elseif ($_POST["link_mode"] == "int" && $_POST["link"] != "") {
349  // $_POST["link"] is "crs|96", "chap|2", "term|1", "wpage|1"
350  // var_dump($_POST);
351  $la = $form->getItemByPostVar("link")->getIntLinkAttributes();
352  // echo "<br>";
353  // var_dump($la); exit;
354  if ($la["Type"] != "") {
355  $this->content_obj->setIntLink($la["Type"], $la["Target"], $la["TargetFrame"]);
356  }
357  } else {
358  $this->content_obj->setNoLink();
359  }
360  }
361 }
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.
global $DIC
Definition: saml.php:7
initForm($a_insert=false)
Init editing form.
static _getStandardCharacteristics()
Get standard characteristics.
$from
const IL_CAL_UNIX
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(isset($_POST['submit'])) $form
update()
Update Section.
displayValidationError()
display validation errors
setDate(ilDateTime $a_date=null)
set date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilDateTim...
Date and time handling
insert(ilPropertyFormGUI $a_form=null)
Insert new section form.
getCharacteristics()
Get characteristics.
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)