ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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(
45  ilLMTree $lm_tree,
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,
53  bool $export_all_languages,
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  case "fullscreen":
231  $link = "fullscreen.html"; // id is handled by xslt
232  break;
233 
234  case "layout":
235 
236  if ($a_obj_id === 0) {
237  $a_obj_id = $this->lm_tree->getRootId();
238  $pg_node = $this->lm_tree->fetchSuccessorNode($a_obj_id, "pg");
239  $a_obj_id = $pg_node["obj_id"];
240  }
241  if ($a_type == "StructureObject") {
242  $pg_node = $this->lm_tree->fetchSuccessorNode($a_obj_id, "pg");
243  $a_obj_id = $pg_node["obj_id"];
244  }
245  if ($a_frame != "" && $a_frame != "_blank") {
246  if ($a_frame != "toc") {
247  $link = "frame_" . $a_obj_id . "_" . $a_frame . $lang_suffix . ".html";
248  } else { // don't save multiple toc frames (all the same)
249  $link = "frame_" . $a_frame . $lang_suffix . ".html";
250  }
251  } else {
252  //if ($nid = ilLMObject::_lookupNID($this->lm->getId(), $a_obj_id, "pg"))
253  if ($nid = ilLMPageObject::getExportId($this->lm->getId(), $a_obj_id)) {
254  $link = "lm_pg_" . $nid . $lang_suffix . ".html";
255  } else {
256  $link = "lm_pg_" . $a_obj_id . $lang_suffix . ".html";
257  }
258  }
259  break;
260 
261  case "glossary":
262  $link = "term_" . $a_obj_id . ".html";
263  break;
264 
265  case "media":
266  $link = "media_" . $a_obj_id . ".html";
267  break;
268 
269  case "downloadFile":
270  default:
271  break;
272  }
273  }
274  $this->ctrl->clearParametersByClass(self::TARGET_GUI);
275  return $link;
276  }
277 
278  public function getLayoutLinkTargets(): array
279  {
280  $targets = [
281  "New" => [
282  "Type" => "New",
283  "Frame" => "_blank",
284  "OnClick" => ""],
285  "FAQ" => [
286  "Type" => "FAQ",
287  "Frame" => "faq",
288  "OnClick" => "return il.LearningModule.showContentFrame(event, 'faq');"],
289  "Glossary" => [
290  "Type" => "Glossary",
291  "OnClick" => "return il.LearningModule.showContentFrame(event, 'glossary');"],
292  "Media" => [
293  "Type" => "Media",
294  "Frame" => "media",
295  "OnClick" => "return il.LearningModule.showContentFrame(event, 'media');"]
296  ];
297 
298  return $targets;
299  }
300 
304  public function getLinkTargetsXML(): string
305  {
306  $link_info = "<LinkTargets>";
307  foreach ($this->getLayoutLinkTargets() as $k => $t) {
308  $link_info .= "<LinkTarget TargetFrame=\"" . $t["Type"] . "\" LinkTarget=\"" . ($t["Frame"] ?? "") . "\" OnClick=\"" . $t["OnClick"] . "\" />";
309  }
310  $link_info .= "</LinkTargets>";
311  return $link_info;
312  }
313 
317  public function getLinkXML(
318  array $int_links
319  ): string {
320  $ilCtrl = $this->ctrl;
321  $a_layoutframes = $this->getLayoutLinkTargets();
322 
323  // Determine whether the view of a learning resource should
324  // be shown in the frameset of ilias, or in a separate window.
325  $showViewInFrameset = true;
326 
327  if ($a_layoutframes == "") {
328  $a_layoutframes = array();
329  }
330  $link_info = "<IntLinkInfos>";
331  foreach ($int_links as $int_link) {
332  $back = "";
333  $href = "";
334  $ltarget = "";
335  $target = $int_link["Target"];
336  if (substr($target, 0, 4) == "il__") {
337  $target_arr = explode("_", $target);
338  $target_id = $target_arr[count($target_arr) - 1];
339  $type = $int_link["Type"];
340  $targetframe = ($int_link["TargetFrame"] != "")
341  ? $int_link["TargetFrame"]
342  : "None";
343 
344  // anchor
345  $anc = $anc_add = "";
346  if (($int_link["Anchor"] ?? "") != "") {
347  $anc = $int_link["Anchor"];
348  $anc_add = "_" . rawurlencode($int_link["Anchor"]);
349  }
350  $lcontent = "";
351  switch ($type) {
352  case "PageObject":
353  case "StructureObject":
354  $lm_id = ilLMObject::_lookupContObjID($target_id);
355  if ($lm_id == $this->lm->getId() ||
356  ($targetframe != "None" && $targetframe != "New")) {
357  $ltarget = $a_layoutframes[$targetframe]["Frame"] ?? "";
358  $nframe = ($ltarget == "")
359  ? ""
360  : $ltarget;
361  if ($ltarget == "") {
362  $ltarget = "_parent";
363  }
364  $cmd = "layout";
365  // page command is for displaying in the slate
366  if ($nframe != "" && $nframe != "_blank") {
367  $cmd = "page";
368  }
369  $href =
370  $this->getLink(
371  $cmd,
372  $target_id,
373  $nframe,
374  $type,
375  "append",
376  $anc
377  );
378  if ($lm_id === 0) {
379  $href = "";
380  }
381  if ($this->embed_mode) {
382  $ltarget = "_blank";
383  }
384  } else {
385  if (!$this->offline) {
386  if ($type == "PageObject") {
387  $href = "./goto.php?target=pg_" . $target_id . $anc_add;
388  } else {
389  $href = "./goto.php?target=st_" . $target_id;
390  }
391  } else {
392  if ($type == "PageObject") {
393  $href = ILIAS_HTTP_PATH . "/goto.php?target=pg_" . $target_id . $anc_add . "&amp;client_id=" . CLIENT_ID;
394  } else {
395  $href = ILIAS_HTTP_PATH . "/goto.php?target=st_" . $target_id . "&amp;client_id=" . CLIENT_ID;
396  }
397  }
398  $ltarget = "";
399  if ($targetframe == "New" || $this->embed_mode) {
400  $ltarget = "_blank";
401  }
402  }
403  break;
404 
405  case "GlossaryItem":
406  if ($targetframe == "None") {
407  $targetframe = "Glossary";
408  }
409  $ltarget = $a_layoutframes[$targetframe]["Frame"] ?? "";
410  $nframe = ($ltarget == "")
411  ? $this->frame
412  : $ltarget;
413  $href = "";
414  if (ilGlossaryTerm::_exists((int) $target_id)) {
415  $href =
416  $this->getLink($a_cmd = "glossary", (int) $target_id, $nframe, $type);
417  }
418  break;
419 
420  case "MediaObject":
421  $ltarget = $a_layoutframes[$targetframe]["Frame"] ?? "";
422  $nframe = ($ltarget == "")
423  ? $this->frame
424  : $ltarget;
425  $href =
426  $this->getLink($a_cmd = "media", $target_id, $nframe, $type);
427  if ($this->offline) {
428  $href = "media_" . $target_id . ".html";
429  } else {
430  $this->ctrl->setParameterByClass("illmpagegui", "ref_id", $this->lm->getRefId());
431  $this->ctrl->setParameterByClass("illmpagegui", "mob_id", $target_id);
432  $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->current_page);
433  $href = $this->ctrl->getLinkTargetByClass(
434  "illmpagegui",
435  "displayMedia",
436  "",
437  false,
438  true
439  );
440  $this->ctrl->setParameterByClass("illmpagegui", "mob_id", "");
441  $ilCtrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->obj_id);
442  }
443  break;
444 
445  case "RepositoryItem":
446  $obj_type = ilObject::_lookupType((int) $target_id, true);
447  $obj_id = ilObject::_lookupObjId((int) $target_id);
448  if (!$this->offline) {
449  $href = "./goto.php?target=" . $obj_type . "_" . $target_id;
450  } else {
451  $href = ILIAS_HTTP_PATH . "/goto.php?target=" . $obj_type . "_" . $target_id . "&amp;client_id=" . CLIENT_ID;
452  }
453  if ($this->embed_mode) {
454  $ltarget = "_blank";
455  }
456  break;
457 
458  case "WikiPage":
459  $wiki_anc = "";
460  if (($int_link["Anchor"] ?? "") != "") {
461  $wiki_anc = "#" . rawurlencode($int_link["Anchor"]);
462  }
463  $href = ilWikiPage::getGotoForWikiPageTarget($target_id) . $wiki_anc;
464  if ($this->embed_mode) {
465  $ltarget = "_blank";
466  }
467  break;
468 
469  case "File":
470  if (!$this->offline) {
471  $ilCtrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->current_page);
472  $ilCtrl->setParameterByClass(self::TARGET_GUI, "file_id", "il__file_" . $target_id);
473  $href = $ilCtrl->getLinkTargetByClass(
474  self::TARGET_GUI,
475  "downloadFile",
476  "",
477  false,
478  true
479  );
480  $ilCtrl->setParameterByClass(self::TARGET_GUI, "file_id", "");
481  $ilCtrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->obj_id);
482  }
483  break;
484 
485  case "User":
486  $obj_type = ilObject::_lookupType((int) $target_id);
487  if ($obj_type == "usr") {
488  if (!$this->embed_mode) {
489  $this->ctrl->setParameterByClass(self::TARGET_GUI, "obj_id", $this->current_page);
490  $back = $this->ctrl->getLinkTargetByClass(
491  self::TARGET_GUI,
492  "layout",
493  "",
494  false,
495  true
496  );
497  }
498  //var_dump($back); exit;
499  $this->ctrl->setParameterByClass("ilpublicuserprofilegui", "user_id", $target_id);
500  $this->ctrl->setParameterByClass(
501  "ilpublicuserprofilegui",
502  "back_url",
503  rawurlencode($back)
504  );
505  $href = "";
506  if (ilUserUtil::hasPublicProfile($target_id)) {
507  $href = $this->ctrl->getLinkTargetByClass(
508  "ilpublicuserprofilegui",
509  "getHTML",
510  "",
511  false,
512  true
513  );
514  }
515  $this->ctrl->setParameterByClass("ilpublicuserprofilegui", "user_id", "");
516  $lcontent = ilUserUtil::getNamePresentation($target_id, false, false);
517  }
518  break;
519  }
520 
521  $anc_par = 'Anchor="' . $anc . '"';
522 
523  if ($href != "") {
524  $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " .
525  "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" LinkContent=\"$lcontent\" $anc_par/>";
526  }
527  }
528  }
529  $link_info .= "</IntLinkInfos>";
530 
531  $link_info .= $this->getLinkTargetsXML();
532  return $link_info;
533  }
534 
535  public function getFullscreenLink(): string
536  {
537  return $this->getLink("fullscreen");
538  }
539 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getExportId(int $a_lm_id, int $a_lmobj_id, string $a_type="pg")
static _exists(int $a_id)
checks whether a glossary term with specified id exists or not
getLinkXML(array $int_links)
get xml for links
$url
Definition: shib_logout.php:66
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
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:
const CLIENT_ID
Definition: constants.php:41
getLinkTargetsXML()
Get XMl for Link Targets.
global $DIC
Definition: shib_login.php:22
__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)
static getGotoForWikiPageTarget(string $a_target, bool $a_offline=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static hasPublicProfile(int $a_user_id)
static _lookupContObjID(int $a_id)
get learning module id for lm object
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
static _lookupType(int $id, bool $reference=false)