ILIAS  release_8 Revision v8.24
class.ilLMPresentationLinker.php
Go to the documentation of this file.
1<?php
2
24{
25 public const TARGET_GUI = "illmpresentationgui";
26 protected int $obj_id;
27 protected string $frame;
28 protected int $requested_ref_id;
29 protected string $profile_back_url = "";
30
31 protected bool $offline;
32 protected bool $embed_mode;
33 protected ilCtrl $ctrl;
34 protected ilLMTree $lm_tree;
36 protected int $current_page;
37 protected string $back_pg;
38 protected string $from_page;
39 protected bool $export_all_languages;
40 protected string $lang;
41 protected string $export_format;
42
43 public function __construct(
46 int $current_page,
47 int $ref_id,
48 string $lang,
49 string $back_pg,
50 string $from_pg,
51 bool $offline,
52 string $export_format,
54 ilCtrl $ctrl = null,
55 bool $embed_mode = false,
56 string $frame = "",
57 int $obj_id = 0
58 ) {
59 global $DIC;
60
61 $this->ctrl = is_null($ctrl)
62 ? $DIC->ctrl()
63 : $ctrl;
64
65 $this->lm_tree = $lm_tree;
66 $this->lm = $lm;
67 $this->current_page = $current_page;
68 $this->back_pg = $back_pg;
69 $this->from_page = $from_pg;
70 $this->export_all_languages = $export_all_languages;
71 $this->lang = $lang;
72 $this->requested_ref_id = $ref_id;
73 $this->offline = $offline;
74 $this->export_format = $export_format;
75 $this->embed_mode = $embed_mode;
76 $this->frame = $frame;
77 $this->obj_id = $obj_id;
78 }
79
80 public function setOffline(
81 bool $offline = true
82 ): void {
83 $this->offline = $offline;
84 }
85
86 public function setProfileBackUrl(string $url): void
87 {
88 $this->profile_back_url = $url;
89 }
90
94 public function getLink(
95 string $a_cmd = "",
96 int $a_obj_id = 0,
97 string $a_frame = "",
98 string $a_type = "",
99 string $a_back_link = "append",
100 string $a_anchor = "",
101 string $a_srcstring = ""
102 ): string {
103 if ($a_cmd == "") {
104 $a_cmd = "layout";
105 }
106
107 $link = "";
108
109 // handling of free pages
110 $cur_page_id = $this->current_page;
111 $back_pg = $this->back_pg;
112 if ($a_obj_id !== 0 && !$this->lm_tree->isInTree($a_obj_id) && $cur_page_id !== 0 &&
113 $a_back_link == "append") {
114 if ($back_pg != "") {
115 $back_pg = $cur_page_id . ":" . $back_pg;
116 } else {
117 $back_pg = $cur_page_id;
118 }
119 } else {
120 if ($a_back_link == "reduce") {
121 $limpos = strpos($this->back_pg, ":");
122
123 if ($limpos > 0) {
124 $back_pg = substr($back_pg, strpos($back_pg, ":") + 1);
125 } else {
126 $back_pg = "";
127 }
128 } elseif ($a_back_link != "keep") {
129 $back_pg = "";
130 }
131 }
132
133 // handle kiosk mode links
134 if ($this->embed_mode && in_array($a_cmd, ["downloadFile", "download_paragraph", "fullscreen"])) {
135 $this->ctrl->setParameterByClass(\ilLMPresentationGUI::class, "ref_id", $this->lm->getRefId());
136 $base = $this->ctrl->getLinkTargetByClass([
137 \ilLMPresentationGUI::class, \ilLMPageGUI::class
138 ]);
139 switch ($a_cmd) {
140 case "downloadFile":
141 return $base . "&cmd=downloadFile";
142 case "download_paragraph":
143 return $base . "&cmd=download_paragraph";
144 case "fullscreen":
145 return $base . "&cmd=displayMediaFullscreen";
146 }
147 return "";
148 // handle online links
149 } elseif (!$this->offline) {
150 if ($this->from_page == "") {
151 // added if due to #23216 (from page has been set in lots of usual navigation links)
152 if (!in_array($a_frame, array("", "_blank"))) {
153 $this->ctrl->setParameterByClass(self::TARGET_GUI, "from_page", $cur_page_id);
154 }
155 } else {
156 // faq link on page (in faq frame) includes faq link on other page
157 // if added due to bug #11007
158 if (!in_array($a_frame, array("", "_blank"))) {
159 $this->ctrl->setParameterByClass(self::TARGET_GUI, "from_page", $this->from_page);
160 }
161 }
162
163 if ($a_anchor != "") {
164 $this->ctrl->setParameterByClass(self::TARGET_GUI, "anchor", rawurlencode($a_anchor));
165 }
166 if ($a_srcstring != "") {
167 $this->ctrl->setParameterByClass(self::TARGET_GUI, "srcstring", $a_srcstring);
168 }
169 $this->ctrl->setParameterByClass(self::TARGET_GUI, "ref_id", $this->lm->getRefId());
170 switch ($a_cmd) {
171 case "fullscreen":
172 $link = $this->ctrl->getLinkTargetByClass(self::TARGET_GUI, "fullscreen", "", false, false);
173 break;
174
175 case "sourcecodeDownload":
176 case "download_paragraph":
177 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->current_page);
178 $link = $this->ctrl->getLinkTargetByClass([self::TARGET_GUI, "ilLMPageGUI"], "", "", false, false);
179 break;
180
181 default:
182 $link = "";
183 if ($back_pg != "") {
184 $this->ctrl->setParameterByClass(self::TARGET_GUI, "back_pg", $back_pg);
185 }
186 if ($a_frame != "") {
187 $this->ctrl->setParameterByClass(self::TARGET_GUI, "frame", $a_frame);
188 }
189 if ($a_obj_id !== 0) {
190 switch ($a_type) {
191 case "MediaObject":
192 $this->ctrl->setParameterByClass(self::TARGET_GUI, "mob_id", $a_obj_id);
193 break;
194
195 default:
196 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", $a_obj_id);
197 $link .= "&amp;obj_id=" . $a_obj_id;
198 break;
199 }
200 }
201 if ($a_type != "") {
202 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_type", $a_type);
203 }
204 if ($a_anchor !== "") {
205 $a_anchor = "copganc_" . $a_anchor;
206 }
207 $link = $this->ctrl->getLinkTargetByClass(
208 self::TARGET_GUI,
209 $a_cmd,
210 $a_anchor,
211 false,
212 true
213 );
214// $link = str_replace("&", "&amp;", $link);
215
216 $this->ctrl->setParameterByClass(self::TARGET_GUI, "frame", null);
217 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", null);
218 $this->ctrl->setParameterByClass(self::TARGET_GUI, "mob_id", null);
219 break;
220 }
221 } else { // handle offline links
222 $lang_suffix = "";
223 if ($this->export_all_languages) {
224 if ($this->lang != "" && $this->lang != "-") {
225 $lang_suffix = "_" . $this->lang;
226 }
227 }
228
229 switch ($a_cmd) {
230
231 case "fullscreen":
232 $link = "fullscreen.html"; // id is handled by xslt
233 break;
234
235 case "layout":
236
237 if ($a_obj_id === 0) {
238 $a_obj_id = $this->lm_tree->getRootId();
239 $pg_node = $this->lm_tree->fetchSuccessorNode($a_obj_id, "pg");
240 $a_obj_id = $pg_node["obj_id"];
241 }
242 if ($a_type == "StructureObject") {
243 $pg_node = $this->lm_tree->fetchSuccessorNode($a_obj_id, "pg");
244 $a_obj_id = $pg_node["obj_id"];
245 }
246 if ($a_frame != "" && $a_frame != "_blank") {
247 if ($a_frame != "toc") {
248 $link = "frame_" . $a_obj_id . "_" . $a_frame . $lang_suffix . ".html";
249 } else { // don't save multiple toc frames (all the same)
250 $link = "frame_" . $a_frame . $lang_suffix . ".html";
251 }
252 } else {
253 //if ($nid = ilLMObject::_lookupNID($this->lm->getId(), $a_obj_id, "pg"))
254 if ($nid = ilLMPageObject::getExportId($this->lm->getId(), $a_obj_id)) {
255 $link = "lm_pg_" . $nid . $lang_suffix . ".html";
256 } else {
257 $link = "lm_pg_" . $a_obj_id . $lang_suffix . ".html";
258 }
259 }
260 break;
261
262 case "glossary":
263 $link = "term_" . $a_obj_id . ".html";
264 break;
265
266 case "media":
267 $link = "media_" . $a_obj_id . ".html";
268 break;
269
270 case "downloadFile":
271 default:
272 break;
273 }
274 }
275 $this->ctrl->clearParametersByClass(self::TARGET_GUI);
276
277 return $link;
278 }
279
280 public function getLayoutLinkTargets(): array
281 {
282 $targets = [
283 "New" => [
284 "Type" => "New",
285 "Frame" => "_blank",
286 "OnClick" => ""],
287 "FAQ" => [
288 "Type" => "FAQ",
289 "Frame" => "faq",
290 "OnClick" => "return il.LearningModule.showContentFrame(event, 'faq');"],
291 "Glossary" => [
292 "Type" => "Glossary",
293 "OnClick" => "return il.LearningModule.showContentFrame(event, 'glossary');"],
294 "Media" => [
295 "Type" => "Media",
296 "Frame" => "media",
297 "OnClick" => "return il.LearningModule.showContentFrame(event, 'media');"]
298 ];
299
300 return $targets;
301 }
302
306 public function getLinkTargetsXML(): string
307 {
308 $link_info = "<LinkTargets>";
309 foreach ($this->getLayoutLinkTargets() as $k => $t) {
310 $link_info .= "<LinkTarget TargetFrame=\"" . $t["Type"] . "\" LinkTarget=\"" . ($t["Frame"] ?? "") . "\" OnClick=\"" . $t["OnClick"] . "\" />";
311 }
312 $link_info .= "</LinkTargets>";
313 return $link_info;
314 }
315
319 public function getLinkXML(
320 array $int_links
321 ): string {
322 $ilCtrl = $this->ctrl;
323 $a_layoutframes = $this->getLayoutLinkTargets();
324
325 // Determine whether the view of a learning resource should
326 // be shown in the frameset of ilias, or in a separate window.
327 $showViewInFrameset = true;
328
329 if ($a_layoutframes == "") {
330 $a_layoutframes = array();
331 }
332 $link_info = "<IntLinkInfos>";
333 foreach ($int_links as $int_link) {
334 $back = "";
335 $href = "";
336 $ltarget = "";
337 $target = $int_link["Target"];
338 if (substr($target, 0, 4) == "il__") {
339 $target_arr = explode("_", $target);
340 $target_id = $target_arr[count($target_arr) - 1];
341 $type = $int_link["Type"];
342 $targetframe = ($int_link["TargetFrame"] != "")
343 ? $int_link["TargetFrame"]
344 : "None";
345
346 // anchor
347 $anc = $anc_add = "";
348 if (($int_link["Anchor"] ?? "") != "") {
349 $anc = $int_link["Anchor"];
350 $anc_add = "_" . rawurlencode($int_link["Anchor"]);
351 }
352 $lcontent = "";
353 switch ($type) {
354 case "PageObject":
355 case "StructureObject":
357 if ($lm_id == $this->lm->getId() ||
358 ($targetframe != "None" && $targetframe != "New")) {
359 $ltarget = $a_layoutframes[$targetframe]["Frame"] ?? "";
360 $nframe = ($ltarget == "")
361 ? ""
362 : $ltarget;
363 if ($ltarget == "") {
364 $ltarget = "_parent";
365 }
366 $cmd = "layout";
367 // page command is for displaying in the slate
368 if ($nframe != "" && $nframe != "_blank") {
369 $cmd = "page";
370 }
371 $href =
372 $this->getLink(
373 $cmd,
375 $nframe,
376 $type,
377 "append",
378 $anc
379 );
380 if ($lm_id === 0) {
381 $href = "";
382 }
383 if ($this->embed_mode) {
384 $ltarget = "_blank";
385 }
386 } else {
387 if (!$this->offline) {
388 if ($type == "PageObject") {
389 $href = "./goto.php?target=pg_" . $target_id . $anc_add;
390 } else {
391 $href = "./goto.php?target=st_" . $target_id;
392 }
393 } else {
394 if ($type == "PageObject") {
395 $href = ILIAS_HTTP_PATH . "/goto.php?target=pg_" . $target_id . $anc_add . "&amp;client_id=" . CLIENT_ID;
396 } else {
397 $href = ILIAS_HTTP_PATH . "/goto.php?target=st_" . $target_id . "&amp;client_id=" . CLIENT_ID;
398 }
399 }
400 $ltarget = "";
401 if ($targetframe == "New" || $this->embed_mode) {
402 $ltarget = "_blank";
403 }
404 }
405 break;
406
407 case "GlossaryItem":
408 if ($targetframe == "None") {
409 $targetframe = "Glossary";
410 }
411 $ltarget = $a_layoutframes[$targetframe]["Frame"] ?? "";
412 $nframe = ($ltarget == "")
413 ? $this->frame
414 : $ltarget;
415 $href = "";
417 $href =
418 $this->getLink($a_cmd = "glossary", (int) $target_id, $nframe, $type);
419 }
420 break;
421
422 case "MediaObject":
423 $ltarget = $a_layoutframes[$targetframe]["Frame"] ?? "";
424 $nframe = ($ltarget == "")
425 ? $this->frame
426 : $ltarget;
427 $href =
428 $this->getLink($a_cmd = "media", $target_id, $nframe, $type);
429 if ($this->offline) {
430 $href = "media_" . $target_id . ".html";
431 } else {
432 $this->ctrl->setParameterByClass("illmpagegui", "ref_id", $this->lm->getRefId());
433 $this->ctrl->setParameterByClass("illmpagegui", "mob_id", $target_id);
434 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->current_page);
435 $href = $this->ctrl->getLinkTargetByClass(
436 "illmpagegui",
437 "displayMedia",
438 "",
439 false,
440 true
441 );
442 $this->ctrl->setParameterByClass("illmpagegui", "mob_id", "");
443 $ilCtrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->obj_id);
444 }
445 break;
446
447 case "RepositoryItem":
448 $obj_type = ilObject::_lookupType((int) $target_id, true);
449 $obj_id = ilObject::_lookupObjId((int) $target_id);
450 if (!$this->offline) {
451 $href = "./goto.php?target=" . $obj_type . "_" . $target_id;
452 } else {
453 $href = ILIAS_HTTP_PATH . "/goto.php?target=" . $obj_type . "_" . $target_id . "&amp;client_id=" . CLIENT_ID;
454 }
455 $ltarget = ilFrameTargetInfo::_getFrame("MainContent");
456 if ($this->embed_mode) {
457 $ltarget = "_blank";
458 }
459 break;
460
461 case "WikiPage":
462 $wiki_anc = "";
463 if (($int_link["Anchor"] ?? "") != "") {
464 $wiki_anc = "#" . rawurlencode($int_link["Anchor"]);
465 }
467 if ($this->embed_mode) {
468 $ltarget = "_blank";
469 }
470 break;
471
472 case "File":
473 if (!$this->offline) {
474 $ilCtrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->current_page);
475 $ilCtrl->setParameterByClass(self::TARGET_GUI, "file_id", "il__file_" . $target_id);
476 $href = $ilCtrl->getLinkTargetByClass(
477 self::TARGET_GUI,
478 "downloadFile",
479 "",
480 false,
481 true
482 );
483 $ilCtrl->setParameterByClass(self::TARGET_GUI, "file_id", "");
484 $ilCtrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->obj_id);
485 }
486 break;
487
488 case "User":
489 $obj_type = ilObject::_lookupType((int) $target_id);
490 if ($obj_type == "usr") {
491 if (!$this->embed_mode) {
492 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->current_page);
493 $back = $this->ctrl->getLinkTargetByClass(
494 self::TARGET_GUI,
495 "layout",
496 "",
497 false,
498 true
499 );
500 }
501 //var_dump($back); exit;
502 $this->ctrl->setParameterByClass("ilpublicuserprofilegui", "user_id", $target_id);
503 $this->ctrl->setParameterByClass(
504 "ilpublicuserprofilegui",
505 "back_url",
506 rawurlencode($back)
507 );
508 $href = "";
510 $href = $this->ctrl->getLinkTargetByClass(
511 "ilpublicuserprofilegui",
512 "getHTML",
513 "",
514 false,
515 true
516 );
517 }
518 $this->ctrl->setParameterByClass("ilpublicuserprofilegui", "user_id", "");
519 $lcontent = ilUserUtil::getNamePresentation($target_id, false, false);
520 }
521 break;
522
523 }
524
525 $anc_par = 'Anchor="' . $anc . '"';
526
527 if ($href != "") {
528 $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " .
529 "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" LinkContent=\"$lcontent\" $anc_par/>";
530 }
531 }
532 }
533 $link_info .= "</IntLinkInfos>";
534
535 $link_info .= $this->getLinkTargetsXML();
536 return $link_info;
537 }
538
539 public function getFullscreenLink(): string
540 {
541 return $this->getLink("fullscreen");
542 }
543}
Class ilCtrl provides processing control methods.
static _getFrame(string $a_class)
static _exists(int $a_id)
checks whether a glossary term with specified id exists or not
static _lookupContObjID(int $a_id)
get learning module id for lm object
static getExportId(int $a_lm_id, int $a_lmobj_id, string $a_type="pg")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLinkXML(array $int_links)
get xml for links
getLink(string $a_cmd="", int $a_obj_id=0, string $a_frame="", string $a_type="", string $a_back_link="append", string $a_anchor="", string $a_srcstring="")
handles links for learning module presentation
getLinkTargetsXML()
Get XMl for Link Targets.
__construct(ilObjLearningModule $lm, ilLMTree $lm_tree, int $current_page, int $ref_id, string $lang, string $back_pg, string $from_pg, bool $offline, string $export_format, bool $export_all_languages, ilCtrl $ctrl=null, bool $embed_mode=false, string $frame="", int $obj_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static hasPublicProfile(int $a_user_id)
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="ilpublicuserprofilegui")
Default behaviour is:
static getGotoForWikiPageTarget(string $a_target, bool $a_offline=false)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
const CLIENT_ID
Definition: constants.php:41
global $DIC
Definition: feed.php:28
$target_id
Definition: goto.php:52
$target_arr
Definition: goto.php:50
$ref_id
Definition: ltiauth.php:67
$base
Definition: index.php:4
$type
$url
$lang
Definition: xapiexit.php:26