ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLMPageObjectGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
18{
22 protected $tabs;
23
27 protected $settings;
28
29 public $obj;
30
37 public function __construct(&$a_content_obj)
38 {
39 global $DIC;
40
41 $this->tpl = $DIC["tpl"];
42 $this->ctrl = $DIC->ctrl();
43 $this->tabs = $DIC->tabs();
44 $this->settings = $DIC->settings();
45 $this->lng = $DIC->language();
46 parent::__construct($a_content_obj);
47 }
48
49
53 public function setLMPageObject($a_pg_obj)
54 {
55 $this->obj = $a_pg_obj;
56 $this->obj->setLMId($this->content_object->getId());
57 }
58
62 public function executeCommand()
63 {
65 $ilCtrl = $this->ctrl;
66 $ilTabs = $this->tabs;
68
69 $next_class = $this->ctrl->getNextClass($this);
70 $cmd = $this->ctrl->getCmd();
71
72 //echo "<br>:cmd:".$this->ctrl->getCmd().":cmdClass:".$this->ctrl->getCmdClass().":".
73 // ":nextClass:".$next_class.":"; flush();
74
75 switch ($next_class) {
76 case "illmpagegui":
77
78 // Determine whether the view of a learning resource should
79 // be shown in the frameset of ilias, or in a separate window.
80 $showViewInFrameset = true;
81 $lm_set = new ilSetting("lm");
82
83 $this->ctrl->setReturn($this, "edit");
84 if (!ilPageObject::_exists("lm", $this->obj->getId(), $_GET["transl"]) &&
85 ilPageObject::_exists("lm", $this->obj->getId(), "-")) {
86 if ($_GET["totransl"] == "") {
87 $_GET["totransl"] = $_GET["transl"];
88 $ilCtrl->setCmd("switchToLanguage");
89 }
90 $ilCtrl->setCmdClass("illmpagegui");
91 $page_gui = new ilLMPageGUI($this->obj->getId(), 0, false, "-");
92 } else {
93 $page_gui = new ilLMPageGUI($this->obj->getId());
94 }
95 $page_gui->setEditPreview(true);
96 $page_gui->activateMetaDataEditor(
97 $this->content_object,
98 $this->obj->getType(),
99 $this->obj->getId(),
100 $this->obj,
101 "MDUpdateListener"
102 );
103 if ($ilSetting->get("block_activated_news")) {
104 $page_gui->setEnabledNews(
105 true,
106 $this->obj->content_object->getId(),
107 $this->obj->content_object->getType()
108 );
109 }
110
111 // set page view link
112 if ($showViewInFrameset) {
113 $view_frame = ilFrameTargetInfo::_getFrame("MainContent");
114 } else {
115 $view_frame = "ilContObj" . $this->content_object->getID();
116 }
117 $page_gui->setViewPageLink(
118 ILIAS_HTTP_PATH . "/goto.php?target=pg_" . $this->obj->getId() .
119 "_" . $_GET["ref_id"],
120 $view_frame
121 );
122
124 $this->content_object->getStyleSheetId(),
125 "lm"
126 ));
127 $page_gui->setTemplateTargetVar("ADM_CONTENT");
128 $page_gui->getPageObject()->buildDom();
129 $int_links = $page_gui->getPageObject()->getInternalLinks();
130 $link_xml = $this->getLinkXML($int_links);
131 $page_gui->setLinkXML($link_xml);
132
133 $page_gui->enableChangeComments($this->content_object->isActiveHistoryUserComments());
134 $page_gui->setFileDownloadLink("ilias.php?cmd=downloadFile&ref_id=" . $_GET["ref_id"] . "&baseClass=ilLMPresentationGUI");
135 $page_gui->setFullscreenLink("ilias.php?cmd=fullscreen&ref_id=" . $_GET["ref_id"] . "&baseClass=ilLMPresentationGUI");
136 $page_gui->setLinkParams("ref_id=" . $this->content_object->getRefId());
137 $page_gui->setSourcecodeDownloadScript("ilias.php?ref_id=" . $_GET["ref_id"] . "&baseClass=ilLMPresentationGUI");
138 $page_gui->setPresentationTitle(
140 $this->obj->getId(),
141 $this->content_object->getPageHeader(),
142 $this->content_object->isActiveNumbering()
143 )
144 );
145 $page_gui->setLocator($contObjLocator);
146 $page_gui->setHeader($this->lng->txt("page") . ": " . $this->obj->getTitle());
147 $page_gui->setActivationListener($this, "activatePage");
148
149 $up_gui = "ilobjlearningmodulegui";
150 $ilCtrl->setParameterByClass($up_gui, "active_node", $this->obj->getId());
151
152 $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg.svg"));
153 $tpl->setTitle($this->lng->txt("page") . ": " . $this->obj->getTitle());
154 if ($this->content_object->getLayoutPerPage()) {
155 $page_gui->setTabHook($this, "addPageTabs");
156 }
157 $ret = $this->ctrl->forwardCommand($page_gui);
158 if ($ret != "") { // in 6.0 this overwrites already set content with an empty string sometimes
159 $tpl->setContent($ret);
160 }
161 break;
162
163 default:
164 $ret = $this->$cmd();
165 break;
166 }
167 }
168
169
170 /*
171 * display content of page (edit view)
172 */
173 public function edit()
174 {
175 //echo "<br>umschuss";
176 $this->ctrl->setCmdClass("ilLMPageGUI");
177 $this->ctrl->setCmd("edit");
178 $this->executeCommand();
179 //$this->setTabs();
180 }
181
182 /*
183 * display content of page (edit view)
184 */
185 public function preview()
186 {
187 $this->ctrl->setCmdClass("ilLMPageGUI");
188 $this->ctrl->setCmd("preview");
189 $this->executeCommand();
190 // $this->setTabs();
191 }
192
193
197 public function cancel()
198 {
199 if ($_GET["obj_id"] != 0) {
200 ilUtil::redirect($this->ctrl->getLinkTargetByClass(
201 "ilStructureObjectGUI",
202 "view",
203 "",
204 true
205 ));
206 }
207 $up_gui = "ilobjlearningmodulegui";
208 $this->ctrl->redirectByClass($up_gui, "pages");
209 }
210
214 public function getLinkXML($a_int_links)
215 {
216 if ($a_layoutframes == "") {
217 $a_layoutframes = array();
218 }
219 $link_info = "<IntLinkInfos>";
220 foreach ($a_int_links as $int_link) {
221 $target = $int_link["Target"];
222 if (substr($target, 0, 4) == "il__") {
223 $target_arr = explode("_", $target);
224 $target_id = $target_arr[count($target_arr) - 1];
225 $type = $int_link["Type"];
226 $targetframe = ($int_link["TargetFrame"] != "")
227 ? $int_link["TargetFrame"]
228 : "None";
229
230 // anchor
231 $anc = $anc_add = "";
232 if ($int_link["Anchor"] != "") {
233 $anc = $int_link["Anchor"];
234 $anc_add = "_" . rawurlencode($int_link["Anchor"]);
235 }
236
237 switch ($type) {
238 case "PageObject":
239 case "StructureObject":
241 $cont_obj = $this->content_object;
242 if ($lm_id == $cont_obj->getId()) {
243 $ltarget = "";
244 if ($type == "PageObject") {
245 $this->ctrl->setParameter($this, "obj_id", $target_id);
246 $href = $this->ctrl->getLinkTargetByClass(
247 get_class($this),
248 "edit",
249 "",
250 false,
251 true
252 );
253 } else {
254 $this->ctrl->setParameterByClass("ilstructureobjectgui", "obj_id", $target_id);
255 $href = $this->ctrl->getLinkTargetByClass(
256 "ilstructureobjectgui",
257 "view",
258 "",
259 false,
260 true
261 );
262 }
263 $href = str_replace("&", "&amp;", $href);
264 $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
265 } else {
266 if ($type == "PageObject") {
267 $href = "goto.php?target=pg_" . $target_id . $anc_add;
268 } else {
269 $href = "goto.php?target=st_" . $target_id;
270 }
271 $ltarget = "ilContObj" . $lm_id;
272 }
273 if ($lm_id == "") {
274 $href = "";
275 }
276 break;
277
278 case "GlossaryItem":
279 $ltarget = $nframe = "_blank";
280 $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;" .
281 "obj_type=$type&amp;cmd=glossary&amp;ref_id=" . $_GET["ref_id"] .
282 "&amp;obj_id=" . $target_id . "&amp;frame=$nframe";
283 break;
284
285 case "MediaObject":
286 $ltarget = $nframe = "_blank";
287 $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;obj_type=$type&amp;cmd=media&amp;ref_id=" . $_GET["ref_id"] .
288 "&amp;mob_id=" . $target_id . "&amp;frame=$nframe";
289 break;
290
291 case "RepositoryItem":
292 $obj_type = ilObject::_lookupType($target_id, true);
294 $href = "./goto.php?target=" . $obj_type . "_" . $target_id;
295 $t_frame = ilFrameTargetInfo::_getFrame("MainContent", $obj_type);
296 $ltarget = $t_frame;
297 break;
298
299 case "File":
300 $this->ctrl->setParameter($this, "file_id", "il__file_" . $target_id);
301 $href = $this->ctrl->getLinkTarget(
302 $this,
303 "downloadFile",
304 "",
305 false,
306 true
307 );
308 $this->ctrl->setParameter($this, "file_id", "");
309 break;
310
311 case "User":
313 if ($obj_type == "usr") {
314 $back = $this->ctrl->getLinkTarget(
315 $this,
316 "edit",
317 "",
318 false,
319 true
320 );
321 //var_dump($back); exit;
322 $this->ctrl->setParameterByClass("ilpublicuserprofilegui", "user_id", $target_id);
323 $this->ctrl->setParameterByClass(
324 "ilpublicuserprofilegui",
325 "back_url",
326 rawurlencode($back)
327 );
328 $href = "";
330 $href = $this->ctrl->getLinkTargetByClass(
331 "ilpublicuserprofilegui",
332 "getHTML",
333 "",
334 false,
335 true
336 );
337 }
338 $this->ctrl->setParameterByClass("ilpublicuserprofilegui", "user_id", "");
339 $lcontent = ilUserUtil::getNamePresentation($target_id, false, false);
340 }
341 break;
342
343 }
344
345 if ($href != "") {
346 $anc_par = 'Anchor="' . $anc . '"';
347 $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " .
348 "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" LinkContent=\"$lcontent\" $anc_par/>";
349 }
350 }
351 }
352 $link_info .= "</IntLinkInfos>";
353 //echo ":".htmlentities($link_info).":";
354 return $link_info;
355 }
356
360 public function updateHistory()
361 {
363 $this->obj->getId(),
364 "update",
365 "",
366 $this->content_object->getType() . ":pg",
367 "",
368 true
369 );
370 }
371
377 public static function _goto($a_target)
378 {
379 global $DIC;
380
381 $rbacsystem = $DIC->rbac()->system();
382 $ilErr = $DIC["ilErr"];
383 $lng = $DIC->language();
384 $ilAccess = $DIC->access();
385
386 $first = strpos($a_target, "_");
387 $second = strpos($a_target, "_", $first + 1);
388 $page_id = substr($a_target, 0, $first);
389 if ($first > 0) {
390 $page_id = substr($a_target, 0, $first);
391 if ($second > 0) {
392 $ref_id = substr($a_target, $first + 1, $second - ($first + 1));
393 $anchor = substr($a_target, $second + 1);
394 } else {
395 $ref_id = substr($a_target, $first + 1);
396 }
397 } else {
398 $page_id = $a_target;
399 }
400
401 // determine learning object
402 $lm_id = ilLMObject::_lookupContObjID($page_id);
403
404 // get all references
405 $ref_ids = ilObject::_getAllReferences($lm_id);
406
407 // always try passed ref id first
408 if (in_array($ref_id, $ref_ids)) {
409 $ref_ids = array_merge(array($ref_id), $ref_ids);
410 }
411
412 // check read permissions
413 foreach ($ref_ids as $ref_id) {
414 // check read permissions
415 if ($ilAccess->checkAccess("read", "", $ref_id)) {
416 // don't redirect anymore, just set parameters
417 // (goto.php includes "ilias.php")
418 $_GET["baseClass"] = "ilLMPresentationGUI";
419 $_GET["obj_id"] = $page_id;
420 $_GET["ref_id"] = $ref_id;
421 $_GET["anchor"] = $anchor;
422 include_once("ilias.php");
423 exit;
424 }
425 }
426
427 if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
428 if ($lm_id > 0) {
429 ilUtil::sendFailure(sprintf(
430 $lng->txt("msg_no_perm_read_item"),
432 ), true);
433 } else {
434 $lng->loadLanguageModule("content");
435 ilUtil::sendFailure($lng->txt("page_does_not_exist"), true);
436 }
438 }
439
440 $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
441 }
442
446 public function editLayout()
447 {
449 $ilCtrl = $this->ctrl;
450 $ilTabs = $this->tabs;
451
452 $page_gui = new ilLMPageGUI($this->obj->getId());
453 $page_gui->setEditPreview(true);
454 $page_gui->activateMetaDataEditor(
455 $this->content_object,
456 $this->obj->getType(),
457 $this->obj->getId(),
458 $this->obj,
459 "MDUpdateListener"
460 );
461 $page_gui->setActivationListener($this, "activatePage");
462 $page_gui->setTabHook($this, "addPageTabs");
463 $lm_set = new ilSetting("lm");
464 $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg.svg"));
465 $tpl->setTitle($this->lng->txt("page") . ": " . $this->obj->getTitle());
466 $ilCtrl->getHTML($page_gui);
467 $ilTabs->setTabActive("cont_layout");
468 $this->initEditLayoutForm();
469 $tpl->setContent($this->form->getHTML());
470 }
471
477 public function initEditLayoutForm()
478 {
480 $ilCtrl = $this->ctrl;
481
482 $this->form = new ilPropertyFormGUI();
483
484 // default layout
485 $layout = new ilRadioGroupInputGUI($lng->txt("cont_layout"), "layout");
486
487 if (is_file($im = ilUtil::getImagePath("layout_" . $this->content_object->getLayout() . ".png"))) {
488 $im_tag = ilUtil::img($im, $this->content_object->getLayout());
489 }
490 $layout->addOption(new ilRadioOption("<table><tr><td>" . $im_tag . "</td><td><b>" .
491 $lng->txt("cont_lm_default_layout") .
492 "</b>: " . $lng->txt("cont_layout_" . $this->content_object->getLayout()) .
493 "</td></tr></table>", ""));
494
496 $im_tag = "";
497 if (is_file($im = ilUtil::getImagePath("layout_" . $l . ".png"))) {
498 $im_tag = ilUtil::img($im, $l);
499 }
500 $layout->addOption(new ilRadioOption("<table><tr><td>" . $im_tag . "</td><td><b>" .
501 $lng->txt("cont_layout_" . $l) . "</b>: " . $lng->txt("cont_layout_" . $l . "_desc") .
502 "</td></tr></table>", $l));
503 }
504
505 $layout->setValue($this->obj->getLayout());
506 $this->form->addItem($layout);
507
508 $this->form->addCommandButton("saveLayout", $lng->txt("save"));
509
510 $this->form->setTitle($lng->txt("cont_page_layout"));
511 $this->form->setFormAction($ilCtrl->getFormAction($this));
512 }
513
518 public function saveLayout()
519 {
522 $ilCtrl = $this->ctrl;
523
524 $this->initEditLayoutForm();
525 if ($this->form->checkInput()) {
526 ilLMObject::writeLayout($this->obj->getId(), $this->form->getInput("layout"));
527 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
528 $ilCtrl->redirect($this, "editLayout");
529 }
530 $this->form->setValuesByPost();
531 $tpl->setContent($this->form->getHtml());
532 }
533
537 public function addPageTabs()
538 {
539 $ilTabs = $this->tabs;
540 $ilCtrl = $this->ctrl;
541
542 $ilTabs->addTarget(
543 "cont_layout",
544 $ilCtrl->getLinkTarget($this, 'editLayout'),
545 "editLayout"
546 );
547 }
548
552 public function downloadFile()
553 {
554 $pg_obj = $this->obj->getPageObject();
555 $pg_obj->buildDom();
556 $int_links = $pg_obj->getInternalLinks();
557 foreach ($int_links as $il) {
558 if ($il["Target"] == str_replace("_file_", "_dfile_", $_GET["file_id"])) {
559 $file = explode("_", $_GET["file_id"]);
560 $file_id = (int) $file[count($file) - 1];
561 $fileObj = new ilObjFile($file_id, false);
562 $fileObj->sendFile();
563 exit;
564 }
565 }
566 }
567
571 public function create()
572 {
573 $ui = $this->ui;
576
578 $tabs->setBackTarget($lng->txt("back"), $ctrl->getLinkTarget($this, "cancel"));
579
580 $ctrl->setParameter($this, "new_type", "pg");
581 $form = $this->initNewPageForm();
582
583 $this->tpl->setContent($ui->renderer()->render($form) . self::getLayoutCssFix());
584 }
585
590 public function initNewPageForm()
591 {
592 $ui = $this->ui;
593 $f = $ui->factory();
596
597 $fields["title"] = $f->input()->field()->text($lng->txt("title"), "");
598
599 $fields["description"] = $f->input()->field()->textarea($lng->txt("description"));
600
601 $ts = ilPageLayoutGUI::getTemplateSelection(ilPageLayout::MODULE_LM);
602 if (!is_null($ts)) {
603 $fields["layout_id"] = $ts;
604 }
605
606 // section
607 $section1 = $f->input()->field()->section($fields, $lng->txt("cont_insert_pagelayout"));
608
609 $form_action = $ctrl->getLinkTarget($this, "save");
610 return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
611 }
612
616 public function save()
617 {
618 global $DIC;
619
620 $request = $DIC->http()->request();
622
623 $form = $this->initNewPageForm();
624 if ($request->getMethod() == "POST") {
625 $form = $form->withRequest($request);
626 $data = $form->getData()["sec"];
627
628 $layout_id = (int) $data["layout_id"];
629
630 $this->obj = new ilLMPageObject($this->content_object);
631 $this->obj->setType("pg");
632 $this->obj->setTitle(ilUtil::stripSlashes($data["title"]));
633 $this->obj->setDescription(ilUtil::stripSlashes($data["description"]));
634 $this->obj->setLMId($this->content_object->getId());
635 if ($layout_id > 0) {
636 $this->obj->create(false, false, $layout_id);
637 } else {
638 $this->obj->create();
639 }
640 ilUtil::sendSuccess($lng->txt("cont_page_created"), true);
641 }
642 $this->cancel();
643 }
644
650 public static function getLayoutCssFix()
651 {
652 return "
653 <style>
654 .form-control.il-input-radiooption > label {
655 vertical-align: middle;
656 }
657 .form-control.il-input-radiooption > .help-block {
658 padding-left: 2rem;
659 }
660 </style>
661 ";
662 }
663}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
static _getFrame($a_class, $a_type='')
Get content frame name.
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
Class ilLMObject.
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
static writeLayout($a_obj_id, $a_layout, $a_lm=null)
Write layout setting.
Extension of ilPageObjectGUI for learning modules.
Class ilLMPageObjectGUI.
__construct(&$a_content_obj)
Constructor.
editLayout()
Edit layout of page.
initEditLayoutForm()
Init edit layout form.
setLMPageObject($a_pg_obj)
Set content object dependent page object (co page)
downloadFile()
download file of file lists
executeCommand()
execute command
static getLayoutCssFix()
Get layout css fix (workaround for broken radio options)
create()
structure / page object creation form
initNewPageForm()
Init insert template form.
static _goto($a_target)
redirect script
getLinkXML($a_int_links)
get link targets
Class ilLMPageObject.
static _getPresentationTitle( $a_pg_id, $a_mode=self::CHAPTER_TITLE, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_force_content=false, $a_lm_id=0, $a_lang="-", $a_include_short=false)
presentation title doesn't have to be page title, it may be chapter title + page title or chapter tit...
static getAvailableLayouts()
get all available lm layouts
Class ilObjFile.
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
static _gotoRepositoryRoot($a_raise_error=false)
Goto repository root.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
static _exists($a_parent_type, $a_id, $a_lang="", $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.
static hasPublicProfile($a_user_id)
Has public profile.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24
$target_id
Definition: goto.php:51
$target_arr
Definition: goto.php:49
exit
Definition: login.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
global $ilSetting
Definition: privfeed.php:17
$type
$ilErr
Definition: raiseError.php:18
settings()
Definition: settings.php:2
$lm_set
$data
Definition: storeScorm.php:23