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