ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPCInteractiveImage.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once("./Services/COPage/classes/class.ilPageContent.php");
6
16{
20 protected $lng;
21
22
23 public $dom;
24 public $iim_node;
25
26 const AREA = "Area";
27 const MARKER = "Marker";
28
32 public function init()
33 {
34 global $DIC;
35
36 $this->lng = $DIC->language();
37 $this->setType("iim");
38 }
39
45 public function readMediaObject($a_mob_id = 0)
46 {
47 if ($a_mob_id > 0) {
48 $mob = new ilObjMediaObject($a_mob_id);
49 $this->setMediaObject($mob);
50 }
51 }
52
56 public function setNode($a_node)
57 {
58 parent::setNode($a_node); // this is the PageContent node
59 $this->iim_node = $a_node->first_child();
60 $this->med_alias_node = $this->iim_node->first_child();
61 if (is_object($this->med_alias_node) && $this->med_alias_node->myDOMNode != null) {
62 $id = $this->med_alias_node->get_attribute("OriginId");
64 if (ilObject::_lookupType($mob_id) == "mob") {
65 $this->setMediaObject(new ilObjMediaObject($mob_id));
66 }
67 }
68 include_once("./Services/COPage/classes/class.ilMediaAliasItem.php");
69 $this->std_alias_item = new ilMediaAliasItem(
70 $this->dom,
71 $this->readHierId(),
72 "Standard",
73 $this->readPCId(),
74 "InteractiveImage"
75 );
76 }
77
81 public function setDom(&$a_dom)
82 {
83 $this->dom = $a_dom;
84 }
85
91 public function setMediaObject($a_mediaobject)
92 {
93 $this->mediaobject = $a_mediaobject;
94 }
95
101 public function getMediaObject()
102 {
103 return $this->mediaobject;
104 }
105
109 public function createMediaObject()
110 {
111 $this->setMediaObject(new ilObjMediaObject());
112 }
113
117 public function create($a_pg_obj, $a_hier_id)
118 {
119 $this->node = $this->createPageContentNode();
120 }
121
127 public function getStandardMediaItem()
128 {
129 return $this->getMediaObject()->getMediaItem("Standard");
130 }
131
135 public function getStandardAliasItem()
136 {
137 return $this->std_alias_item;
138 }
139
140
146 public function getBaseThumbnailTarget()
147 {
148 return $this->getMediaObject()->getMediaItem("Standard")->getThumbnailTarget();
149 }
150
151
158 public function createAlias(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
159 {
160 $this->node = $this->dom->create_element("PageContent");
161 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
162 $this->iim_node = $this->dom->create_element("InteractiveImage");
163 $this->iim_node = $this->node->append_child($this->iim_node);
164 $this->mal_node = $this->dom->create_element("MediaAlias");
165 $this->mal_node = $this->iim_node->append_child($this->mal_node);
166 $this->mal_node->set_attribute("OriginId", "il__mob_" . $this->getMediaObject()->getId());
167
168 // standard view
169 $item_node = $this->dom->create_element("MediaAliasItem");
170 $item_node = $this->iim_node->append_child($item_node);
171 $item_node->set_attribute("Purpose", "Standard");
172 $media_item = $this->getMediaObject()->getMediaItem("Standard");
173
174 $layout_node = $this->dom->create_element("Layout");
175 $layout_node = $item_node->append_child($layout_node);
176 if ($media_item->getWidth() > 0) {
177 //$layout_node->set_attribute("Width", $media_item->getWidth());
178 }
179 if ($media_item->getHeight() > 0) {
180 //$layout_node->set_attribute("Height", $media_item->getHeight());
181 }
182 $layout_node->set_attribute("HorizontalAlign", "Left");
183
184 // caption
185 if ($media_item->getCaption() != "") {
186 $cap_node = $this->dom->create_element("Caption");
187 $cap_node = $item_node->append_child($cap_node);
188 $cap_node->set_attribute("Align", "bottom");
189 $cap_node->set_content($media_item->getCaption());
190 }
191
192 // text representation
193 if ($media_item->getTextRepresentation() != "") {
194 $tr_node = $this->dom->create_element("TextRepresentation");
195 $tr_node = $item_node->append_child($tr_node);
196 $tr_node->set_content($media_item->getTextRepresentation());
197 }
198 }
199
203 public function dumpXML()
204 {
205 $xml = $this->dom->dump_node($this->node);
206 return $xml;
207 }
208
214 public function setStyleClass($a_class)
215 {
216 // check this
217 die("pcinteractiveimage: setstyleclass");
218 if (is_object($this->iim_node)) {
219 $mal_node = $this->iim_node->first_child();
220 if (is_object($mal_node)) {
221 if (!empty($a_class)) {
222 $mal_node->set_attribute("Class", $a_class);
223 } else {
224 if ($mal_node->has_attribute("Class")) {
225 $mal_node->remove_attribute("Class");
226 }
227 }
228 }
229 }
230 }
231
237 public function getStyleClass()
238 {
239 if (is_object($this->iim_node)) {
240 $mal_node = $this->iim_node->first_child();
241 if (is_object($mal_node)) {
242 $class = $mal_node->get_attribute("Class");
243 return $class;
244 }
245 }
246 }
247
248
252
253
257 public function addContentPopup()
258 {
260
261 $max = 0;
262 $popups = $this->getPopups();
263 foreach ($popups as $p) {
264 $max = max($max, (int) $p["nr"]);
265 }
266
267 $new_item = $this->dom->create_element("ContentPopup");
268 $new_item->set_attribute("Title", $lng->txt("cont_new_popup"));
269 $new_item->set_attribute("Nr", $max + 1);
270 $new_item = $this->iim_node->append_child($new_item);
271 }
272
276 public function getPopups()
277 {
278 $titles = array();
279 $childs = $this->iim_node->child_nodes();
280 $k = 0;
281 for ($i = 0; $i < count($childs); $i++) {
282 if ($childs[$i]->node_name() == "ContentPopup") {
283 $pc_id = $childs[$i]->get_attribute("PCID");
284 $hier_id = $childs[$i]->get_attribute("HierId");
285 $title = $childs[$i]->get_attribute("Title");
286 $nr = $childs[$i]->get_attribute("Nr");
287
288 $titles[] = array("title" => $title, "nr" => $nr,
289 "pc_id" => $pc_id, "hier_id" => $hier_id);
290 $k++;
291 }
292 }
293 return $titles;
294 }
295
299 public function savePopups($a_popups)
300 {
301 $childs = $this->iim_node->child_nodes();
302 for ($i = 0; $i < count($childs); $i++) {
303 if ($childs[$i]->node_name() == "ContentPopup") {
304 $pc_id = $childs[$i]->get_attribute("PCID");
305 $hier_id = $childs[$i]->get_attribute("HierId");
306 $k = $hier_id . ":" . $pc_id;
307 $childs[$i]->set_attribute("Title", $a_popups[$k]);
308 }
309 }
310 }
311
315 public function deletePopup($a_hier_id, $a_pc_id)
316 {
317 // File Item
318 $childs = $this->iim_node->child_nodes();
319 $nodes = array();
320 for ($i = 0; $i < count($childs); $i++) {
321 if ($childs[$i]->node_name() == "ContentPopup") {
322 if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
323 $a_hier_id == $childs[$i]->get_attribute("HierId")) {
324 $childs[$i]->unlink($childs[$i]);
325 }
326 }
327 }
328 }
329
333 /*
334 function getCaption($a_hier_id, $a_pc_id)
335 {
336 $captions = array();
337 $tab_nodes = $this->tabs_node->child_nodes();
338 $k = 0;
339 for($i = 0; $i < count($tab_nodes); $i++)
340 {
341 if ($tab_nodes[$i]->node_name() == "Tab")
342 {
343 if ($a_pc_id == $tab_nodes[$i]->get_attribute("PCID") &&
344 ($a_hier_id == $tab_nodes[$i]->get_attribute("HierId")))
345 {
346 $tab_node_childs = $tab_nodes[$i]->child_nodes();
347 for($j = 0; $j < count($tab_node_childs); $j++)
348 {
349 if ($tab_node_childs[$j]->node_name() == "TabCaption")
350 {
351 return $tab_node_childs[$j]->get_content();
352 }
353 }
354 }
355 }
356 }
357
358 return "";
359 }
360 */
361
365 /*
366 function savePositions($a_pos)
367 {
368 asort($a_pos);
369
370 // File Item
371 $childs = $this->tabs_node->child_nodes();
372 $nodes = array();
373 for ($i=0; $i<count($childs); $i++)
374 {
375 if ($childs[$i]->node_name() == "Tab")
376 {
377 $pc_id = $childs[$i]->get_attribute("PCID");
378 $hier_id = $childs[$i]->get_attribute("HierId");
379 $nodes[$hier_id.":".$pc_id] = $childs[$i];
380 $childs[$i]->unlink($childs[$i]);
381 }
382 }
383
384 foreach($a_pos as $k => $v)
385 {
386 if (is_object($nodes[$k]))
387 {
388 $nodes[$k] = $this->tabs_node->append_child($nodes[$k]);
389 }
390 }
391 }
392 */
393
397 /*
398 function deleteTab($a_hier_id, $a_pc_id)
399 {
400 // File Item
401 $childs = $this->tabs_node->child_nodes();
402 $nodes = array();
403 for ($i=0; $i<count($childs); $i++)
404 {
405 if ($childs[$i]->node_name() == "Tab")
406 {
407 if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
408 $a_hier_id == $childs[$i]->get_attribute("HierId"))
409 {
410 $childs[$i]->unlink($childs[$i]);
411 }
412 }
413 }
414 }
415 */
416
420
424 public function addTriggerArea(
425 $a_alias_item,
426 $a_shape_type,
427 $a_coords,
428 $a_title,
429 $a_link
430 ) {
431 $max = 0;
432 $triggers = $this->getTriggers();
433 foreach ($triggers as $t) {
434 $max = max($max, (int) $t["Nr"]);
435 }
436
437 $link = array(
438 "LinkType" => IL_EXT_LINK,
439 "Href" => ilUtil::stripSlashes("#"));
440
441 $a_alias_item->addMapArea(
442 $a_shape_type,
443 $a_coords,
444 ilUtil::stripSlashes($a_title),
445 $link,
446 $max + 1
447 );
448
449 $attributes = array("Type" => self::AREA,
450 "Title" => ilUtil::stripSlashes($a_title),
451 "Nr" => $max + 1,
452 "OverlayX" => "0", "OverlayY" => "0", "Overlay" => "", "PopupNr" => "",
453 "PopupX" => "0", "PopupY" => "0", "PopupWidth" => "150", "PopupHeight" => "200");
455 $this->dom,
456 $this->iim_node,
457 "Trigger",
458 array("ContentPopup"),
459 "",
461 );
462 }
463
467 public function addTriggerMarker()
468 {
470
471 $max = 0;
472 $triggers = $this->getTriggers();
473 foreach ($triggers as $t) {
474 $max = max($max, (int) $t["Nr"]);
475 }
476
477 $attributes = array("Type" => self::MARKER,
478 "Title" => $lng->txt("cont_new_marker"),
479 "Nr" => $max + 1, "OverlayX" => "0", "OverlayY" => "0",
480 "MarkerX" => "0", "MarkerY" => "0", "PopupNr" => "",
481 "PopupX" => "0", "PopupY" => "0", "PopupWidth" => "150", "PopupHeight" => "200");
483 $this->dom,
484 $this->iim_node,
485 "Trigger",
486 array("ContentPopup"),
487 "",
489 );
490 }
491
495 public function getTriggerNodes($a_hier_id, $a_pc_id = "")
496 {
497 if ($a_pc_id != "") {
498 $xpc = xpath_new_context($this->dom);
499 $path = "//PageContent[@PCID = '" . $a_pc_id . "']/InteractiveImage/Trigger";
500 $res = xpath_eval($xpc, $path);
501 if (count($res->nodeset) > 0) {
502 return $res->nodeset;
503 }
504 return array();
505 }
506
507 $xpc = xpath_new_context($this->dom);
508 $path = "//PageContent[@HierId = '" . $a_hier_id . "']/InteractiveImage/Trigger";
509 $res = xpath_eval($xpc, $path);
510 if (count($res->nodeset) > 0) {
511 return $res->nodeset;
512 }
513 }
514
515
519 public function getTriggers()
520 {
521 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
522 $trigger_arr = array();
523 for ($i = 0; $i < count($tr_nodes); $i++) {
524 $tr_node = $tr_nodes[$i];
525 $childs = $tr_node->child_nodes();
526 $trigger_arr[] = array(
527 "Nr" => $tr_node->get_attribute("Nr"),
528 "Type" => $tr_node->get_attribute("Type"),
529 "Title" => $tr_node->get_attribute("Title"),
530 "OverlayX" => $tr_node->get_attribute("OverlayX"),
531 "OverlayY" => $tr_node->get_attribute("OverlayY"),
532 "MarkerX" => $tr_node->get_attribute("MarkerX"),
533 "MarkerY" => $tr_node->get_attribute("MarkerY"),
534 "Overlay" => $tr_node->get_attribute("Overlay"),
535 "PopupNr" => $tr_node->get_attribute("PopupNr"),
536 "PopupX" => $tr_node->get_attribute("PopupX"),
537 "PopupY" => $tr_node->get_attribute("PopupY"),
538 "PopupWidth" => $tr_node->get_attribute("PopupWidth"),
539 "PopupHeight" => $tr_node->get_attribute("PopupHeight")
540 );
541 }
542
543 return $trigger_arr;
544 }
545
549 public function deleteTrigger($a_alias_item, $a_nr)
550 {
551 // File Item
552 $childs = $this->iim_node->child_nodes();
553 $nodes = array();
554 for ($i = 0; $i < count($childs); $i++) {
555 if ($childs[$i]->node_name() == "Trigger") {
556 if ($a_nr == $childs[$i]->get_attribute("Nr")) {
557 $childs[$i]->unlink($childs[$i]);
558 }
559 }
560 }
561 $a_alias_item->deleteMapAreaById($a_nr);
562 }
563
564
570 public function setTriggerOverlays($a_ovs)
571 {
572 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
573 for ($i = 0; $i < count($tr_nodes); $i++) {
574 $tr_node = $tr_nodes[$i];
575 if (isset($a_ovs["" . $tr_node->get_attribute("Nr")])) {
576 $tr_node->set_attribute(
577 "Overlay",
578 $a_ovs["" . $tr_node->get_attribute("Nr")]
579 );
580 }
581 }
582 }
583
589 public function setTriggerOverlayPositions($a_pos)
590 {
591 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
592 for ($i = 0; $i < count($tr_nodes); $i++) {
593 $tr_node = $tr_nodes[$i];
594 if (isset($a_pos["" . $tr_node->get_attribute("Nr")])) {
595 $pos = explode(",", $a_pos["" . $tr_node->get_attribute("Nr")]);
596 $tr_node->set_attribute("OverlayX", (int) $pos[0]);
597 $tr_node->set_attribute("OverlayY", (int) $pos[1]);
598 }
599 }
600 }
601
607 public function setTriggerMarkerPositions($a_pos)
608 {
609 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
610 for ($i = 0; $i < count($tr_nodes); $i++) {
611 $tr_node = $tr_nodes[$i];
612 if ($tr_node->get_attribute("Type") == self::MARKER) {
613 if (isset($a_pos["" . $tr_node->get_attribute("Nr")])) {
614 $pos = explode(",", $a_pos["" . $tr_node->get_attribute("Nr")]);
615 $tr_node->set_attribute("MarkerX", (int) $pos[0]);
616 $tr_node->set_attribute("MarkerY", (int) $pos[1]);
617 }
618 }
619 }
620 }
621
627 public function setTriggerPopupPositions($a_pos)
628 {
629 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
630 for ($i = 0; $i < count($tr_nodes); $i++) {
631 $tr_node = $tr_nodes[$i];
632 if (isset($a_pos["" . $tr_node->get_attribute("Nr")])) {
633 $pos = explode(",", $a_pos["" . $tr_node->get_attribute("Nr")]);
634 $tr_node->set_attribute("PopupX", (int) $pos[0]);
635 $tr_node->set_attribute("PopupY", (int) $pos[1]);
636 }
637 }
638 }
639
645 public function setTriggerPopupSize($a_size)
646 {
647 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
648 for ($i = 0; $i < count($tr_nodes); $i++) {
649 $tr_node = $tr_nodes[$i];
650 if (isset($a_size["" . $tr_node->get_attribute("Nr")])) {
651 $size = explode(",", $a_size["" . $tr_node->get_attribute("Nr")]);
652 $tr_node->set_attribute("PopupWidth", (int) $size[0]);
653 $tr_node->set_attribute("PopupHeight", (int) $size[1]);
654 }
655 }
656 }
657
663 public function setTriggerPopups($a_pops)
664 {
665 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
666 for ($i = 0; $i < count($tr_nodes); $i++) {
667 $tr_node = $tr_nodes[$i];
668 if (isset($a_pops["" . $tr_node->get_attribute("Nr")])) {
669 $pop = $a_pops["" . $tr_node->get_attribute("Nr")];
670 $tr_node->set_attribute("PopupNr", $pop);
671 }
672 }
673 }
674
680 public function setTriggerTitles($a_titles)
681 {
682 $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
683 for ($i = 0; $i < count($tr_nodes); $i++) {
684 $tr_node = $tr_nodes[$i];
685 if (isset($a_titles["" . $tr_node->get_attribute("Nr")])) {
686 $tr_node->set_attribute(
687 "Title",
688 $a_titles["" . $tr_node->get_attribute("Nr")]
689 );
690 $this->setExtLinkTitle(
691 $tr_node->get_attribute("Nr"),
692 $a_titles["" . $tr_node->get_attribute("Nr")]
693 );
694 }
695 }
696 }
697
704 public function setExtLinkTitle($a_nr, $a_title)
705 {
706 if ($this->getPcId() != "") {
707 $xpc = xpath_new_context($this->dom);
708 $path = "//PageContent[@PCID = '" . $this->getPcId() . "']/InteractiveImage/MediaAliasItem/MapArea[@Id='" . $a_nr . "']/ExtLink";
709 $res = xpath_eval($xpc, $path);
710 if (count($res->nodeset) > 0) {
711 $res->nodeset[0]->set_content($a_title);
712 }
713 return;
714 }
715
716 $xpc = xpath_new_context($this->dom);
717 $path = "//PageContent[@HierId = '" . $this->hier_id . "']/InteractiveImage/MediaAliasItem/MapArea[@Id='" . $a_nr . "']/ExtLink";
718 $res = xpath_eval($xpc, $path);
719 if (count($res->nodeset) > 0) {
720 $res->nodeset[0]->set_content($a_title);
721 }
722 }
723}
$size
Definition: RandomTest.php:84
An exception for terminatinating execution or to throw for unit testing.
const IL_EXT_LINK
const IL_INSERT_AFTER
static addElementToList( $doc, $parent_node, $a_node_name, $a_successors, $a_content, $a_attributes)
Places a new node $a_node_name directly before nodes with names of $a_successors.
Class ilMediaAliasItem.
Class ilObjMediaObject.
static _lookupType($a_id, $a_reference=false)
lookup object type
setDom(&$a_dom)
Set dom object.
setStyleClass($a_class)
Set style class.
setTriggerOverlays($a_ovs)
Set trigger overlays.
init()
Init page content component.
setExtLinkTitle($a_nr, $a_title)
Set ExtLink Title.
getStandardAliasItem()
Get standard alias item.
setTriggerPopupPositions($a_pos)
Set trigger popup position.
getBaseThumbnailTarget()
Get base thumbnail target.
setTriggerTitles($a_titles)
Set trigger titles.
setMediaObject($a_mediaobject)
Set Media Object.
createMediaObject()
Create new media object.
setTriggerPopupSize($a_size)
Set trigger popup size.
readMediaObject($a_mob_id=0)
Read/get Media Object.
addTriggerMarker()
Add a new trigger marker.
setTriggerPopups($a_pops)
Set trigger popups.
createAlias(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create an media alias in page.
deleteTrigger($a_alias_item, $a_nr)
Delete Trigger.
addTriggerArea( $a_alias_item, $a_shape_type, $a_coords, $a_title, $a_link)
Get caption.
deletePopup($a_hier_id, $a_pc_id)
Delete popup.
setTriggerOverlayPositions($a_pos)
Set trigger overlay position.
create($a_pg_obj, $a_hier_id)
Create pc media object.
setTriggerMarkerPositions($a_pos)
Set trigger marker position.
savePopups($a_popups)
Save popups.
getStandardMediaItem()
Get standard media item.
getTriggerNodes($a_hier_id, $a_pc_id="")
Get trigger nodes.
setNode($a_node)
Set node (and media object node)
Class ilPageContent.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
readHierId()
Read PC Id.
readPCId()
Read PC Id.
setType($a_type)
Set Type.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $DIC
Definition: goto.php:24
xpath_eval($xpath_context, $eval_str, $contextnode=null)
xpath_new_context($dom_document)
$i
Definition: metadata.php:24
$attributes
Definition: metadata.php:231
$xml
Definition: metadata.php:332
foreach($_POST as $key=> $value) $res