ILIAS  release_8 Revision v8.24
class.ilPCInteractiveImage.php
Go to the documentation of this file.
1<?php
2
25{
26 public const AREA = "Area";
27 public const MARKER = "Marker";
30
33 protected ilLanguage $lng;
35
36 public function init(): void
37 {
38 global $DIC;
39
40 $this->lng = $DIC->language();
41 $this->setType("iim");
42 }
43
44 public function readMediaObject(int $a_mob_id = 0): void
45 {
46 if ($a_mob_id > 0) {
47 $mob = new ilObjMediaObject($a_mob_id);
48 $this->setMediaObject($mob);
49 }
50 }
51
52 public function setNode(php4DOMElement $a_node): void
53 {
54 parent::setNode($a_node); // this is the PageContent node
55 $this->iim_node = $a_node->first_child();
56 if (isset($this->iim_node->myDOMNode)) {
57 $this->med_alias_node = $this->iim_node->first_child();
58 }
59 if (isset($this->med_alias_node) && $this->med_alias_node->myDOMNode != null) {
60 $id = $this->med_alias_node->get_attribute("OriginId");
62 if (ilObject::_lookupType($mob_id) == "mob") {
63 $this->setMediaObject(new ilObjMediaObject($mob_id));
64 }
65 }
66 $this->std_alias_item = new ilMediaAliasItem(
67 $this->dom,
68 $this->readHierId(),
69 "Standard",
70 $this->readPCId(),
71 "InteractiveImage"
72 );
73 }
74
75 public function setDom(php4DOMDocument $a_dom): void
76 {
77 $this->dom = $a_dom;
78 }
79
80 public function setMediaObject(ilObjMediaObject $a_mediaobject): void
81 {
82 $this->mediaobject = $a_mediaobject;
83 }
84
86 {
87 return $this->mediaobject;
88 }
89
90 public function createMediaObject(): void
91 {
92 $this->setMediaObject(new ilObjMediaObject());
93 }
94
95 public function create(): void
96 {
97 $this->node = $this->createPageContentNode();
98 }
99
101 {
102 return $this->getMediaObject()->getMediaItem("Standard");
103 }
104
106 {
108 }
109
110 public function getBaseThumbnailTarget(): string
111 {
112 return $this->getMediaObject()->getMediaItem("Standard")->getThumbnailTarget();
113 }
114
115
116 public function createAlias(
117 ilPageObject $a_pg_obj,
118 string $a_hier_id,
119 string $a_pc_id = ""
120 ): void {
121 $this->node = $this->dom->create_element("PageContent");
122 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
123 $this->iim_node = $this->dom->create_element("InteractiveImage");
124 $this->iim_node = $this->node->append_child($this->iim_node);
125 $this->mal_node = $this->dom->create_element("MediaAlias");
126 $this->mal_node = $this->iim_node->append_child($this->mal_node);
127 $this->mal_node->set_attribute("OriginId", "il__mob_" . $this->getMediaObject()->getId());
128
129 // standard view
130 $item_node = $this->dom->create_element("MediaAliasItem");
131 $item_node = $this->iim_node->append_child($item_node);
132 $item_node->set_attribute("Purpose", "Standard");
133 $media_item = $this->getMediaObject()->getMediaItem("Standard");
134
135 $layout_node = $this->dom->create_element("Layout");
136 $layout_node = $item_node->append_child($layout_node);
137 if ($media_item->getWidth() > 0) {
138 //$layout_node->set_attribute("Width", $media_item->getWidth());
139 }
140 if ($media_item->getHeight() > 0) {
141 //$layout_node->set_attribute("Height", $media_item->getHeight());
142 }
143 $layout_node->set_attribute("HorizontalAlign", "Left");
144
145 // caption
146 if ($media_item->getCaption() != "") {
147 $cap_node = $this->dom->create_element("Caption");
148 $cap_node = $item_node->append_child($cap_node);
149 $cap_node->set_attribute("Align", "bottom");
150 $cap_node->set_content($media_item->getCaption());
151 }
152
153 // text representation
154 if ($media_item->getTextRepresentation() != "") {
155 $tr_node = $this->dom->create_element("TextRepresentation");
156 $tr_node = $item_node->append_child($tr_node);
157 $tr_node->set_content($media_item->getTextRepresentation());
158 }
159 }
160
161 public function dumpXML(): string
162 {
163 $xml = $this->dom->dump_node($this->node);
164 return $xml;
165 }
166
167
171
172
176 public function addContentPopup(): void
177 {
179
180 $max = 0;
181 $popups = $this->getPopups();
182 foreach ($popups as $p) {
183 $max = max($max, (int) $p["nr"]);
184 }
185
186 $new_item = $this->dom->create_element("ContentPopup");
187 $new_item->set_attribute("Title", $lng->txt("cont_new_popup"));
188 $new_item->set_attribute("Nr", $max + 1);
189 $new_item = $this->iim_node->append_child($new_item);
190 }
191
195 public function getPopups(): array
196 {
197 $titles = array();
198 $childs = $this->iim_node->child_nodes();
199 $k = 0;
200 for ($i = 0; $i < count($childs); $i++) {
201 if ($childs[$i]->node_name() == "ContentPopup") {
202 $pc_id = $childs[$i]->get_attribute("PCID");
203 $hier_id = $childs[$i]->get_attribute("HierId");
204 $title = $childs[$i]->get_attribute("Title");
205 $nr = $childs[$i]->get_attribute("Nr");
206
207 $titles[] = array("title" => $title, "nr" => $nr,
208 "pc_id" => $pc_id, "hier_id" => $hier_id);
209 $k++;
210 }
211 }
212 return $titles;
213 }
214
218 public function savePopups(array $a_popups): void
219 {
220 $childs = $this->iim_node->child_nodes();
221 for ($i = 0; $i < count($childs); $i++) {
222 if ($childs[$i]->node_name() == "ContentPopup") {
223 $pc_id = $childs[$i]->get_attribute("PCID");
224 $hier_id = $childs[$i]->get_attribute("HierId");
225 $k = $hier_id . ":" . $pc_id;
226 $childs[$i]->set_attribute("Title", $a_popups[$k]);
227 }
228 }
229 }
230
234 public function deletePopup(
235 string $a_hier_id,
236 string $a_pc_id
237 ): void {
238 // File Item
239 $childs = $this->iim_node->child_nodes();
240 $nodes = array();
241 for ($i = 0; $i < count($childs); $i++) {
242 if ($childs[$i]->node_name() == "ContentPopup") {
243 if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
244 $a_hier_id == $childs[$i]->get_attribute("HierId")) {
245 $childs[$i]->unlink($childs[$i]);
246 }
247 }
248 }
249 }
250
254
258 public function addTriggerArea(
259 ilMediaAliasItem $a_alias_item,
260 string $a_shape_type,
261 string $a_coords,
262 string $a_title
263 ): void {
264 $max = 0;
265 $triggers = $this->getTriggers();
266 foreach ($triggers as $t) {
267 $max = max($max, (int) $t["Nr"]);
268 }
269
270 $link = array(
271 "LinkType" => IL_EXT_LINK,
272 "Href" => ilUtil::stripSlashes("#"));
273
274 $a_alias_item->addMapArea(
275 $a_shape_type,
276 $a_coords,
277 ilUtil::stripSlashes($a_title),
278 $link,
279 $max + 1
280 );
281
282 $attributes = array("Type" => self::AREA,
283 "Title" => ilUtil::stripSlashes($a_title),
284 "Nr" => $max + 1,
285 "OverlayX" => "0", "OverlayY" => "0", "Overlay" => "", "PopupNr" => "",
286 "PopupX" => "0", "PopupY" => "0", "PopupWidth" => "150", "PopupHeight" => "200");
288 $this->dom,
289 $this->iim_node,
290 "Trigger",
291 array("ContentPopup"),
292 "",
294 );
295 }
296
300 public function addTriggerMarker(): void
301 {
303
304 $max = 0;
305 $triggers = $this->getTriggers();
306 foreach ($triggers as $t) {
307 $max = max($max, (int) $t["Nr"]);
308 }
309
310 $attributes = array("Type" => self::MARKER,
311 "Title" => $lng->txt("cont_new_marker"),
312 "Nr" => $max + 1, "OverlayX" => "0", "OverlayY" => "0",
313 "MarkerX" => "0", "MarkerY" => "0", "PopupNr" => "",
314 "PopupX" => "0", "PopupY" => "0", "PopupWidth" => "150", "PopupHeight" => "200");
316 $this->dom,
317 $this->iim_node,
318 "Trigger",
319 array("ContentPopup"),
320 "",
322 );
323 }
324
325 public function getTriggerNodes(
326 string $a_hier_id,
327 string $a_pc_id = ""
328 ): array {
329 $xpc = xpath_new_context($this->dom);
330 if ($a_pc_id != "") {
331 $path = "//PageContent[@PCID = '" . $a_pc_id . "']/InteractiveImage/Trigger";
332 $res = xpath_eval($xpc, $path);
333 if (count($res->nodeset) > 0) {
334 return $res->nodeset;
335 }
336 return [];
337 }
338
339 $path = "//PageContent[@HierId = '" . $a_hier_id . "']/InteractiveImage/Trigger";
340 $res = xpath_eval($xpc, $path);
341 if (count($res->nodeset) > 0) {
342 return $res->nodeset;
343 }
344 return [];
345 }
346
347 public function getTriggers(): array
348 {
349 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPCId());
350 $trigger_arr = array();
351 for ($i = 0; $i < count($tr_nodes); $i++) {
352 $tr_node = $tr_nodes[$i];
353 $childs = $tr_node->child_nodes();
354 $trigger_arr[] = array(
355 "Nr" => $tr_node->get_attribute("Nr"),
356 "Type" => $tr_node->get_attribute("Type"),
357 "Title" => $tr_node->get_attribute("Title"),
358 "OverlayX" => $tr_node->get_attribute("OverlayX"),
359 "OverlayY" => $tr_node->get_attribute("OverlayY"),
360 "MarkerX" => $tr_node->get_attribute("MarkerX"),
361 "MarkerY" => $tr_node->get_attribute("MarkerY"),
362 "Overlay" => $tr_node->get_attribute("Overlay"),
363 "PopupNr" => $tr_node->get_attribute("PopupNr"),
364 "PopupX" => $tr_node->get_attribute("PopupX"),
365 "PopupY" => $tr_node->get_attribute("PopupY"),
366 "PopupWidth" => $tr_node->get_attribute("PopupWidth"),
367 "PopupHeight" => $tr_node->get_attribute("PopupHeight")
368 );
369 }
370
371 return $trigger_arr;
372 }
373
377 public function deleteTrigger(
378 ilMediaAliasItem $a_alias_item,
379 int $a_nr
380 ): void {
381 // File Item
382 $childs = $this->iim_node->child_nodes();
383 $nodes = array();
384 for ($i = 0; $i < count($childs); $i++) {
385 if ($childs[$i]->node_name() == "Trigger") {
386 if ($a_nr == $childs[$i]->get_attribute("Nr")) {
387 $childs[$i]->unlink($childs[$i]);
388 }
389 }
390 }
391 $a_alias_item->deleteMapAreaById($a_nr);
392 }
393
394
399 public function setTriggerOverlays(
400 array $a_ovs
401 ): void {
402 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPCId());
403 for ($i = 0; $i < count($tr_nodes); $i++) {
404 $tr_node = $tr_nodes[$i];
405 if (isset($a_ovs["" . $tr_node->get_attribute("Nr")])) {
406 $tr_node->set_attribute(
407 "Overlay",
408 $a_ovs["" . $tr_node->get_attribute("Nr")]
409 );
410 }
411 }
412 }
413
419 array $a_pos
420 ): void {
421 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPCId());
422 for ($i = 0; $i < count($tr_nodes); $i++) {
423 $tr_node = $tr_nodes[$i];
424 if (isset($a_pos["" . $tr_node->get_attribute("Nr")])) {
425 $pos = explode(",", $a_pos["" . $tr_node->get_attribute("Nr")]);
426 $tr_node->set_attribute("OverlayX", (int) $pos[0]);
427 $tr_node->set_attribute("OverlayY", (int) $pos[1]);
428 }
429 }
430 }
431
437 array $a_pos
438 ): void {
439 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPCId());
440 for ($i = 0; $i < count($tr_nodes); $i++) {
441 $tr_node = $tr_nodes[$i];
442 if ($tr_node->get_attribute("Type") == self::MARKER) {
443 if (isset($a_pos["" . $tr_node->get_attribute("Nr")])) {
444 $pos = explode(",", $a_pos["" . $tr_node->get_attribute("Nr")]);
445 $tr_node->set_attribute("MarkerX", (int) $pos[0]);
446 $tr_node->set_attribute("MarkerY", (int) $pos[1]);
447 }
448 }
449 }
450 }
451
457 array $a_pos
458 ): void {
459 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPCId());
460 for ($i = 0; $i < count($tr_nodes); $i++) {
461 $tr_node = $tr_nodes[$i];
462 if (isset($a_pos["" . $tr_node->get_attribute("Nr")])) {
463 $pos = explode(",", $a_pos["" . $tr_node->get_attribute("Nr")]);
464 $tr_node->set_attribute("PopupX", (int) $pos[0]);
465 $tr_node->set_attribute("PopupY", (int) $pos[1]);
466 }
467 }
468 }
469
474 public function setTriggerPopupSize(
475 array $a_size
476 ): void {
477 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPCId());
478 for ($i = 0; $i < count($tr_nodes); $i++) {
479 $tr_node = $tr_nodes[$i];
480 if (isset($a_size["" . $tr_node->get_attribute("Nr")])) {
481 $size = explode(",", $a_size["" . $tr_node->get_attribute("Nr")]);
482 $tr_node->set_attribute("PopupWidth", (int) $size[0]);
483 $tr_node->set_attribute("PopupHeight", (int) $size[1]);
484 }
485 }
486 }
487
492 public function setTriggerPopups(
493 array $a_pops
494 ): void {
495 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPCId());
496 for ($i = 0; $i < count($tr_nodes); $i++) {
497 $tr_node = $tr_nodes[$i];
498 if (isset($a_pops[(string) $tr_node->get_attribute("Nr")])) {
499 $pop = $a_pops[(string) $tr_node->get_attribute("Nr")];
500 $tr_node->set_attribute("PopupNr", $pop);
501 }
502 }
503 }
504
509 public function setTriggerTitles(
510 array $a_titles
511 ): void {
512 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPCId());
513 for ($i = 0; $i < count($tr_nodes); $i++) {
514 $tr_node = $tr_nodes[$i];
515 if (isset($a_titles[(string) $tr_node->get_attribute("Nr")])) {
516 $tr_node->set_attribute(
517 "Title",
518 $a_titles[(string) $tr_node->get_attribute("Nr")]
519 );
520 $this->setExtLinkTitle(
521 $tr_node->get_attribute("Nr"),
522 $a_titles[(string) $tr_node->get_attribute("Nr")]
523 );
524 }
525 }
526 }
527
528 public function setExtLinkTitle(
529 int $a_nr,
530 string $a_title
531 ): void {
532 if ($this->getPCId() != "") {
533 $xpc = xpath_new_context($this->dom);
534 $path = "//PageContent[@PCID = '" . $this->getPCId() . "']/InteractiveImage/MediaAliasItem/MapArea[@Id='" . $a_nr . "']/ExtLink";
535 $res = xpath_eval($xpc, $path);
536 if (count($res->nodeset) > 0) {
537 $res->nodeset[0]->set_content($a_title);
538 }
539 return;
540 }
541
542 $xpc = xpath_new_context($this->dom);
543 $path = "//PageContent[@HierId = '" . $this->hier_id . "']/InteractiveImage/MediaAliasItem/MapArea[@Id='" . $a_nr . "']/ExtLink";
544 $res = xpath_eval($xpc, $path);
545 if (count($res->nodeset) > 0) {
546 $res->nodeset[0]->set_content($a_title);
547 }
548 }
549}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_EXT_LINK
const IL_INSERT_AFTER
static addElementToList(php4DOMDocument $doc, php4DOMElement $parent_node, string $a_node_name, array $a_successors, string $a_content, array $a_attributes)
Places a new node $a_node_name directly before nodes with names of $a_successors.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addMapArea(string $a_shape_type, string $a_coords, string $a_title, array $a_link, string $a_id="")
Add a new area to the map.
deleteMapAreaById(string $a_id)
Delete map areas by id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTriggerOverlayPositions(array $a_pos)
Set trigger overlay position.
deleteTrigger(ilMediaAliasItem $a_alias_item, int $a_nr)
Delete Trigger.
addTriggerArea(ilMediaAliasItem $a_alias_item, string $a_shape_type, string $a_coords, string $a_title)
Add a new trigger.
setDom(php4DOMDocument $a_dom)
setTriggerOverlays(array $a_ovs)
Set trigger overlays.
setTriggerPopups(array $a_pops)
Set trigger popups.
setExtLinkTitle(int $a_nr, string $a_title)
setTriggerMarkerPositions(array $a_pos)
Set trigger marker position.
deletePopup(string $a_hier_id, string $a_pc_id)
Delete popup.
getTriggerNodes(string $a_hier_id, string $a_pc_id="")
createAlias(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
setTriggerPopupPositions(array $a_pos)
Set trigger popup position.
setTriggerPopupSize(array $a_size)
Set trigger popup size.
addTriggerMarker()
Add a new trigger marker.
setTriggerTitles(array $a_titles)
Set trigger titles.
setMediaObject(ilObjMediaObject $a_mediaobject)
savePopups(array $a_popups)
Save popups.
setNode(php4DOMElement $a_node)
Set xml node of page content.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
insertContent(ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true)
insert a content node before/after a sibling or as first child of a parent
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
xpath_new_context($dom_document)
xpath_eval(php4DOMXPath $xpath_context, string $eval_str, $contextnode=null)
$path
Definition: ltiservices.php:32
$res
Definition: ltiservices.php:69
$i
Definition: metadata.php:41
$attributes
Definition: metadata.php:248
$xml
Definition: metadata.php:351
$lng