ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCContentInclude.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30{
31 protected ilLanguage $lng;
33
37 public function init(): void
38 {
39 global $DIC;
40
41 $this->lng = $DIC->language();
42 $this->setType("incl");
43 $this->access = $DIC->access();
44 }
45
46
47 public function create(
48 ilPageObject $a_pg_obj,
49 string $a_hier_id,
50 string $a_pc_id = ""
51 ): void {
52 $this->createInitialChildNode($a_hier_id, $a_pc_id, "ContentInclude");
53 }
54
58 public function setContentId(int $a_id): void
59 {
60 $this->setContentIncludeAttribute("ContentId", (string) $a_id);
61 }
62
66 public function getContentId(): int
67 {
68 return (int) $this->getContentIncludeAttribute("ContentId");
69 }
70
74 public function setContentType(string $a_type): void
75 {
76 $this->setContentIncludeAttribute("ContentType", $a_type);
77 }
78
82 public function getContentType(): string
83 {
84 return $this->getContentIncludeAttribute("ContentType");
85 }
86
90 public function setInstId(string $a_id): void
91 {
92 $this->setContentIncludeAttribute("InstId", $a_id);
93 }
94
98 public function getInstId(): string
99 {
100 return $this->getContentIncludeAttribute("InstId");
101 }
102
106 protected function setContentIncludeAttribute(
107 string $a_attr,
108 string $a_value
109 ): void {
110 if (!empty($a_value)) {
111 $this->getChildNode()->setAttribute($a_attr, $a_value);
112 } else {
113 if ($this->getChildNode()->hasAttribute($a_attr)) {
114 $this->getChildNode()->removeAttribute($a_attr);
115 }
116 }
117 }
118
122 public function getContentIncludeAttribute(string $a_attr): string
123 {
124 if (is_object($this->getChildNode())) {
125 return $this->getChildNode()->getAttribute($a_attr);
126 }
127 return "";
128 }
129
133 public static function afterPageUpdate(
134 ilPageObject $a_page,
135 DOMDocument $a_domdoc,
136 string $a_xml,
137 bool $a_creation
138 ): void {
139 // pc content include
140 self::saveContentIncludeUsage($a_page, $a_domdoc);
141 }
142
146 public static function beforePageDelete(ilPageObject $a_page): void
147 {
148 ilPageContentUsage::deleteAllUsages("incl", $a_page->getParentType() . ":pg", $a_page->getId(), 0, $a_page->getLanguage());
149 }
150
154 public static function afterPageHistoryEntry(
155 ilPageObject $a_page,
156 DOMDocument $a_old_domdoc,
157 string $a_old_xml,
158 int $a_old_nr
159 ): void {
160 self::saveContentIncludeUsage($a_page, $a_old_domdoc, $a_old_nr);
161 }
162
166 public static function saveContentIncludeUsage(
167 ilPageObject $a_page,
168 DOMDocument $a_domdoc,
169 int $a_old_nr = 0
170 ): void {
171 $ci_ids = self::collectContentIncludes($a_page, $a_domdoc);
172 ilPageContentUsage::deleteAllUsages("incl", $a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage());
173 foreach ($ci_ids as $ci_id) {
174 if ((int) $ci_id["inst_id"] <= 0 || $ci_id["inst_id"] == IL_INST_ID) {
176 "incl",
177 (int) $ci_id["id"],
178 $a_page->getParentType() . ":pg",
179 $a_page->getId(),
180 $a_old_nr,
181 $a_page->getLanguage()
182 );
183 }
184 }
185 }
186
190 public static function collectContentIncludes(
191 ilPageObject $a_page,
192 DOMDocument $a_domdoc
193 ): array {
194 $xpath = new DOMXPath($a_domdoc);
195 $nodes = $xpath->query('//ContentInclude');
196
197 $ci_ids = array();
198 foreach ($nodes as $node) {
199 $type = $node->getAttribute("ContentType");
200 $id = $node->getAttribute("ContentId");
201 $inst_id = $node->getAttribute("InstId");
202 $ci_ids[$type . ":" . $id . ":" . $inst_id] = array(
203 "type" => $type, "id" => $id, "inst_id" => $inst_id);
204 }
205
206 return $ci_ids;
207 }
208
210 string $a_output,
211 string $a_mode,
212 bool $a_abstract_only = false
213 ): string {
214 $lng = $this->lng;
215
216 $end = 0;
217 $start = strpos($a_output, "{{{{{ContentInclude;");
218 if (is_int($start)) {
219 $end = strpos($a_output, "}}}}}", $start);
220 }
221 $i = 1;
222 $parent_lang = $this->getPage()->getLanguage();
223 if ($parent_lang == "-" && $this->getPage()->getConcreteLang() != "") {
224 $parent_lang = $this->getPage()->getConcreteLang();
225 }
226 while ($end > 0) {
227 $param = substr($a_output, $start + 20, $end - $start - 20);
228 $param = explode(";", $param);
229
230 if ($param[0] == "mep" && is_numeric($param[1])) {
231 $html = "";
232 $snippet_lang = $parent_lang;
233 if (!ilPageObject::_exists("mep", (int) $param[1], $snippet_lang)) {
234 $snippet_lang = "-";
235 }
236 if (($param[2] <= 0 || $param[2] == IL_INST_ID) && ilPageObject::_exists("mep", (int) $param[1])) {
237 $page_gui = new ilMediaPoolPageGUI((int) $param[1], 0, true, $snippet_lang);
238 if ($a_mode != "offline") {
239 $page_gui->setFileDownloadLink($this->getFileDownloadLink());
240 $page_gui->setProfileBackUrl($this->getProfileBackUrl());
241 $page_gui->setFullscreenLink($this->getFullscreenLink() . "&pg_type=mep");
242 $page_gui->setSourcecodeDownloadScript($this->getSourcecodeDownloadScript());
243 } else {
244 $page_gui->setOutputMode(ilPageObjectGUI::OFFLINE);
245 }
246
247 $html = $page_gui->getRawContent();
248 if ($a_mode == "edit") {
249 $par_id = $page_gui->getPageObject()->getParentId();
250 $info = "";
251 foreach (ilObject::_getAllReferences($par_id) as $ref_id) {
252 if ($this->access->checkAccess("write", "", $ref_id)) {
253 $info = " " . $lng->txt("title") . ": " . ilMediaPoolItem::lookupTitle($page_gui->getPageObject()->getId()) .
254 ", " . $lng->txt("obj_mep") . ": <a href='" . ilLink::_getLink($ref_id) . "'>" . ilObject::_lookupTitle($par_id) . "</a>";
255 }
256 }
257 $html = '<p class="small light">' . $lng->txt("copg_snippet_cannot_be_edited") . $info . '</p>' . $html;
258 }
259 } else {
260 if ($a_mode == "edit") {
261 if ($param[2] <= 0) {
262 $html = "// " . $lng->txt("cont_missing_snippet") . " //";
263 } else {
264 $html = "// " . $lng->txt("cont_snippet_from_another_installation") . " //";
265 }
266 }
267 }
268 $h2 = substr($a_output, 0, $start) .
269 $html .
270 substr($a_output, $end + 5);
271 $a_output = $h2;
272 $i++;
273 }
274
275 $start = strpos($a_output, "{{{{{ContentInclude;", $start + 5);
276 $end = 0;
277 if (is_int($start)) {
278 $end = strpos($a_output, "}}}}}", $start);
279 }
280 }
281 return $a_output;
282 }
283
284 public static function deleteHistoryLowerEqualThan(
285 string $parent_type,
286 int $page_id,
287 string $lang,
288 int $delete_lower_than_nr
289 ): void {
290 global $DIC;
291
292 $usage_repo = $DIC->copage()
293 ->internal()
294 ->repo()
295 ->usage();
296
297 $usage_repo->deleteHistoryUsagesLowerEqualThan(
298 "incl",
299 $parent_type . ":pg",
300 $page_id,
301 $delete_lower_than_nr,
302 $lang
303 );
304 }
305}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
language handling
static lookupTitle(int $a_id)
Class ilMediaPoolPage GUI class.
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
Class ilPCContentInclude.
getContentIncludeAttribute(string $a_attr)
Get content include tag attribute.
setContentId(int $a_id)
Set content id.
static deleteHistoryLowerEqualThan(string $parent_type, int $page_id, string $lang, int $delete_lower_than_nr)
Overwrite in derived classes, if old history entries are being deleted.
static collectContentIncludes(ilPageObject $a_page, DOMDocument $a_domdoc)
get all content includes that are used within the page
static saveContentIncludeUsage(ilPageObject $a_page, DOMDocument $a_domdoc, int $a_old_nr=0)
save content include usages
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
Modify page content after xsl.
setInstId(string $a_id)
Set installation id.
getInstId()
Get installation id.
static beforePageDelete(ilPageObject $a_page)
Before page is being deleted.
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
getContentType()
Get content type.
setContentIncludeAttribute(string $a_attr, string $a_value)
Set attribute of content include tag.
static afterPageHistoryEntry(ilPageObject $a_page, DOMDocument $a_old_domdoc, string $a_old_xml, int $a_old_nr)
After page history entry has been created.
init()
Init page content component.
static afterPageUpdate(ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
After page has been updated (or created)
setContentType(string $a_type)
Set content type.
static saveUsage(string $a_pc_type, int $a_pc_id, string $a_usage_type, int $a_usage_id, int $a_usage_hist_nr=0, string $a_lang="-")
static deleteAllUsages(string $a_pc_type, string $a_usage_type, int $a_usage_id, int $a_usage_hist_nr=0, string $a_lang="-")
Content object of ilPageObject (see ILIAS DTD).
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
const IL_INST_ID
Definition: constants.php:40
$info
Definition: entry_point.php:21
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$lang
Definition: xapiexit.php:25
$param
Definition: xapitoken.php:46