ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4require_once("./Services/COPage/classes/class.ilPCSection.php");
5require_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
43 public function getHTML(array $params)
44 {
45 $this->getCharacteristicsOfCurrentStyle("section");
46
47 if ($params["form"] == true) {
48 $insert = (bool) !($this->content_obj);
49 $form = $this->initForm($insert);
50 $form->setShowTopButtons(false);
51
52 $from = $form->getItemByPostVar("active_from");
53 $from->setSideBySide(false);
54 $on_load_code1 = $from->getOnloadCode();
55 $to = $form->getItemByPostVar("active_to");
56 $to->setSideBySide(false);
57 $on_load_code2 = $to->getOnloadCode();
58
59 $rep_sel = $form->getItemByPostVar("permission_ref_id");
60 $on_load_code3 = "";
61 if ($rep_sel) {
62 $exp = $rep_sel->getExplorerGUI();
63 $this->ctrl->setParameterByClass("ilformpropertydispatchgui", "postvar", "permission_ref_id");
64 $on_load_code3 = $exp->getOnloadCode();
65 $this->ctrl->setParameterByClass("ilformpropertydispatchgui", "postvar", "");
66 }
67
68 $html = $params["ui_wrapper"]->getRenderedForm(
69 $form,
70 $params["buttons"]
71 );
72
73 $html .= "<script>" .
74 implode("\n", array_merge($on_load_code1, $on_load_code2)) .
75 "\n" . $on_load_code3 .
76 "</script>";
77
78 return $html;
79 }
80 return "";
81 }
82
86 public static function _getStandardCharacteristics()
87 {
88 global $DIC;
89
90 $lng = $DIC->language();
91
92 return array("Block" => $lng->txt("cont_Block"),
93 "Mnemonic" => $lng->txt("cont_Mnemonic"),
94 "Remark" => $lng->txt("cont_Remark"),
95 "Example" => $lng->txt("cont_Example"),
96 "Additional" => $lng->txt("cont_Additional"),
97 "Special" => $lng->txt("cont_Special"),
98
99 "Attention" => $lng->txt("cont_Attention"),
100 "Background" => $lng->txt("cont_Background"),
101 "Citation" => $lng->txt("cont_Citation"),
102 "Confirmation" => $lng->txt("cont_Confirmation"),
103 "Information" => $lng->txt("cont_Information"),
104 "Interaction" => $lng->txt("cont_Interaction"),
105 "Link" => $lng->txt("cont_Link"),
106 "Literature" => $lng->txt("cont_Literature"),
107 "Separator" => $lng->txt("cont_Separator"),
108 "StandardCenter" => $lng->txt("cont_StandardCenter"),
109
110 "Excursus" => $lng->txt("cont_Excursus"),
111 "AdvancedKnowledge" => $lng->txt("cont_AdvancedKnowledge"));
112 }
113
117 public static function _getCharacteristics($a_style_id)
118 {
120 $chars = $std_chars;
121 if ($a_style_id > 0 &&
122 ilObject::_lookupType($a_style_id) == "sty") {
123 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
124 $style = new ilObjStyleSheet($a_style_id);
125 $chars = $style->getCharacteristics("section");
126 $new_chars = array();
127 foreach ($chars as $char) {
128 if (($std_chars[$char] ?? "") != "") { // keep lang vars for standard chars
129 $new_chars[$char] = $std_chars[$char];
130 } else {
131 $new_chars[$char] = $char;
132 }
133 asort($new_chars);
134 }
135 $chars = $new_chars;
136 }
137 return $chars;
138 }
139
143 public function executeCommand()
144 {
145 $this->getCharacteristicsOfCurrentStyle("section"); // scorm-2004
146
147 // get next class that processes or forwards current command
148 $next_class = $this->ctrl->getNextClass($this);
149
150 // get current command
151 $cmd = $this->ctrl->getCmd();
152
153 switch ($next_class) {
154 case "ilpropertyformgui":
155 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
156 $form = $this->initForm(true);
157 $this->ctrl->forwardCommand($form);
158 break;
159
160 default:
161 $ret = $this->$cmd();
162 break;
163 }
164
165 return $ret;
166 }
167
171 public function insert(ilPropertyFormGUI $a_form = null)
172 {
173 $this->edit(true, $a_form);
174 }
175
179 public function edit($a_insert = false, ilPropertyFormGUI $a_form = null)
180 {
182
183 $this->displayValidationError();
184
185 if (!$a_form) {
186 $a_form = $this->initForm($a_insert);
187 }
188
189 $tpl->setContent($a_form->getHTML());
190 }
191
195 public function initForm($a_insert = false)
196 {
198 $ilCtrl = $this->ctrl;
199
200 // edit form
201 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
202 $form = new ilPropertyFormGUI();
203 $form->setFormAction($ilCtrl->getFormAction($this));
204 if ($a_insert) {
205 $form->setTitle($this->lng->txt("cont_insert_section"));
206 } else {
207 $form->setTitle($this->lng->txt("cont_update_section"));
208 }
209
210 // characteristic selection
211 require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
212 $char_prop = new ilAdvSelectInputGUI(
213 $this->lng->txt("cont_characteristic"),
214 "characteristic"
215 );
216 $chars = $this->getCharacteristics();
217 if (is_object($this->content_obj)) {
218 if ($chars[$a_seleted_value] == "" && ($this->content_obj->getCharacteristic() != "")) {
219 $chars = array_merge(
220 array($this->content_obj->getCharacteristic() => $this->content_obj->getCharacteristic()),
221 $chars
222 );
223 }
224 }
225
226 $selected = ($a_insert)
227 ? "Block"
228 : $this->content_obj->getCharacteristic();
229
230 foreach ($chars as $k => $char) {
231 $html = '<div class="ilCOPgEditStyleSelectionItem"><div class="ilc_section_' . $k . '" style="' . self::$style_selector_reset . '">' .
232 $char . '</div></div>';
233 $char_prop->addOption($k, $char, $html);
234 }
235
236 $char_prop->setValue($selected);
237 $form->addItem($char_prop);
238
239 // link input
240 include_once 'Services/Form/classes/class.ilLinkInputGUI.php';
241 $ac = new ilLinkInputGUI($this->lng->txt('cont_link'), 'link');
242 if ($this->getPageConfig()->getEnableInternalLinks()) {
243 $ac->setAllowedLinkTypes(ilLinkInputGUI::BOTH);
244 } else {
245 $ac->setAllowedLinkTypes(ilLinkInputGUI::EXT);
246 }
247 $ac->setRequired(false);
248 $ac->setInfo($this->lng->txt("copg_sec_link_info"));
249 $ac->setInternalLinkDefault(
250 $this->getPageConfig()->getIntLinkHelpDefaultType(),
251 $this->getPageConfig()->getIntLinkHelpDefaultId()
252 );
253 $link_types = array();
254 foreach ($this->getPageConfig()->getIntLinkFilters() as $f) {
255 $link_types[] = $f;
256 }
257 $ac->setInternalLinkFilterTypes($link_types);
258 $ac->setFilterWhiteList(
259 $this->getPageConfig()->getIntLinkFilterWhiteList()
260 );
261
262 if (!$a_insert) {
263 $l = $this->content_obj->getLink();
264 if ($l["LinkType"] == "IntLink") {
265 $ac->setValueByIntLinkAttributes($l["Type"], $l["Target"], $l["TargetFrame"]);
266 }
267 if ($l["LinkType"] == "ExtLink") {
268 $ac->setValue($l["Href"]);
269 }
270 }
271 $form->addItem($ac);
272
273 // activation
274
275 // active from
276 $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_from"), "active_from");
277 if (!$a_insert && ($from = $this->content_obj->getActiveFrom()) != "") {
278 $dt_prop->setDate(new ilDateTime($from, IL_CAL_UNIX));
279 }
280 $dt_prop->setShowTime(true);
281 $form->addItem($dt_prop);
282
283 // active to
284 $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_to"), "active_to");
285 if (!$a_insert && ($to = $this->content_obj->getActiveTo()) != "") {
286 $dt_prop->setDate(new ilDateTime($to, IL_CAL_UNIX));
287 }
288 $dt_prop->setShowTime(true);
289 $form->addItem($dt_prop);
290
291 // rep selector
292 if ($this->getPageConfig()->getEnablePermissionChecks()) {
293 include_once("./Services/Form/classes/class.ilRepositorySelector2InputGUI.php");
294 $rs = new ilRepositorySelector2InputGUI($lng->txt("cont_permission_object"), "permission_ref_id");
295 $rs->setParent($this);
296 $form->addItem($rs);
297
298 // permission
299 $options = array(
300 "read" => $lng->txt("read"),
301 "write" => $lng->txt("write"),
302 "visible" => $lng->txt("visible"),
303 "no_read" => $lng->txt("cont_no_read")
304 );
305 $si = new ilSelectInputGUI($lng->txt("permission"), "permission");
306 $si->setInfo($lng->txt("cont_permission_object_desc"));
307 $si->setOptions($options);
308 $form->addItem($si);
309
310 if (!$a_insert) {
311 $si->setValue($this->content_obj->getPermission());
312 $rs->setValue($this->content_obj->getPermissionRefId());
313 }
314 }
315
316 // save/cancel buttons
317 if ($a_insert) {
318 $form->addCommandButton("create_section", $lng->txt("save"));
319 $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
320 } else {
321 $form->addCommandButton("update", $lng->txt("save"));
322 $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
323 }
324 return $form;
325 }
326
327
331 public function create()
332 {
333 $form = $this->initForm(true);
334 if ($form->checkInput()) {
335 $this->content_obj = new ilPCSection($this->getPage());
336 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
337
338 $this->setValuesFromForm($form);
339
340 $this->updated = $this->pg_obj->update();
341 if ($this->updated === true) {
342 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
343 }
344 }
345
346 $this->insert($form);
347 }
348
352 public function update()
353 {
354 $form = $this->initForm(false);
355 if ($form->checkInput()) {
356 $this->setValuesFromForm($form);
357
358 $this->updated = $this->pg_obj->update();
359 if ($this->updated === true) {
360 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
361 }
362 }
363
364 $this->pg_obj->addHierIDs();
365 $this->edit(false, $form);
366 }
367
373 public function setValuesFromForm($form)
374 {
375 $this->content_obj->setCharacteristic($_POST["characteristic"]);
376
377 $from = $form->getItemByPostVar("active_from")->getDate();
378 if ($from) {
379 $this->content_obj->setActiveFrom($from->get(IL_CAL_UNIX));
380 } else {
381 $this->content_obj->setActiveFrom(0);
382 }
383
384 $to = $form->getItemByPostVar("active_to")->getDate();
385 if ($to) {
386 $this->content_obj->setActiveTo($to->get(IL_CAL_UNIX));
387 } else {
388 $this->content_obj->setActiveTo(0);
389 }
390
391 if ($this->getPageConfig()->getEnablePermissionChecks()) {
392 $this->content_obj->setPermissionRefId($_POST["permission_ref_id"]);
393 $this->content_obj->setPermission($_POST["permission"]);
394 }
395
396 if ($_POST["link_mode"] == "ext" && $_POST["link"] != "") {
397 $this->content_obj->setExtLink($_POST["link"]);
398 } elseif ($_POST["link_mode"] == "int" && $_POST["link"] != "") {
399 // $_POST["link"] is "crs|96", "chap|2", "term|1", "wpage|1"
400 // var_dump($_POST);
401 $la = $form->getItemByPostVar("link")->getIntLinkAttributes();
402 // echo "<br>";
403 // var_dump($la); exit;
404 if ($la["Type"] != "") {
405 $this->content_obj->setIntLink($la["Type"], $la["Target"], $la["TargetFrame"]);
406 }
407 } else {
408 $this->content_obj->setNoLink();
409 }
410 }
411}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
This class represents an advanced selection list property in a property form.
This class represents a date/time property in a property form.
@classDescription Date and time handling
This class represents a external and/or internal link in a property form.
Class ilObjStyleSheet.
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilPCSectionGUI.
update()
Update Section.
create()
Create new Section.
initForm($a_insert=false)
Init editing form.
static _getCharacteristics($a_style_id)
Get characteristics.
getHTML(array $params)
Get HTML.
edit($a_insert=false, ilPropertyFormGUI $a_form=null)
Edit section form.
setValuesFromForm($form)
Set values from form.
static _getStandardCharacteristics()
Get standard characteristics.
executeCommand()
execute command
__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
insert(ilPropertyFormGUI $a_form=null)
Insert new section form.
Class ilPCSection.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
getPageConfig()
Get Page Config.
displayValidationError()
display validation errors
getCharacteristics()
Get characteristics.
setCharacteristics($a_chars)
Set Characteristics.
This class represents a property form user interface.
This class represents a selection list property in a property form.
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6