ILIAS  trunk Revision v12.0_alpha-1329-g1094ddb0c33
class.ilPageLinker.php
Go to the documentation of this file.
1<?php
2
20
26{
27 protected bool $offline;
28 protected string $profile_back_url = "";
29 protected ilCtrl $ctrl;
30 protected string $cmd_gui;
31 protected \ILIAS\StaticURL\Services $static_url;
32
33 public function __construct(
34 string $cmd_gui_class,
35 bool $offline = false,
36 string $profile_back_url = "",
37 ?ilCtrl $ctrl = null
38 ) {
39 global $DIC;
40
41 $this->offline = $offline;
42 $this->profile_back_url = $profile_back_url;
43 $this->cmd_gui = $cmd_gui_class;
44
45 $this->ctrl = (is_null($ctrl))
46 ? $DIC->ctrl()
47 : $ctrl;
48 $this->static_url = $DIC["static_url"];
49 }
50
51 public function setOffline(bool $offline = true): void
52 {
53 $this->offline = $offline;
54 }
55
56 public function setProfileBackUrl(string $url): void
57 {
58 $this->profile_back_url = $url;
59 }
60
61
62 public function getLayoutLinkTargets(): array
63 {
64 $targets = [];
65 return $targets;
66 }
67
68 public function getLinkTargetsXML(): string
69 {
70 $layoutLinkTargets = $this->getLayoutLinkTargets();
71
72 if (0 === count($layoutLinkTargets)) {
73 return '';
74 }
75
76 $link_info = "<LinkTargets>";
77 foreach ($layoutLinkTargets as $k => $t) {
78 $link_info .= "<LinkTarget TargetFrame=\"" . $t["Type"] . "\" LinkTarget=\"" . $t["Frame"] . "\" OnClick=\"" . $t["OnClick"] . "\" />";
79 }
80 $link_info .= "</LinkTargets>";
81 return $link_info;
82 }
83
84 public function getLinkXML(array $int_links): string
85 {
86 $ilCtrl = $this->ctrl;
87 $link_info = "<IntLinkInfos>";
88 foreach ($int_links as $int_link) {
89 $target = $int_link["Target"];
90 if (substr($target, 0, 4) == "il__") {
91 $target_arr = explode("_", $target);
92 $target_id = $target_arr[count($target_arr) - 1];
93 $type = $int_link["Type"];
94
95 $targetframe = ($int_link["TargetFrame"] != "")
96 ? $int_link["TargetFrame"]
97 : "None";
98
99 $ltarget = "_top";
100 if ($targetframe != "None") {
101 $ltarget = "_blank";
102 }
103
104 // anchor
105 $anc = $anc_add = "";
106 if (($int_link["Anchor"] ?? "") != "") {
107 $anc = $int_link["Anchor"];
108 $anc_add = "_" . rawurlencode($int_link["Anchor"]);
109 }
110
111 $href = "";
112 $lcontent = "";
113 switch ($type) {
114 case "PageObject":
115 case "StructureObject":
116 $lm_id = ilLMObject::_lookupContObjID($target_id);
117 if ($type === "PageObject") {
118 $href = (string) $this->static_url->builder()->build(
119 "pg",
120 null,
121 [$target_id]
122 ) . $anc_add;
123 } else {
124 $href = (string) $this->static_url->builder()->build(
125 "st",
126 null,
127 [$target_id]
128 ) . $anc_add;
129 }
130 if ($lm_id == "") {
131 $href = "";
132 }
133 break;
134
135 case "GlossaryItem":
136 if ($targetframe == "Glossary") {
137 $ltarget = "";
138 }
139 if ($this->offline) {
140 $href = "term_" . $target_id . ".html";
141 } else {
142 $href = "./goto.php?target=git_" . $target_id;
143 }
144 break;
145
146 case "MediaObject":
147 if ($this->offline) {
148 $href = "media_" . $target_id . ".html";
149 } else {
150 $this->ctrl->setParameterByClass($this->cmd_gui, "mob_id", $target_id);
151 $href = $this->ctrl->getLinkTargetByClass(
152 $this->cmd_gui,
153 "displayMedia",
154 "",
155 false,
156 true
157 );
158 $this->ctrl->setParameterByClass($this->cmd_gui, "mob_id", "");
159 }
160 break;
161
162 case "WikiPage":
163 $wiki_anc = "";
164 if (($int_link["Anchor"] ?? "") != "") {
165 $wiki_anc = "#" . rawurlencode("copganc_" . $int_link["Anchor"]);
166 }
167 $href = ilWikiPage::getGotoForWikiPageTarget($target_id) . $wiki_anc;
168 break;
169
170 case "PortfolioPage":
171 $href = ilPortfolioPage::getGotoForPortfolioPageTarget($target_id, $this->offline);
172 break;
173
174 case "RepositoryItem":
175 $obj_type = ilObject::_lookupType((int) $target_id, true);
176 if ((int) $target_id > 0) {
177 $href = (string) $this->static_url->builder()->build(
178 $obj_type,
179 new \ILIAS\Data\ReferenceId($target_id)
180 );
181 } else {
182 $href = "#";
183 }
184 break;
185
186 case "File":
187 if (!$this->offline) {
188 $href = "#";
189 }
190 break;
191
192 case "User":
193 // target = il__user_329
194 $obj_type = ilObject::_lookupType((int) $target_id);
195 if ($obj_type == "usr") {
197 //var_dump($back); exit;
198 $this->ctrl->setParameterByClass(PublicProfileGUI::class, "user_id", $target_id);
199 if (strlen($back)) {
200 $this->ctrl->setParameterByClass(
201 PublicProfileGUI::class,
202 "back_url",
203 rawurlencode($back)
204 );
205 }
206 $href = "";
207 if (ilUserUtil::hasPublicProfile($target_id)) {
208 $href = $this->ctrl->getLinkTargetByClass(
209 [ilPublicProfileBaseClassGUI::class, PublicProfileGUI::class],
210 "getHTML",
211 "",
212 false,
213 true
214 );
215 }
216 $this->ctrl->setParameterByClass(PublicProfileGUI::class, "user_id", "");
217 $lcontent = ilUserUtil::getNamePresentation($target_id, false, false);
218 $lcontent = str_replace("&", "&amp;", htmlentities($lcontent));
219 }
220 break;
221 }
222 if ($href != "" || $type === "User") {
223 $anc_par = 'Anchor="' . $anc . '"';
224 $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " . $anc_par . " " .
225 "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" LinkContent=\"$lcontent\" />";
226 }
227 }
228 }
229 $link_info .= "</IntLinkInfos>";
230 $link_info .= $this->getLinkTargetsXML();
231 return $link_info;
232 }
233
234 public function getFullscreenLink(): string
235 {
236 if ($this->offline) {
237 return "fullscreen.html";
238 }
239
240 return $this->ctrl->getLinkTargetByClass($this->cmd_gui, "fullscreen", "", false, false);
241 }
242}
GUI class for public user profile presentation.
Class ilCtrl provides processing control methods.
static _lookupContObjID(int $a_id)
get learning module id for lm object
static _lookupType(int $id, bool $reference=false)
getLinkXML(array $int_links)
setOffline(bool $offline=true)
setProfileBackUrl(string $url)
__construct(string $cmd_gui_class, bool $offline=false, string $profile_back_url="", ?ilCtrl $ctrl=null)
ILIAS StaticURL Services $static_url
static getGotoForPortfolioPageTarget(int $a_target, bool $a_offline=false)
Get goto href for portfolio page 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)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:70