ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLMPageObjectGUI.php
Go to the documentation of this file.
1<?php
2
21
29{
31 protected ilTabsGUI $tabs;
33 protected \ILIAS\Style\Content\DomainService $content_style_domain;
34
35 public function __construct(
36 ilObjLearningModule $a_content_obj
37 ) {
38 global $DIC;
39
40 $this->tpl = $DIC["tpl"];
41 $this->ctrl = $DIC->ctrl();
42 $this->tabs = $DIC->tabs();
43 $this->settings = $DIC->settings();
44 $this->lng = $DIC->language();
45 parent::__construct($a_content_obj);
46 $cs = $DIC->contentStyle();
47 $this->content_style_domain = $cs->domain();
48 }
49
53 public function setLMPageObject(ilLMPageObject $a_pg_obj): void
54 {
55 $this->obj = $a_pg_obj;
56 $this->obj->setLMId($this->content_object->getId());
57 }
58
59 public function executeCommand(): void
60 {
62 $ilCtrl = $this->ctrl;
64
65 $next_class = $this->ctrl->getNextClass($this);
66 $cmd = $this->ctrl->getCmd();
67
68 switch ($next_class) {
69 case "illmpagegui":
70
71 $this->ctrl->setReturn($this, "edit");
72 if (!ilPageObject::_exists("lm", $this->obj->getId(), $this->requested_transl) &&
73 ilPageObject::_exists("lm", $this->obj->getId(), "-")) {
74 if ($this->requested_totransl == "") {
75 $this->requested_totransl = $this->requested_transl;
76 $ilCtrl->setParameterByClass("illmpagegui", "totransl", $this->requested_transl);
77 $ilCtrl->redirectByClass("illmpagegui", "switchToLanguage");
78 }
79 $page_gui = new ilLMPageGUI($this->obj->getId(), 0, false, "-");
80 } else {
81 $page_gui = new ilLMPageGUI($this->obj->getId());
82 }
83 $page_gui->setEditPreview(true);
84 $page_gui->activateMetaDataEditor(
85 $this->content_object,
86 $this->obj->getType(),
87 $this->obj->getId(),
88 $this->obj,
89 "MDUpdateListener"
90 );
91 if ($ilSetting->get("block_activated_news")) {
92 $page_gui->setEnabledNews(
93 true,
94 $this->obj->content_object->getId(),
95 $this->obj->content_object->getType()
96 );
97 }
98
99 $page_gui->setViewPageLink(
100 ILIAS_HTTP_PATH . "/goto.php?target=pg_" . $this->obj->getId() .
101 "_" . $this->requested_ref_id
102 );
103
104 $page_gui->setStyleId($this->content_style_domain
105 ->styleForRefId($this->content_object->getRefId())
106 ->getEffectiveStyleId());
107 $page_gui->setTemplateTargetVar("ADM_CONTENT");
108 $page_gui->getPageObject()->buildDom();
109 $int_links = $page_gui->getPageObject()->getInternalLinks();
110 $link_xml = $this->getLinkXML($int_links);
111 $page_gui->setLinkXml($link_xml);
112
113 $page_gui->setFileDownloadLink("ilias.php?cmd=downloadFile&ref_id=" . $this->requested_ref_id . "&baseClass=ilLMPresentationGUI");
114 $page_gui->setFullscreenLink("ilias.php?cmd=fullscreen&ref_id=" . $this->requested_ref_id . "&baseClass=ilLMPresentationGUI");
115 $page_gui->setLinkParams("ref_id=" . $this->content_object->getRefId());
116 $page_gui->setSourcecodeDownloadScript("ilias.php?ref_id=" . $this->requested_ref_id . "&baseClass=ilLMPresentationGUI");
117 $page_gui->setPresentationTitle(
119 $this->obj->getId(),
120 $this->content_object->getPageHeader(),
121 $this->content_object->isActiveNumbering(),
122 false,
123 false,
124 0,
125 $page_gui->getLanguage()
126 )
127 );
128 //$page_gui->setLocator($contObjLocator);
129 $page_gui->setHeader($this->lng->txt("page") . ": " . $this->obj->getTitle());
130 $page_gui->setActivationListener($this, "activatePage");
131
132 $up_gui = "ilobjlearningmodulegui";
133 $ilCtrl->setParameterByClass($up_gui, "active_node", $this->obj->getId());
134
135 $tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_pg.svg"));
136 $tpl->setTitle($this->lng->txt("page") . ": " . $this->obj->getTitle());
137 if ($this->content_object->getLayoutPerPage()) {
138 $page_gui->setTabHook($this, "addPageTabs");
139 }
140 $ret = $this->ctrl->forwardCommand($page_gui);
141 if ($ret != "") { // in 6.0 this overwrites already set content with an empty string sometimes
142 $tpl->setContent($ret);
143 }
144 break;
145
146 default:
147 $this->$cmd();
148 break;
149 }
150 }
151
152
156 public function edit(): void
157 {
158 $this->ctrl->redirectByClass(ilLMPageGUI::class, "edit");
159 }
160
164 public function preview(): void
165 {
166 $this->ctrl->redirectByClass(ilLMPageGUI::class, "preview");
167 }
168
169
173 public function cancel(): void
174 {
175 if ($this->requested_obj_id != 0) {
176 ilUtil::redirect($this->ctrl->getLinkTargetByClass(
177 "ilStructureObjectGUI",
178 "view",
179 "",
180 true
181 ));
182 }
183 $up_gui = "ilobjlearningmodulegui";
184 $this->ctrl->redirectByClass($up_gui, "pages");
185 }
186
190 public function getLinkXML(array $a_int_links): string
191 {
192 $link_info = "<IntLinkInfos>";
193 foreach ($a_int_links as $int_link) {
194 $target = $int_link["Target"];
195 $ltarget = "";
196 $href = "";
197 $lcontent = "";
198 if (substr($target, 0, 4) == "il__") {
199 $target_arr = explode("_", $target);
200 $target_id = $target_arr[count($target_arr) - 1];
201 $type = $int_link["Type"];
202 $targetframe = ($int_link["TargetFrame"] != "")
203 ? $int_link["TargetFrame"]
204 : "None";
205
206 // anchor
207 $anc = $anc_add = "";
208 if (($int_link["Anchor"] ?? "") != "") {
209 $anc = $int_link["Anchor"];
210 $anc_add = "_" . rawurlencode($int_link["Anchor"]);
211 }
212
213 switch ($type) {
214 case "PageObject":
215 case "StructureObject":
216 $lm_id = ilLMObject::_lookupContObjID($target_id);
217 $cont_obj = $this->content_object;
218 if ($lm_id == $cont_obj->getId()) {
219 $ltarget = "";
220 if ($type == "PageObject") {
221 $this->ctrl->setParameter($this, "obj_id", $target_id);
222 $href = $this->ctrl->getLinkTargetByClass(
223 get_class($this),
224 "edit",
225 "",
226 false,
227 true
228 );
229 } else {
230 $this->ctrl->setParameterByClass("ilstructureobjectgui", "obj_id", $target_id);
231 $href = $this->ctrl->getLinkTargetByClass(
232 "ilstructureobjectgui",
233 "view",
234 "",
235 false,
236 true
237 );
238 }
239 $href = str_replace("&", "&amp;", $href);
240 $this->ctrl->setParameter($this, "obj_id", $this->requested_obj_id);
241 } else {
242 if ($type == "PageObject") {
243 $href = "goto.php?target=pg_" . $target_id . $anc_add;
244 } else {
245 $href = "goto.php?target=st_" . $target_id;
246 }
247 $ltarget = "ilContObj" . $lm_id;
248 }
249 if ($lm_id == "") {
250 $href = "";
251 }
252 break;
253
254 case "GlossaryItem":
255 $ltarget = $nframe = "_blank";
256 $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;" .
257 "obj_type=$type&amp;cmd=glossary&amp;ref_id=" . $this->requested_ref_id .
258 "&amp;obj_id=" . $target_id . "&amp;frame=$nframe";
259 break;
260
261 case "MediaObject":
262 $ltarget = $nframe = "_blank";
263 $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;obj_type=$type&amp;cmd=media&amp;ref_id=" . $this->requested_ref_id .
264 "&amp;mob_id=" . $target_id . "&amp;frame=$nframe";
265 break;
266
267 case "RepositoryItem":
268 $obj_type = ilObject::_lookupType((int) $target_id, true);
269 $obj_id = ilObject::_lookupObjId((int) $target_id);
270 $href = "./goto.php?target=" . $obj_type . "_" . $target_id;
271 $t_frame = ilFrameTargetInfo::_getFrame("MainContent");
272 $ltarget = $t_frame;
273 break;
274
275 case "File":
276 $this->ctrl->setParameter($this, "file_id", "il__file_" . $target_id);
277 $href = $this->ctrl->getLinkTarget(
278 $this,
279 "downloadFile",
280 "",
281 false,
282 true
283 );
284 $this->ctrl->setParameter($this, "file_id", null);
285 break;
286
287 case "WikiPage":
288 $href = ilWikiPage::getGotoForWikiPageTarget($target_id);
289 break;
290
291 case "User":
292 $obj_type = ilObject::_lookupType((int) $target_id);
293 if ($obj_type == "usr") {
294 $back = $this->ctrl->getLinkTarget(
295 $this,
296 "edit",
297 "",
298 false,
299 true
300 );
301 //var_dump($back); exit;
302 $this->ctrl->setParameterByClass(PublicProfileGUI::class, "user_id", $target_id);
303 $this->ctrl->setParameterByClass(
304 PublicProfileGUI::class,
305 "back_url",
306 rawurlencode($back)
307 );
308 $href = "";
309 if (ilUserUtil::hasPublicProfile($target_id)) {
310 $href = $this->ctrl->getLinkTargetByClass(
311 PublicProfileGUI::class,
312 "getHTML",
313 "",
314 false,
315 true
316 );
317 }
318 $this->ctrl->setParameterByClass(PublicProfileGUI::class, "user_id", null);
319 $lcontent = ilUserUtil::getNamePresentation($target_id, false, false);
320 }
321 break;
322 }
323
324 if ($href != "") {
325 $anc_par = 'Anchor="' . $anc . '"';
326 $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " .
327 "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" LinkContent=\"$lcontent\" $anc_par/>";
328 }
329 }
330 }
331 $link_info .= "</IntLinkInfos>";
332 return $link_info;
333 }
334
338 public static function _goto(string $a_target): void
339 {
340 global $DIC;
341 $main_tpl = $DIC->ui()->mainTemplate();
342
343 $ilErr = $DIC["ilErr"];
344 $lng = $DIC->language();
345 $ilAccess = $DIC->access();
346 $ctrl = $DIC->ctrl();
347 $ref_id = 0;
348 $anchor = "";
349
350 $first = strpos($a_target, "_");
351 $second = strpos($a_target, "_", $first + 1);
352 if ($first > 0) {
353 $page_id = substr($a_target, 0, $first);
354 if ($second > 0) {
355 $ref_id = substr($a_target, $first + 1, $second - ($first + 1));
356 $anchor = substr($a_target, $second + 1);
357 } else {
358 $ref_id = substr($a_target, $first + 1);
359 }
360 } else {
361 $page_id = $a_target;
362 }
363
364 // determine learning object
365 $lm_id = ilLMObject::_lookupContObjID($page_id);
366
367 // get all references
368 $ref_ids = ilObject::_getAllReferences($lm_id);
369
370 // always try passed ref id first
371 if (in_array($ref_id, $ref_ids)) {
372 $ref_ids = array_merge(array($ref_id), $ref_ids);
373 }
374
375 // check read permissions
376 foreach ($ref_ids as $ref_id) {
377 // check read permissions
378 if ($ilAccess->checkAccess("read", "", $ref_id)) {
379 $ctrl->setParameterByClass("ilLMPresentationGUI", "obj_id", $page_id);
380 $ctrl->setParameterByClass("ilLMPresentationGUI", "ref_id", $ref_id);
381 $ctrl->setParameterByClass("ilLMPresentationGUI", "anchor", $anchor);
382 $ctrl->redirectByClass("ilLMPresentationGUI", "");
383 }
384 }
385
386 if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
387 if ($lm_id > 0) {
388 $main_tpl->setOnScreenMessage('failure', sprintf(
389 $lng->txt("msg_no_perm_read_item"),
391 ), true);
392 } else {
393 $lng->loadLanguageModule("content");
394 $main_tpl->setOnScreenMessage('failure', $lng->txt("page_does_not_exist"), true);
395 }
397 }
398
399 $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
400 }
401
405 public function editLayout(): void
406 {
408 $ilCtrl = $this->ctrl;
409 $ilTabs = $this->tabs;
410
411 $page_gui = new ilLMPageGUI($this->obj->getId());
412 $page_gui->setEditPreview(true);
413 $page_gui->activateMetaDataEditor(
414 $this->content_object,
415 $this->obj->getType(),
416 $this->obj->getId(),
417 $this->obj,
418 "MDUpdateListener"
419 );
420 $page_gui->setActivationListener($this, "activatePage");
421 $page_gui->setTabHook($this, "addPageTabs");
422 $lm_set = new ilSetting("lm");
423 $tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_pg.svg"));
424 $tpl->setTitle($this->lng->txt("page") . ": " . $this->obj->getTitle());
425 $ilCtrl->getHTML($page_gui);
426 $ilTabs->setTabActive("cont_layout");
427 $this->initEditLayoutForm();
428 $tpl->setContent($this->form->getHTML());
429 }
430
431 public function initEditLayoutForm(): void
432 {
434 $ilCtrl = $this->ctrl;
435 $im_tag = "";
436
437 $this->form = new ilPropertyFormGUI();
438
439 // default layout
440 $layout = new ilRadioGroupInputGUI($lng->txt("cont_layout"), "layout");
441
442 if (is_file($im = ilUtil::getImagePath("layout_" . $this->content_object->getLayout() . ".png"))) {
443 $im_tag = ilUtil::img($im, $this->content_object->getLayout());
444 }
445 $layout->addOption(new ilRadioOption("<table><tr><td>" . $im_tag . "</td><td><strong>" .
446 $lng->txt("cont_lm_default_layout") .
447 "</strong>: " . $lng->txt("cont_layout_" . $this->content_object->getLayout()) .
448 "</td></tr></table>", ""));
449
451 $im_tag = "";
452 if (is_file($im = ilUtil::getImagePath("layout_" . $l . ".png"))) {
453 $im_tag = ilUtil::img($im, $l);
454 }
455 $layout->addOption(new ilRadioOption("<table><tr><td>" . $im_tag . "</td><td><strong>" .
456 $lng->txt("cont_layout_" . $l) . "</strong>: " . $lng->txt("cont_layout_" . $l . "_desc") .
457 "</td></tr></table>", $l));
458 }
459
460 $layout->setValue($this->obj->getLayout());
461 $this->form->addItem($layout);
462
463 $this->form->addCommandButton("saveLayout", $lng->txt("save"));
464
465 $this->form->setTitle($lng->txt("cont_page_layout"));
466 $this->form->setFormAction($ilCtrl->getFormAction($this));
467 }
468
469 public function saveLayout(): void
470 {
473 $ilCtrl = $this->ctrl;
474
475 $this->initEditLayoutForm();
476 if ($this->form->checkInput()) {
477 ilLMObject::writeLayout($this->obj->getId(), $this->form->getInput("layout"));
478 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
479 $ilCtrl->redirect($this, "editLayout");
480 }
481 $this->form->setValuesByPost();
482 $tpl->setContent($this->form->getHTML());
483 }
484
485 public function addPageTabs(): void
486 {
487 $ilTabs = $this->tabs;
488 $ilCtrl = $this->ctrl;
489
490 $ilTabs->addTarget(
491 "cont_layout",
492 $ilCtrl->getLinkTarget($this, 'editLayout'),
493 "editLayout"
494 );
495 }
496
500 public function downloadFile(): void
501 {
502 $pg_obj = $this->obj->getPageObject();
503 $pg_obj->buildDom();
504 $int_links = $pg_obj->getInternalLinks();
505 foreach ($int_links as $il) {
506 if ($il["Target"] == str_replace(
507 "_file_",
508 "_dfile_",
509 $this->request->getFileId()
510 )) {
511 $file = explode("_", $this->request->getFileId());
512 $file_id = (int) $file[count($file) - 1];
513 $fileObj = new ilObjFile($file_id, false);
514 $fileObj->sendFile();
515 exit;
516 }
517 }
518 }
519
520 public function create(): void
521 {
522 $ui = $this->ui;
525
527 $tabs->setBackTarget($lng->txt("back"), $ctrl->getLinkTarget($this, "cancel"));
528
529 $ctrl->setParameter($this, "new_type", "pg");
530 $form = $this->initNewPageForm();
531
532 $this->tpl->setContent($ui->renderer()->render($form) . self::getLayoutCssFix());
533 }
534
535 public function initNewPageForm(): Form\Standard
536 {
537 $ui = $this->ui;
538 $f = $ui->factory();
541
542 $fields["title"] = $f->input()->field()->text($lng->txt("title"), "");
543
544 $fields["description"] = $f->input()->field()->textarea($lng->txt("description"));
545
546 $ts = ilPageLayoutGUI::getTemplateSelection(ilPageLayout::MODULE_LM);
547 if (!is_null($ts)) {
548 $fields["layout_id"] = $ts;
549 }
550
551 // section
552 $section1 = $f->input()->field()->section($fields, $lng->txt("cont_insert_pagelayout"));
553
554 $form_action = $ctrl->getLinkTarget($this, "save");
555 return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
556 }
557
561 public function save(): void
562 {
563 global $DIC;
564
565 $request = $DIC->http()->request();
567
568 $form = $this->initNewPageForm();
569 if ($request->getMethod() == "POST") {
570 $form = $form->withRequest($request);
571 $data = $form->getData()["sec"];
572
573 $layout_id = (int) ($data["layout_id"] ?? 0);
574
575 $this->obj = new ilLMPageObject($this->content_object);
576 $this->obj->setType("pg");
577 $this->obj->setTitle(ilUtil::stripSlashes($data["title"]));
578 $this->obj->setDescription(ilUtil::stripSlashes($data["description"]));
579 $this->obj->setLMId($this->content_object->getId());
580 if ($layout_id > 0) {
581 $this->obj->create(false, false, $layout_id);
582 } else {
583 $this->obj->create();
584 }
585 $this->tpl->setOnScreenMessage('success', $lng->txt("cont_page_created"), true);
586 }
587 $this->cancel();
588 }
589
594 public static function getLayoutCssFix(): string
595 {
596 return "
597 <style>
598 .form-control.il-input-radiooption > label {
599 vertical-align: middle;
600 }
601 .form-control.il-input-radiooption > .help-block {
602 padding-left: 2rem;
603 }
604 </style>
605 ";
606 }
607}
GUI class for public user profile presentation.
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
static _getFrame(string $a_class)
Base class for ilStructureObjects and ilPageObjects (see ILIAS DTD)
EditingGUIRequest $request
ilGlobalTemplateInterface $tpl
ilObjLearningModule $content_object
ILIAS DI UIServices $ui
static writeLayout(int $a_obj_id, string $a_layout, ?ilObjLearningModule $a_lm=null)
Write layout setting.
static _lookupContObjID(int $a_id)
get learning module id for lm object
setLMId(int $a_lm_id)
Extension of ilPageObjectGUI for learning modules.
User Interface for Learning Module Page Objects Editing.
static _goto(string $a_target)
redirect script
editLayout()
Edit layout of page.
getLinkXML(array $a_int_links)
get link targets
preview()
display content of page (edit view)
__construct(ilObjLearningModule $a_content_obj)
constructor
downloadFile()
download file of file lists
setLMPageObject(ilLMPageObject $a_pg_obj)
Set content object dependent page object (co page)
static getLayoutCssFix()
Get layout css fix (workaround for broken radio options)
create()
structure / page object creation form
ILIAS Style Content DomainService $content_style_domain
edit()
display content of page (edit view)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getPresentationTitle(int $a_pg_id, string $a_mode=self::CHAPTER_TITLE, bool $a_include_numbers=false, bool $a_time_scheduled_activation=false, bool $a_force_content=false, int $a_lm_id=0, string $a_lang="-", bool $a_include_short=false)
presentation title doesn't have to be page title, it may be chapter title + page title or chapter tit...
loadLanguageModule(string $a_module)
Load language module.
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...
static getAvailableLayouts()
get all available lm layouts
Class ilObjFile.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setBackTarget(string $a_title, string $a_target, string $a_frame="")
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
static hasPublicProfile(int $a_user_id)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static redirect(string $a_script)
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static getGotoForWikiPageTarget(string $a_target, bool $a_offline=false)
const ROOT_FOLDER_ID
Definition: constants.php:32
exit
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
setContent(string $a_html)
Sets content for standard template.
This describes commonalities between all forms.
Definition: Form.php:33
This describes a standard form.
Definition: Standard.php:29
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd, string $submit_caption="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
global $ilSetting
Definition: privfeed.php:31
$ilErr
Definition: raiseError.php:33
global $DIC
Definition: shib_login.php:26
$lm_set