ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilPCSectionGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 public function __construct(
27 ilPageObject $a_pg_obj,
28 ?ilPageContent $a_content_obj = null,
29 string $a_hier_id = "",
30 string $a_pc_id = ""
31 ) {
32 global $DIC;
33
34 $this->tpl = $DIC["tpl"];
35 $this->lng = $DIC->language();
36 $this->ctrl = $DIC->ctrl();
37 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
38
40 }
41
42 public function getHTML(array $params): string
43 {
44 $this->getCharacteristicsOfCurrentStyle(["section"]);
45
46 if ($params["form"] == true) {
47 $insert = !($this->content_obj);
48 $form = $this->initForm($params["insert"] ?? false);
49 $form->setShowTopButtons(false);
50
51 $onload_code = [];
52 $char = $form->getItemByPostVar("characteristic");
53 //$onload_code = array_merge($onload_code, $char->getOnloadCode());
54
55 $from = $form->getItemByPostVar("active_from");
56 $from->setSideBySide(false);
57 $onload_code = array_merge($onload_code, $from->getOnloadCode());
58
59 $to = $form->getItemByPostVar("active_to");
60 $to->setSideBySide(false);
61 $onload_code = array_merge($onload_code, $to->getOnloadCode());
62
63 $link = $form->getItemByPostVar("link");
64 $onload_code = array_merge($onload_code, $link->getOnloadCode());
65
66 $rep_sel = $form->getItemByPostVar("permission_ref_id");
67 $on_load_code3 = "";
68 $on_load_code4 = [];
69 if ($rep_sel) {
70 $exp = $rep_sel->getExplorerGUI();
71 $this->ctrl->setParameterByClass("ilformpropertydispatchgui", "postvar", "permission_ref_id");
72 $onload_code = array_merge($onload_code, [$exp->getOnloadCode()]);
73
74 $this->ctrl->setParameterByClass("ilformpropertydispatchgui", "postvar", "");
75 $onload_code = array_merge($onload_code, $rep_sel->getOnloadCode());
76 }
77
78 if (($params["validation"] ?? false) === true) {
79 $this->checkInput($form);
80 $form->setValuesByPost();
81 }
82
83 $html = $params["ui_wrapper"]->getRenderedForm(
84 $form,
85 $params["buttons"]
86 );
87
88 $html .= "<script>" .
89 implode("\n", $onload_code) .
90 "</script>";
91
92 return $html;
93 }
94 return "";
95 }
96
97 public function checkInput(ilPropertyFormGUI $form): bool
98 {
99 $ret = $form->checkInput();
100 if ($ret) {
101 $from = $form->getItemByPostVar("active_from")->getDate();
102 $to = $form->getItemByPostVar("active_to")->getDate();
103 if ($from && $to && $from->get(IL_CAL_UNIX) > $to->get(IL_CAL_UNIX)) {
104 $form->getItemByPostVar("active_to")->setAlert(
105 $this->lng->txt("copg_active_to_small")
106 );
107 $ret = false;
108 }
109 }
110 return $ret;
111 }
112
113 public static function _getStandardCharacteristics(): array
114 {
115 global $DIC;
116
117 $lng = $DIC->language();
118
119 return array("Block" => $lng->txt("cont_Block"),
120 "Mnemonic" => $lng->txt("cont_Mnemonic"),
121 "Remark" => $lng->txt("cont_Remark"),
122 "Example" => $lng->txt("cont_Example"),
123 "Additional" => $lng->txt("cont_Additional"),
124 "Special" => $lng->txt("cont_Special"),
125
126 "Attention" => $lng->txt("cont_Attention"),
127 "Background" => $lng->txt("cont_Background"),
128 "Citation" => $lng->txt("cont_Citation"),
129 "Confirmation" => $lng->txt("cont_Confirmation"),
130 "Information" => $lng->txt("cont_Information"),
131 "Interaction" => $lng->txt("cont_Interaction"),
132 "Link" => $lng->txt("cont_char_link"),
133 "Literature" => $lng->txt("cont_Literature"),
134 "Separator" => $lng->txt("cont_Separator"),
135 "StandardCenter" => $lng->txt("cont_StandardCenter"),
136
137 "Excursus" => $lng->txt("cont_Excursus"),
138 "AdvancedKnowledge" => $lng->txt("cont_AdvancedKnowledge"));
139 }
140
141 public static function _getCharacteristics(int $a_style_id): array
142 {
143 global $DIC;
144
145 $service = $DIC->contentStyle()->internal();
146 $request = $DIC->copage()->internal()
147 ->gui()
148 ->pc()
149 ->editRequest();
150 $requested_ref_id = $request->getRefId();
151 $access_manager = $service->domain()->access(
153 $DIC->user()->getId()
154 );
155 $char_manager = $service->domain()->characteristic(
156 $a_style_id,
157 $access_manager
158 );
159
161 $chars = $std_chars;
162 if ($a_style_id > 0 &&
163 ilObject::_lookupType($a_style_id) == "sty") {
164 $style = new ilObjStyleSheet($a_style_id);
165 $chars = $style->getCharacteristics("section");
166 $new_chars = array();
167 foreach ($chars as $char) {
168 if ($char_manager->isOutdated("section", $char)) {
169 continue;
170 }
171 if (($std_chars[$char] ?? "") != "") { // keep lang vars for standard chars
172 $new_chars[$char] = $std_chars[$char];
173 } else {
174 $new_chars[$char] = $char;
175 }
176 asort($new_chars);
177 }
178 $chars = $new_chars;
179 }
180 return $chars;
181 }
182
187 public function executeCommand(): mixed
188 {
189 $ret = "";
190
191 $this->getCharacteristicsOfCurrentStyle(["section"]); // scorm-2004
192
193 // get next class that processes or forwards current command
194 $next_class = $this->ctrl->getNextClass($this);
195
196 // get current command
197 $cmd = $this->ctrl->getCmd();
198
199 switch ($next_class) {
200 case "ilpropertyformgui":
201 $form = $this->initForm(true);
202 $this->ctrl->forwardCommand($form);
203 break;
204
205 default:
206 $ret = $this->$cmd();
207 break;
208 }
209
210 return $ret;
211 }
212
213 public function insert(?ilPropertyFormGUI $a_form = null): void
214 {
215 $this->edit(true, $a_form);
216 }
217
218 public function edit(
219 bool $a_insert = false,
220 ?ilPropertyFormGUI $a_form = null
221 ): void {
222 $tpl = $this->tpl;
223
224 $this->displayValidationError();
225
226 if (!$a_form) {
227 $a_form = $this->initForm($a_insert);
228 }
229
230 $tpl->setContent($a_form->getHTML());
231 }
232
233 public function initForm(
234 bool $a_insert = false
236 $lng = $this->lng;
237 $ilCtrl = $this->ctrl;
238 $a_seleted_value = "";
239
240 // edit form
241 $form = new ilPropertyFormGUI();
242 $form->setFormAction($ilCtrl->getFormAction($this));
243 if ($a_insert) {
244 $form->setTitle($this->lng->txt("cont_insert_section"));
245 } else {
246 $form->setTitle($this->lng->txt("cont_update_section"));
247 }
248
249 // characteristic selection
250 $char_prop = new ilSelectInputGUI(
251 $this->lng->txt("cont_characteristic"),
252 "characteristic"
253 );
254 $chars = $this->getCharacteristics();
255 if (is_object($this->content_obj)) {
256 if (($chars[$a_seleted_value] ?? "") == "" && ($this->content_obj->getCharacteristic() != "")) {
257 $chars = array_merge(
258 array($this->content_obj->getCharacteristic() => $this->content_obj->getCharacteristic()),
259 $chars
260 );
261 }
262 }
263
264 $selected = ($a_insert)
265 ? "Block"
266 : $this->content_obj->getCharacteristic();
267
268 $options = [];
269 foreach ($chars as $k => $char) {
270 $options[$k] = $char;
271 }
272 $char_prop->setOptions($options);
273
274 $char_prop->setValue($selected);
275 $form->addItem($char_prop);
276
277 // link input
278 //
279 $cb = new ilCheckboxInputGUI($lng->txt("cont_link"), "link_cb");
280
281 $ac = new ilLinkInputGUI($this->lng->txt('cont_target'), 'link');
282 if ($this->getPageConfig()->getEnableInternalLinks()) {
283 $ac->setAllowedLinkTypes(ilLinkInputGUI::BOTH);
284 } else {
285 $ac->setAllowedLinkTypes(ilLinkInputGUI::EXT);
286 }
287 $ac->setRequired(true);
288 $ac->setInfo($this->lng->txt("copg_sec_link_info"));
289 $ac->setInternalLinkDefault(
290 $this->getPageConfig()->getIntLinkHelpDefaultType(),
291 $this->getPageConfig()->getIntLinkHelpDefaultId()
292 );
293 $link_types = array();
294 foreach ($this->getPageConfig()->getIntLinkFilters() as $f) {
295 $link_types[] = $f;
296 }
297 $ac->setInternalLinkFilterTypes($link_types);
298 $ac->setFilterWhiteList(
299 $this->getPageConfig()->getIntLinkFilterWhiteList()
300 );
301
302 if (!$a_insert) {
303 $l = $this->content_obj->getLink();
304 if ($l["LinkType"] == "IntLink") {
305 $target_frame = $l["TargetFrame"];
306 if (trim($target_frame) === "") {
307 $target_frame = trim($l["Anchor"]);
308 }
309 $ac->setValueByIntLinkAttributes($l["Type"], $l["Target"], $target_frame);
310 $cb->setChecked(true);
311 } elseif ($l["LinkType"] == "ExtLink") {
312 $ac->setValue($l["Href"]);
313 $cb->setChecked(true);
314 } else {
315 $ac->setValue("https://");
316 }
317 } else {
318 $ac->setValue("https://");
319 }
320 $form->addItem($cb);
321 $ac->setParentForm($form);
322 $cb->addSubItem($ac);
323
324
325 // activation
326
327 // active from
328 $act_cb = new ilCheckboxInputGUI($lng->txt("cont_activation"), "activation");
329 $form->addItem($act_cb);
330 $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_from"), "active_from");
331 if (!$a_insert && ($from = $this->content_obj->getActiveFrom()) > 0) {
332 $dt_prop->setDate(new ilDateTime($from, IL_CAL_UNIX));
333 $act_cb->setChecked(true);
334 }
335 $dt_prop->setShowTime(true);
336 $act_cb->addSubItem($dt_prop);
337
338 // active to
339 $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_to"), "active_to");
340 if (!$a_insert && ($to = $this->content_obj->getActiveTo()) > 0) {
341 $dt_prop->setDate(new ilDateTime($to, IL_CAL_UNIX));
342 $act_cb->setChecked(true);
343 }
344 $dt_prop->setShowTime(true);
345 $act_cb->addSubItem($dt_prop);
346
347 // rep selector
348 if ($this->getPageConfig()->getEnablePermissionChecks()) {
349 $perm_cb = new ilCheckboxInputGUI($lng->txt("cont_permission_handling"), "permission_handling");
350 $form->addItem($perm_cb);
351
352 $rs = new ilRepositorySelector2InputGUI($lng->txt("cont_permission_object"), "permission_ref_id", false, $form);
353 //$rs->setParent($this);
354 $rs->setParentForm($form);
355 $rs->setRequired(true);
356 $perm_cb->addSubItem($rs);
357
358 // permission
359 $options = array(
360 "read" => $lng->txt("read"),
361 "write" => $lng->txt("write"),
362 "visible" => $lng->txt("visible"),
363 "no_read" => $lng->txt("cont_no_read")
364 );
365 $si = new ilSelectInputGUI($lng->txt("permission"), "permission");
366 $si->setInfo($lng->txt("cont_permission_object_desc"));
367 $si->setOptions($options);
368 $perm_cb->addSubItem($si);
369
370 if (!$a_insert) {
371 $si->setValue($this->content_obj->getPermission());
372 $rs->setValue($this->content_obj->getPermissionRefId());
373 if ($this->content_obj->getPermissionRefId() > 0) {
374 $perm_cb->setChecked(true);
375 }
376 }
377 }
378
379 // protection
380 if ($this->getPageConfig()->getSectionProtection() == ilPageConfig::SEC_PROTECT_EDITABLE) {
381 $cb = new ilCheckboxInputGUI($lng->txt("cont_sec_protected"), "protected");
382 $cb->setInfo($this->getPageConfig()->getSectionProtectionInfo());
383 if (!$a_insert) {
384 $cb->setChecked($this->content_obj->getProtected());
385 }
386 $form->addItem($cb);
387 }
388
389 // save/cancel buttons
390 if ($a_insert) {
391 $form->addCommandButton("create", $lng->txt("save"));
392 $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
393 } else {
394 $form->addCommandButton("update", $lng->txt("save"));
395 $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
396 }
397 return $form;
398 }
399
400 public function create(): void
401 {
402 $form = $this->initForm(true);
403 if ($form->checkInput()) {
404 $this->content_obj = new ilPCSection($this->getPage());
405 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
406
407 $this->setValuesFromForm($form);
408
409 $this->updated = $this->pg_obj->update();
410 if ($this->updated === true) {
411 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
412 }
413 }
414
415 $this->insert($form);
416 }
417
418 public function update(): void
419 {
420 $form = $this->initForm(false);
421 if ($form->checkInput()) {
422 $this->setValuesFromForm($form);
423
424 $this->updated = $this->pg_obj->update();
425 if ($this->updated === true) {
426 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
427 }
428 }
429
430 $this->pg_obj->addHierIDs();
431 $this->edit(false, $form);
432 }
433
434 public function setValuesFromForm(ilPropertyFormGUI $form): void
435 {
436 $this->content_obj->setCharacteristic($form->getInput("characteristic"));
437
438 $activation = (bool) $form->getInput("activation");
439 $from = $form->getItemByPostVar("active_from")->getDate();
440 if ($activation && $from) {
441 $this->content_obj->setActiveFrom($from->get(IL_CAL_UNIX));
442 } else {
443 $this->content_obj->setActiveFrom(0);
444 }
445
446 $to = $form->getItemByPostVar("active_to")->getDate();
447 if ($activation && $to) {
448 $this->content_obj->setActiveTo($to->get(IL_CAL_UNIX));
449 } else {
450 $this->content_obj->setActiveTo(0);
451 }
452
453 if ($this->getPageConfig()->getEnablePermissionChecks()) {
454 $permission_handling = (bool) $form->getInput("permission_handling");
455 if ($permission_handling) {
456 $this->content_obj->setPermissionRefId((int) $form->getInput("permission_ref_id"));
457 $this->content_obj->setPermission($form->getInput("permission"));
458 } else {
459 $this->content_obj->setPermissionRefId(0);
460 $this->content_obj->setPermission("");
461 }
462 }
463
464 if ($form->getInput("link_cb") !== "") {
465 if ($form->getInput("link_mode") == "ext" && $form->getInput("link") != "") {
466 $this->content_obj->setExtLink($form->getInput("link"));
467 } elseif ($form->getInput("link_mode") == "int" && $form->getInput("link") != "") {
468 $la = $form->getItemByPostVar("link")->getIntLinkAttributes();
469 if (($la["Type"] ?? "") != "") {
470 $anchor = "";
471 if (trim($la["TargetFrame"]) !== "" &&
472 !in_array($la["TargetFrame"], ["Media", "FAQ", "Glossary", "New"])) {
473 $anchor = trim($la["TargetFrame"]);
474 $la["TargetFrame"] = "";
475 }
476 $this->content_obj->setIntLink($la["Type"], $la["Target"], $la["TargetFrame"], $anchor);
477 }
478 } else {
479 $this->content_obj->setNoLink();
480 }
481 } else {
482 $this->content_obj->setNoLink();
483 }
484
485 if ($this->getPageConfig()->getSectionProtection() == ilPageConfig::SEC_PROTECT_EDITABLE) {
486 $this->content_obj->setProtected($form->getInput("protected"));
487 }
488 }
489}
const IL_CAL_UNIX
This class represents a checkbox property in a property form.
This class represents a date/time property in a property form.
@classDescription Date and time handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This class represents a external and/or internal link in a property form.
Class ilObjStyleSheet.
getCharacteristics(string $a_type="", bool $a_no_hidden=false, bool $a_include_core=true)
Get characteristics.
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setValuesFromForm(ilPropertyFormGUI $form)
initForm(bool $a_insert=false)
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj=null, string $a_hier_id="", string $a_pc_id="")
getHTML(array $params)
edit(bool $a_insert=false, ?ilPropertyFormGUI $a_form=null)
insert(?ilPropertyFormGUI $a_form=null)
checkInput(ilPropertyFormGUI $form)
static _getCharacteristics(int $a_style_id)
static _getStandardCharacteristics()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getCharacteristicsOfCurrentStyle(array $a_type)
Get characteristics of current style and call setCharacteristics, if style is given.
ilGlobalTemplateInterface $tpl
Style Content CharacteristicManager $char_manager
setCharacteristics(array $a_chars)
Content object of ilPageObject (see ILIAS DTD).
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
This class represents a selection list property in a property form.
setContent(string $a_html)
Sets content for standard template.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$service
Definition: ltiresult.php:36
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26