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