ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCMediaObject.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Services/COPage/classes/class.ilPageContent.php");
5 
17 {
18  var $dom;
19  var $mob_node;
20 
24  function init()
25  {
26  $this->setType("media");
27  }
28 
34  function readMediaObject($a_mob_id = 0)
35  {
36  if ($a_mob_id > 0)
37  {
38  $mob = new ilObjMediaObject($a_mob_id);
39  $this->setMediaObject($mob);
40  }
41  }
42 
43  function setNode(&$a_node)
44  {
45  parent::setNode($a_node); // this is the PageContent node
46  $this->mob_node =& $a_node->first_child();
47  }
48 
52  function setDom(&$a_dom)
53  {
54  $this->dom =& $a_dom;
55  }
56 
60  function setHierId($a_hier_id)
61  {
62  $this->hier_id = $a_hier_id;
63  }
64 
70  function setMediaObject($a_mediaobject)
71  {
72  $this->mediaobject = $a_mediaobject;
73  }
74 
80  function getMediaObject()
81  {
82  return $this->mediaobject;
83  }
84 
85  function createMediaObject()
86  {
87  $this->setMediaObject(new ilObjMediaObject());
88  }
89 
93  function create(&$a_pg_obj, $a_hier_id)
94  {
95  $this->node = $this->createPageContentNode();
96  }
97 
104  function createAlias(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
105  {
106  $this->node =& $this->dom->create_element("PageContent");
107  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
108  $this->mob_node =& $this->dom->create_element("MediaObject");
109  $this->mob_node =& $this->node->append_child($this->mob_node);
110  $this->mal_node =& $this->dom->create_element("MediaAlias");
111  $this->mal_node =& $this->mob_node->append_child($this->mal_node);
112  $this->mal_node->set_attribute("OriginId", "il__mob_".$this->getMediaObject()->getId());
113 
114  // standard view
115  $item_node =& $this->dom->create_element("MediaAliasItem");
116  $item_node =& $this->mob_node->append_child($item_node);
117  $item_node->set_attribute("Purpose", "Standard");
118  $media_item =& $this->getMediaObject()->getMediaItem("Standard");
119 
120  $layout_node =& $this->dom->create_element("Layout");
121  $layout_node =& $item_node->append_child($layout_node);
122  if ($media_item->getWidth() > 0)
123  {
124  //$layout_node->set_attribute("Width", $media_item->getWidth());
125  }
126  if ($media_item->getHeight() > 0)
127  {
128  //$layout_node->set_attribute("Height", $media_item->getHeight());
129  }
130  $layout_node->set_attribute("HorizontalAlign", "Left");
131 
132  // caption
133  if ($media_item->getCaption() != "")
134  {
135  $cap_node =& $this->dom->create_element("Caption");
136  $cap_node =& $item_node->append_child($cap_node);
137  $cap_node->set_attribute("Align", "bottom");
138  $cap_node->set_content($media_item->getCaption());
139  }
140 
141  // text representation
142  if ($media_item->getTextRepresentation() != "")
143  {
144  $tr_node =& $this->dom->create_element("TextRepresentation");
145  $tr_node =& $item_node->append_child($tr_node);
146  $tr_node->set_content($media_item->getTextRepresentation());
147  }
148 
149  $pars = $media_item->getParameters();
150  foreach($pars as $par => $val)
151  {
152  $par_node =& $this->dom->create_element("Parameter");
153  $par_node =& $item_node->append_child($par_node);
154  $par_node->set_attribute("Name", $par);
155  $par_node->set_attribute("Value", $val);
156  }
157 
158  // fullscreen view
159  $fullscreen_item =& $this->getMediaObject()->getMediaItem("Fullscreen");
160  if (is_object($fullscreen_item))
161  {
162  $item_node =& $this->dom->create_element("MediaAliasItem");
163  $item_node =& $this->mob_node->append_child($item_node);
164  $item_node->set_attribute("Purpose", "Fullscreen");
165 
166  // width and height
167  $layout_node =& $this->dom->create_element("Layout");
168  $layout_node =& $item_node->append_child($layout_node);
169  if ($fullscreen_item->getWidth() > 0)
170  {
171  $layout_node->set_attribute("Width", $fullscreen_item->getWidth());
172  }
173  if ($fullscreen_item->getHeight() > 0)
174  {
175  $layout_node->set_attribute("Height", $fullscreen_item->getHeight());
176  }
177 
178  // caption
179  if ($fullscreen_item->getCaption() != "")
180  {
181  $cap_node =& $this->dom->create_element("Caption");
182  $cap_node =& $item_node->append_child($cap_node);
183  $cap_node->set_attribute("Align", "bottom");
184  $cap_node->set_content($fullscreen_item->getCaption());
185  }
186 
187  // text representation
188  if ($fullscreen_item->getTextRepresentation() != "")
189  {
190  $tr_node =& $this->dom->create_element("TextRepresentation");
191  $tr_node =& $item_node->append_child($tr_node);
192  $tr_node->set_content($fullscreen_item->getTextRepresentation());
193  }
194 
195  $pars = $fullscreen_item->getParameters();
196  foreach($pars as $par => $val)
197  {
198  $par_node =& $this->dom->create_element("Parameter");
199  $par_node =& $item_node->append_child($par_node);
200  $par_node->set_attribute("Name", $par);
201  $par_node->set_attribute("Value", $val);
202  }
203  }
204  }
205 
212  {
213  if (is_object($this->mob_node))
214  {
215  $this->mal_node =& $this->mob_node->first_child();
216  if (is_object($this->mal_node) && $this->mal_node->node_name() == "MediaAlias")
217  {
218  $this->mal_node->set_attribute("OriginId", "il__mob_".$this->getMediaObject()->getId());
219  }
220  }
221  }
222 
226  function dumpXML()
227  {
228  $xml = $this->dom->dump_node($this->node);
229  return $xml;
230  }
231 
237  function setClass($a_class)
238  {
239  if (is_object($this->mob_node))
240  {
241  $mal_node = $this->mob_node->first_child();
242  if (is_object($mal_node))
243  {
244  if (!empty($a_class))
245  {
246  $mal_node->set_attribute("Class", $a_class);
247  }
248  else
249  {
250  if ($mal_node->has_attribute("Class"))
251  {
252  $mal_node->remove_attribute("Class");
253  }
254  }
255  }
256  }
257  }
258 
264  function getClass()
265  {
266  if (is_object($this->mob_node))
267  {
268  $mal_node = $this->mob_node->first_child();
269  if (is_object($mal_node))
270  {
271  $class = $mal_node->get_attribute("Class");
272  return $class;
273  }
274  }
275  }
276 
277 }
278 ?>