ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLMPresentationLinker.php
Go to the documentation of this file.
1<?php
2
20
26{
27 public const TARGET_GUI = "illmpresentationgui";
28 protected int $obj_id;
29 protected string $frame;
30 protected int $requested_ref_id;
31 protected string $profile_back_url = "";
32
33 protected bool $offline;
34 protected bool $embed_mode;
35 protected ilCtrl $ctrl;
36 protected ilLMTree $lm_tree;
38 protected int $current_page;
39 protected string $back_pg;
40 protected string $from_page;
41 protected bool $export_all_languages;
42 protected string $lang;
43 protected string $export_format;
44
45 public function __construct(
48 int $current_page,
49 int $ref_id,
50 string $lang,
51 string $back_pg,
52 string $from_pg,
53 bool $offline,
54 string $export_format,
56 ?ilCtrl $ctrl = null,
57 bool $embed_mode = false,
58 string $frame = "",
59 int $obj_id = 0
60 ) {
61 global $DIC;
62
63 $this->ctrl = is_null($ctrl)
64 ? $DIC->ctrl()
65 : $ctrl;
66
67 $this->lm_tree = $lm_tree;
68 $this->lm = $lm;
69 $this->current_page = $current_page;
70 $this->back_pg = $back_pg;
71 $this->from_page = $from_pg;
72 $this->export_all_languages = $export_all_languages;
73 $this->lang = $lang;
74 $this->requested_ref_id = $ref_id;
75 $this->offline = $offline;
76 $this->export_format = $export_format;
77 $this->embed_mode = $embed_mode;
78 $this->frame = $frame;
79 $this->obj_id = $obj_id;
80 }
81
82 public function setOffline(
83 bool $offline = true
84 ): void {
85 $this->offline = $offline;
86 }
87
88 public function setProfileBackUrl(string $url): void
89 {
90 $this->profile_back_url = $url;
91 }
92
96 public function getLink(
97 string $a_cmd = "",
98 int $a_obj_id = 0,
99 string $a_frame = "",
100 string $a_type = "",
101 string $a_back_link = "append",
102 string $a_anchor = "",
103 string $a_srcstring = ""
104 ): string {
105 if ($a_cmd == "") {
106 $a_cmd = "layout";
107 }
108
109 $link = "";
110
111 // handling of free pages
112 $cur_page_id = $this->current_page;
113 $back_pg = $this->back_pg;
114 if ($a_obj_id !== 0 && !$this->lm_tree->isInTree($a_obj_id) && $cur_page_id !== 0 &&
115 $a_back_link == "append") {
116 if ($back_pg != "") {
117 $back_pg = $cur_page_id . ":" . $back_pg;
118 } else {
119 $back_pg = $cur_page_id;
120 }
121 } else {
122 if ($a_back_link == "reduce") {
123 $limpos = strpos($this->back_pg, ":");
124
125 if ($limpos > 0) {
126 $back_pg = substr($back_pg, strpos($back_pg, ":") + 1);
127 } else {
128 $back_pg = "";
129 }
130 } elseif ($a_back_link != "keep") {
131 $back_pg = "";
132 }
133 }
134
135 // handle kiosk mode links
136 if ($this->embed_mode && in_array($a_cmd, ["downloadFile", "download_paragraph", "fullscreen"])) {
137 $this->ctrl->setParameterByClass(\ilLMPresentationGUI::class, "ref_id", $this->lm->getRefId());
138 $base = $this->ctrl->getLinkTargetByClass([
139 \ilLMPresentationGUI::class, \ilLMPageGUI::class
140 ]);
141 switch ($a_cmd) {
142 case "downloadFile":
143 return $base . "&cmd=downloadFile";
144 case "download_paragraph":
145 return $base . "&cmd=download_paragraph";
146 case "fullscreen":
147 return $base . "&cmd=displayMediaFullscreen";
148 }
149 return "";
150 // handle online links
151 } elseif (!$this->offline) {
152 if ($this->from_page == "") {
153 // added if due to #23216 (from page has been set in lots of usual navigation links)
154 if (!in_array($a_frame, array("", "_blank"))) {
155 $this->ctrl->setParameterByClass(self::TARGET_GUI, "from_page", $cur_page_id);
156 }
157 } else {
158 // faq link on page (in faq frame) includes faq link on other page
159 // if added due to bug #11007
160 if (!in_array($a_frame, array("", "_blank"))) {
161 $this->ctrl->setParameterByClass(self::TARGET_GUI, "from_page", $this->from_page);
162 }
163 }
164
165 if ($a_anchor != "") {
166 $this->ctrl->setParameterByClass(self::TARGET_GUI, "anchor", rawurlencode($a_anchor));
167 }
168 if ($a_srcstring != "") {
169 $this->ctrl->setParameterByClass(self::TARGET_GUI, "srcstring", $a_srcstring);
170 }
171 $this->ctrl->setParameterByClass(self::TARGET_GUI, "ref_id", $this->lm->getRefId());
172 switch ($a_cmd) {
173 case "fullscreen":
174 $link = $this->ctrl->getLinkTargetByClass(self::TARGET_GUI, "fullscreen", "", false, false);
175 break;
176
177 case "sourcecodeDownload":
178 case "download_paragraph":
179 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->current_page);
180 $link = $this->ctrl->getLinkTargetByClass([self::TARGET_GUI, "ilLMPageGUI"], "", "", false, false);
181 break;
182
183 default:
184 $link = "";
185 if ($back_pg != "") {
186 $this->ctrl->setParameterByClass(self::TARGET_GUI, "back_pg", $back_pg);
187 }
188 if ($a_frame != "") {
189 $this->ctrl->setParameterByClass(self::TARGET_GUI, "frame", $a_frame);
190 }
191 if ($a_obj_id > 0) {
192 switch ($a_type) {
193 case "MediaObject":
194 $this->ctrl->setParameterByClass(self::TARGET_GUI, "mob_id", $a_obj_id);
195 break;
196
197 default:
198 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", $a_obj_id);
199 $link .= "&amp;obj_id=" . $a_obj_id;
200 break;
201 }
202 }
203 if ($a_type != "") {
204 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_type", $a_type);
205 }
206 if ($a_anchor !== "") {
207 $a_anchor = "copganc_" . $a_anchor;
208 }
209 $link = $this->ctrl->getLinkTargetByClass(
210 self::TARGET_GUI,
211 $a_cmd,
212 $a_anchor,
213 false,
214 true
215 );
216 // $link = str_replace("&", "&amp;", $link);
217
218 $this->ctrl->setParameterByClass(self::TARGET_GUI, "frame", null);
219 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", null);
220 $this->ctrl->setParameterByClass(self::TARGET_GUI, "mob_id", null);
221 break;
222 }
223 } else { // handle offline links
224 $lang_suffix = "";
225 if ($this->export_all_languages) {
226 if ($this->lang != "" && $this->lang != "-") {
227 $lang_suffix = "_" . $this->lang;
228 }
229 }
230
231 switch ($a_cmd) {
232 case "fullscreen":
233 $link = "fullscreen.html"; // id is handled by xslt
234 break;
235
236 case "layout":
237
238 if ($a_obj_id === 0) {
239 $a_obj_id = $this->lm_tree->getRootId();
240 $pg_node = $this->lm_tree->fetchSuccessorNode($a_obj_id, "pg");
241 $a_obj_id = $pg_node["obj_id"];
242 }
243 if ($a_type == "StructureObject") {
244 $pg_node = $this->lm_tree->fetchSuccessorNode($a_obj_id, "pg");
245 $a_obj_id = $pg_node["obj_id"];
246 }
247 if ($a_frame != "" && $a_frame != "_blank") {
248 if ($a_frame != "toc") {
249 $link = "frame_" . $a_obj_id . "_" . $a_frame . $lang_suffix . ".html";
250 } else { // don't save multiple toc frames (all the same)
251 $link = "frame_" . $a_frame . $lang_suffix . ".html";
252 }
253 } else {
254 //if ($nid = ilLMObject::_lookupNID($this->lm->getId(), $a_obj_id, "pg"))
255 if ($nid = ilLMPageObject::getExportId($this->lm->getId(), $a_obj_id)) {
256 $link = "lm_pg_" . $nid . $lang_suffix . ".html";
257 } else {
258 $link = "lm_pg_" . $a_obj_id . $lang_suffix . ".html";
259 }
260 }
261 break;
262
263 case "glossary":
264 $link = "term_" . $a_obj_id . ".html";
265 break;
266
267 case "media":
268 $link = "media_" . $a_obj_id . ".html";
269 break;
270
271 case "downloadFile":
272 default:
273 break;
274 }
275 }
276 $this->ctrl->clearParametersByClass(self::TARGET_GUI);
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":
356 $lm_id = ilLMObject::_lookupContObjID($target_id);
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,
374 $target_id,
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 = "";
416 if (ilGlossaryTerm::_exists((int) $target_id)) {
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 if ($this->embed_mode) {
456 $ltarget = "_blank";
457 }
458 break;
459
460 case "WikiPage":
461 $wiki_anc = "";
462 if (($int_link["Anchor"] ?? "") != "") {
463 $wiki_anc = "#" . rawurlencode($int_link["Anchor"]);
464 }
465 $href = ilWikiPage::getGotoForWikiPageTarget($target_id) . $wiki_anc;
466 if ($this->embed_mode) {
467 $ltarget = "_blank";
468 }
469 break;
470
471 case "File":
472 if (!$this->offline) {
473 $ilCtrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->current_page);
474 $ilCtrl->setParameterByClass(self::TARGET_GUI, "file_id", "il__file_" . $target_id);
475 $href = $ilCtrl->getLinkTargetByClass(
476 self::TARGET_GUI,
477 "downloadFile",
478 "",
479 false,
480 true
481 );
482 $ilCtrl->setParameterByClass(self::TARGET_GUI, "file_id", "");
483 $ilCtrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->obj_id);
484 }
485 break;
486
487 case "User":
488 $obj_type = ilObject::_lookupType((int) $target_id);
489 if ($obj_type == "usr") {
490 if (!$this->embed_mode) {
491 $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->current_page);
492 $back = $this->ctrl->getLinkTargetByClass(
493 self::TARGET_GUI,
494 "layout",
495 "",
496 false,
497 true
498 );
499 }
500 //var_dump($back); exit;
501 $this->ctrl->setParameterByClass(PublicProfileGUI::class, "user_id", $target_id);
502 $this->ctrl->setParameterByClass(
503 PublicProfileGUI::class,
504 "back_url",
505 rawurlencode($back)
506 );
507 $href = "";
508 if (ilUserUtil::hasPublicProfile($target_id)) {
509 $href = $this->ctrl->getLinkTargetByClass(
510 PublicProfileGUI::class,
511 "getHTML",
512 "",
513 false,
514 true
515 );
516 }
517 $this->ctrl->setParameterByClass(PublicProfileGUI::class, "user_id", "");
518 $lcontent = ilUserUtil::getNamePresentation($target_id, false, false);
519 }
520 break;
521 }
522
523 $anc_par = 'Anchor="' . $anc . '"';
524
525 if ($href != "") {
526 $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " .
527 "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" LinkContent=\"$lcontent\" $anc_par/>";
528 }
529 }
530 }
531 $link_info .= "</IntLinkInfos>";
532
533 $link_info .= $this->getLinkTargetsXML();
534 return $link_info;
535 }
536
537 public function getFullscreenLink(): string
538 {
539 return $this->getLink("fullscreen");
540 }
541}
GUI class for public user profile presentation.
Class ilCtrl provides processing control methods.
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")
Learning module presentation linker.
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 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 getGotoForWikiPageTarget(string $a_target, bool $a_offline=false)
const CLIENT_ID
Definition: constants.php:41
$ref_id
Definition: ltiauth.php:66
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68
$lang
Definition: xapiexit.php:25