ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
5 require_once("./Services/COPage/classes/class.ilPageContent.php");
6 
16 {
17  var $dom;
18  var $iim_node;
19 
20  const AREA = "Area";
21  const MARKER = "Marker";
22 
26  function init()
27  {
28  $this->setType("iim");
29  }
30 
36  function readMediaObject($a_mob_id = 0)
37  {
38  if ($a_mob_id > 0)
39  {
40  $mob = new ilObjMediaObject($a_mob_id);
41  $this->setMediaObject($mob);
42  }
43  }
44 
48  function setNode($a_node)
49  {
50  parent::setNode($a_node); // this is the PageContent node
51  $this->iim_node = $a_node->first_child();
52  $this->med_alias_node = $this->iim_node->first_child();
53  if (is_object($this->med_alias_node) && $this->med_alias_node->myDOMNode != null)
54  {
55  $id = $this->med_alias_node->get_attribute("OriginId");
57  if (ilObject::_lookupType($mob_id) == "mob")
58  {
59  $this->setMediaObject(new ilObjMediaObject($mob_id));
60  }
61  }
62  include_once("./Services/COPage/classes/class.ilMediaAliasItem.php");
63  $this->std_alias_item = new ilMediaAliasItem($this->dom,
64  $this->readHierId(), "Standard", $this->readPCId(),
65  "InteractiveImage");
66  }
67 
71  function setDom(&$a_dom)
72  {
73  $this->dom =& $a_dom;
74  }
75 
81  function setMediaObject($a_mediaobject)
82  {
83  $this->mediaobject = $a_mediaobject;
84  }
85 
91  function getMediaObject()
92  {
93  return $this->mediaobject;
94  }
95 
99  function createMediaObject()
100  {
101  $this->setMediaObject(new ilObjMediaObject());
102  }
103 
107  function create($a_pg_obj, $a_hier_id)
108  {
109  $this->node = $this->createPageContentNode();
110  }
111 
118  {
119  return $this->getMediaObject()->getMediaItem("Standard");
120  }
121 
126  {
127  return $this->std_alias_item;
128  }
129 
130 
137  {
138  return $this->getMediaObject()->getMediaItem("Standard")->getThumbnailTarget();
139  }
140 
141 
148  function createAlias(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
149  {
150  $this->node =& $this->dom->create_element("PageContent");
151  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
152  $this->iim_node =& $this->dom->create_element("InteractiveImage");
153  $this->iim_node =& $this->node->append_child($this->iim_node);
154  $this->mal_node =& $this->dom->create_element("MediaAlias");
155  $this->mal_node =& $this->iim_node->append_child($this->mal_node);
156  $this->mal_node->set_attribute("OriginId", "il__mob_".$this->getMediaObject()->getId());
157 
158  // standard view
159  $item_node =& $this->dom->create_element("MediaAliasItem");
160  $item_node =& $this->iim_node->append_child($item_node);
161  $item_node->set_attribute("Purpose", "Standard");
162  $media_item =& $this->getMediaObject()->getMediaItem("Standard");
163 
164  $layout_node =& $this->dom->create_element("Layout");
165  $layout_node =& $item_node->append_child($layout_node);
166  if ($media_item->getWidth() > 0)
167  {
168  //$layout_node->set_attribute("Width", $media_item->getWidth());
169  }
170  if ($media_item->getHeight() > 0)
171  {
172  //$layout_node->set_attribute("Height", $media_item->getHeight());
173  }
174  $layout_node->set_attribute("HorizontalAlign", "Left");
175 
176  // caption
177  if ($media_item->getCaption() != "")
178  {
179  $cap_node =& $this->dom->create_element("Caption");
180  $cap_node =& $item_node->append_child($cap_node);
181  $cap_node->set_attribute("Align", "bottom");
182  $cap_node->set_content($media_item->getCaption());
183  }
184 
185  // text representation
186  if ($media_item->getTextRepresentation() != "")
187  {
188  $tr_node =& $this->dom->create_element("TextRepresentation");
189  $tr_node =& $item_node->append_child($tr_node);
190  $tr_node->set_content($media_item->getTextRepresentation());
191  }
192  }
193 
197  function dumpXML()
198  {
199  $xml = $this->dom->dump_node($this->node);
200  return $xml;
201  }
202 
208  function setStyleClass($a_class)
209  {
210 // check this
211 die("pcinteractiveimage: setstyleclass");
212  if (is_object($this->iim_node))
213  {
214  $mal_node = $this->iim_node->first_child();
215  if (is_object($mal_node))
216  {
217  if (!empty($a_class))
218  {
219  $mal_node->set_attribute("Class", $a_class);
220  }
221  else
222  {
223  if ($mal_node->has_attribute("Class"))
224  {
225  $mal_node->remove_attribute("Class");
226  }
227  }
228  }
229  }
230  }
231 
237  function getStyleClass()
238  {
239  if (is_object($this->iim_node))
240  {
241  $mal_node = $this->iim_node->first_child();
242  if (is_object($mal_node))
243  {
244  $class = $mal_node->get_attribute("Class");
245  return $class;
246  }
247  }
248  }
249 
250 
254 
255 
259  function addContentPopup()
260  {
261  global $lng;
262 
263  $max = 0;
264  $popups = $this->getPopups();
265  foreach ($popups as $p)
266  {
267  $max = max($max, (int) $p["nr"]);
268  }
269 
270  $new_item = $this->dom->create_element("ContentPopup");
271  $new_item->set_attribute("Title", $lng->txt("cont_new_popup"));
272  $new_item->set_attribute("Nr", $max + 1);
273  $new_item = $this->iim_node->append_child($new_item);
274  }
275 
279  function getPopups()
280  {
281  $titles = array();
282  $childs = $this->iim_node->child_nodes();
283  $k = 0;
284  for($i = 0; $i < count($childs); $i++)
285  {
286  if ($childs[$i]->node_name() == "ContentPopup")
287  {
288  $pc_id = $childs[$i]->get_attribute("PCID");
289  $hier_id = $childs[$i]->get_attribute("HierId");
290  $title = $childs[$i]->get_attribute("Title");
291  $nr = $childs[$i]->get_attribute("Nr");
292 
293  $titles[] = array("title" => $title, "nr" => $nr,
294  "pc_id" => $pc_id, "hier_id" => $hier_id);
295  $k++;
296  }
297  }
298  return $titles;
299  }
300 
304  function savePopups($a_popups)
305  {
306  $childs = $this->iim_node->child_nodes();
307  for($i = 0; $i < count($childs); $i++)
308  {
309  if ($childs[$i]->node_name() == "ContentPopup")
310  {
311  $pc_id = $childs[$i]->get_attribute("PCID");
312  $hier_id = $childs[$i]->get_attribute("HierId");
313  $k = $hier_id.":".$pc_id;
314  $childs[$i]->set_attribute("Title", $a_popups[$k]);
315  }
316  }
317  }
318 
322  function deletePopup($a_hier_id, $a_pc_id)
323  {
324  // File Item
325  $childs = $this->iim_node->child_nodes();
326  $nodes = array();
327  for ($i=0; $i<count($childs); $i++)
328  {
329  if ($childs[$i]->node_name() == "ContentPopup")
330  {
331  if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
332  $a_hier_id == $childs[$i]->get_attribute("HierId"))
333  {
334  $childs[$i]->unlink($childs[$i]);
335  }
336  }
337  }
338  }
339 
343 /*
344  function getCaption($a_hier_id, $a_pc_id)
345  {
346  $captions = array();
347  $tab_nodes = $this->tabs_node->child_nodes();
348  $k = 0;
349  for($i = 0; $i < count($tab_nodes); $i++)
350  {
351  if ($tab_nodes[$i]->node_name() == "Tab")
352  {
353  if ($a_pc_id == $tab_nodes[$i]->get_attribute("PCID") &&
354  ($a_hier_id == $tab_nodes[$i]->get_attribute("HierId")))
355  {
356  $tab_node_childs = $tab_nodes[$i]->child_nodes();
357  for($j = 0; $j < count($tab_node_childs); $j++)
358  {
359  if ($tab_node_childs[$j]->node_name() == "TabCaption")
360  {
361  return $tab_node_childs[$j]->get_content();
362  }
363  }
364  }
365  }
366  }
367 
368  return "";
369  }
370 */
371 
375 /*
376  function savePositions($a_pos)
377  {
378  asort($a_pos);
379 
380  // File Item
381  $childs = $this->tabs_node->child_nodes();
382  $nodes = array();
383  for ($i=0; $i<count($childs); $i++)
384  {
385  if ($childs[$i]->node_name() == "Tab")
386  {
387  $pc_id = $childs[$i]->get_attribute("PCID");
388  $hier_id = $childs[$i]->get_attribute("HierId");
389  $nodes[$hier_id.":".$pc_id] = $childs[$i];
390  $childs[$i]->unlink($childs[$i]);
391  }
392  }
393 
394  foreach($a_pos as $k => $v)
395  {
396  if (is_object($nodes[$k]))
397  {
398  $nodes[$k] = $this->tabs_node->append_child($nodes[$k]);
399  }
400  }
401  }
402 */
403 
407 /*
408  function deleteTab($a_hier_id, $a_pc_id)
409  {
410  // File Item
411  $childs = $this->tabs_node->child_nodes();
412  $nodes = array();
413  for ($i=0; $i<count($childs); $i++)
414  {
415  if ($childs[$i]->node_name() == "Tab")
416  {
417  if ($a_pc_id == $childs[$i]->get_attribute("PCID") &&
418  $a_hier_id == $childs[$i]->get_attribute("HierId"))
419  {
420  $childs[$i]->unlink($childs[$i]);
421  }
422  }
423  }
424  }
425 */
426 
430 
434  function addTriggerArea($a_alias_item, $a_shape_type, $a_coords, $a_title,
435  $a_link)
436  {
437  $max = 0;
438  $triggers = $this->getTriggers();
439  foreach ($triggers as $t)
440  {
441  $max = max($max, (int) $t["Nr"]);
442  }
443 
444  $link = array(
445  "LinkType" => IL_EXT_LINK,
446  "Href" => ilUtil::stripSlashes("#"));
447 
448  $a_alias_item->addMapArea(
449  $a_shape_type, $a_coords,
450  ilUtil::stripSlashes($a_title), $link, $max + 1);
451 
452  $attributes = array("Type" => self::AREA,
453  "Title" => ilUtil::stripSlashes($a_title),
454  "Nr" => $max + 1,
455  "OverlayX" => "0", "OverlayY" => "0", "Overlay" => "", "PopupNr" => "",
456  "PopupX" => "0", "PopupY" => "0", "PopupWidth" => "150", "PopupHeight" => "200");
457  $ma_node = ilDOMUtil::addElementToList($this->dom, $this->iim_node,
458  "Trigger", array("ContentPopup"), "", $attributes);
459  }
460 
464  function addTriggerMarker()
465  {
466  global $lng;
467 
468  $max = 0;
469  $triggers = $this->getTriggers();
470  foreach ($triggers as $t)
471  {
472  $max = max($max, (int) $t["Nr"]);
473  }
474 
475  $attributes = array("Type" => self::MARKER,
476  "Title" => $lng->txt("cont_new_marker"),
477  "Nr" => $max + 1, "OverlayX" => "0", "OverlayY" => "0",
478  "MarkerX" => "0", "MarkerY" => "0", "PopupNr" => "",
479  "PopupX" => "0", "PopupY" => "0", "PopupWidth" => "150", "PopupHeight" => "200");
480  $ma_node = ilDOMUtil::addElementToList($this->dom, $this->iim_node,
481  "Trigger", array("ContentPopup"), "", $attributes);
482  }
483 
487  function getTriggerNodes($a_hier_id, $a_pc_id = "")
488  {
489  if ($a_pc_id != "")
490  {
491  $xpc = xpath_new_context($this->dom);
492  $path = "//PageContent[@PCID = '".$a_pc_id."']/InteractiveImage/Trigger";
493  $res =& xpath_eval($xpc, $path);
494  if (count($res->nodeset) > 0)
495  {
496  return $res->nodeset;
497  }
498  return array();
499  }
500 
501  $xpc = xpath_new_context($this->dom);
502  $path = "//PageContent[@HierId = '".$a_hier_id."']/InteractiveImage/Trigger";
503  $res =& xpath_eval($xpc, $path);
504  if (count($res->nodeset) > 0)
505  {
506  return $res->nodeset;
507  }
508  }
509 
510 
514  function getTriggers()
515  {
516  $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
517  $trigger_arr = array();
518  for($i=0; $i < count($tr_nodes); $i++)
519  {
520  $tr_node = $tr_nodes[$i];
521  $childs = $tr_node->child_nodes();
522  $trigger_arr[] = array(
523  "Nr" => $tr_node->get_attribute("Nr"),
524  "Type" => $tr_node->get_attribute("Type"),
525  "Title" => $tr_node->get_attribute("Title"),
526  "OverlayX" => $tr_node->get_attribute("OverlayX"),
527  "OverlayY" => $tr_node->get_attribute("OverlayY"),
528  "MarkerX" => $tr_node->get_attribute("MarkerX"),
529  "MarkerY" => $tr_node->get_attribute("MarkerY"),
530  "Overlay" => $tr_node->get_attribute("Overlay"),
531  "PopupNr" => $tr_node->get_attribute("PopupNr"),
532  "PopupX" => $tr_node->get_attribute("PopupX"),
533  "PopupY" => $tr_node->get_attribute("PopupY"),
534  "PopupWidth" => $tr_node->get_attribute("PopupWidth"),
535  "PopupHeight" => $tr_node->get_attribute("PopupHeight")
536  );
537  }
538 
539  return $trigger_arr;
540  }
541 
545  function deleteTrigger($a_alias_item, $a_nr)
546  {
547  // File Item
548  $childs = $this->iim_node->child_nodes();
549  $nodes = array();
550  for ($i=0; $i<count($childs); $i++)
551  {
552  if ($childs[$i]->node_name() == "Trigger")
553  {
554  if ($a_nr == $childs[$i]->get_attribute("Nr"))
555  {
556  $childs[$i]->unlink($childs[$i]);
557  }
558  }
559  }
560  $a_alias_item->deleteMapAreaById($a_nr);
561  }
562 
563 
569  function setTriggerOverlays($a_ovs)
570  {
571  $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
572  for($i=0; $i < count($tr_nodes); $i++)
573  {
574  $tr_node = $tr_nodes[$i];
575  if (isset($a_ovs["".$tr_node->get_attribute("Nr")]))
576  {
577  $tr_node->set_attribute("Overlay",
578  $a_ovs["".$tr_node->get_attribute("Nr")]);
579  }
580  }
581  }
582 
588  function setTriggerOverlayPositions($a_pos)
589  {
590  $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
591  for($i=0; $i < count($tr_nodes); $i++)
592  {
593  $tr_node = $tr_nodes[$i];
594  if (isset($a_pos["".$tr_node->get_attribute("Nr")]))
595  {
596  $pos = explode(",", $a_pos["".$tr_node->get_attribute("Nr")]);
597  $tr_node->set_attribute("OverlayX", (int) $pos[0]);
598  $tr_node->set_attribute("OverlayY", (int) $pos[1]);
599  }
600  }
601  }
602 
608  function setTriggerMarkerPositions($a_pos)
609  {
610  $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
611  for($i=0; $i < count($tr_nodes); $i++)
612  {
613  $tr_node = $tr_nodes[$i];
614  if ($tr_node->get_attribute("Type") == self::MARKER)
615  {
616  if (isset($a_pos["".$tr_node->get_attribute("Nr")]))
617  {
618  $pos = explode(",", $a_pos["".$tr_node->get_attribute("Nr")]);
619  $tr_node->set_attribute("MarkerX", (int) $pos[0]);
620  $tr_node->set_attribute("MarkerY", (int) $pos[1]);
621  }
622  }
623  }
624  }
625 
631  function setTriggerPopupPositions($a_pos)
632  {
633  $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
634  for($i=0; $i < count($tr_nodes); $i++)
635  {
636  $tr_node = $tr_nodes[$i];
637  if (isset($a_pos["".$tr_node->get_attribute("Nr")]))
638  {
639  $pos = explode(",", $a_pos["".$tr_node->get_attribute("Nr")]);
640  $tr_node->set_attribute("PopupX", (int) $pos[0]);
641  $tr_node->set_attribute("PopupY", (int) $pos[1]);
642  }
643  }
644  }
645 
651  function setTriggerPopupSize($a_size)
652  {
653  $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
654  for($i=0; $i < count($tr_nodes); $i++)
655  {
656  $tr_node = $tr_nodes[$i];
657  if (isset($a_size["".$tr_node->get_attribute("Nr")]))
658  {
659  $size = explode(",", $a_size["".$tr_node->get_attribute("Nr")]);
660  $tr_node->set_attribute("PopupWidth", (int) $size[0]);
661  $tr_node->set_attribute("PopupHeight", (int) $size[1]);
662  }
663  }
664  }
665 
671  function setTriggerPopups($a_pops)
672  {
673  $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
674  for($i=0; $i < count($tr_nodes); $i++)
675  {
676  $tr_node = $tr_nodes[$i];
677  if (isset($a_pops["".$tr_node->get_attribute("Nr")]))
678  {
679  $pop = $a_pops["".$tr_node->get_attribute("Nr")];
680  $tr_node->set_attribute("PopupNr", $pop);
681  }
682  }
683  }
684 
690  function setTriggerTitles($a_titles)
691  {
692  $tr_nodes = $this->getTriggerNodes($this->hier_id, $this->getPcId());
693  for($i=0; $i < count($tr_nodes); $i++)
694  {
695  $tr_node = $tr_nodes[$i];
696  if (isset($a_titles["".$tr_node->get_attribute("Nr")]))
697  {
698  $tr_node->set_attribute("Title",
699  $a_titles["".$tr_node->get_attribute("Nr")]);
700  $this->setExtLinkTitle($tr_node->get_attribute("Nr"),
701  $a_titles["".$tr_node->get_attribute("Nr")]);
702  }
703  }
704  }
705 
712  function setExtLinkTitle($a_nr, $a_title)
713  {
714  if ($this->getPcId() != "")
715  {
716  $xpc = xpath_new_context($this->dom);
717  $path = "//PageContent[@PCID = '".$this->getPcId()."']/InteractiveImage/MediaAliasItem/MapArea[@Id='".$a_nr."']/ExtLink";
718  $res = xpath_eval($xpc, $path);
719  if (count($res->nodeset) > 0)
720  {
721  $res->nodeset[0]->set_content($a_title);
722  }
723  return;
724  }
725 
726  $xpc = xpath_new_context($this->dom);
727  $path = "//PageContent[@HierId = '".$this->hier_id."']/InteractiveImage/MediaAliasItem/MapArea[@Id='".$a_nr."']/ExtLink";
728  $res =& xpath_eval($xpc, $path);
729  if (count($res->nodeset) > 0)
730  {
731  $res->nodeset[0]->set_content($a_title);
732  }
733  }
734 
735 
736 }
737 ?>