ILIAS  Release_5_0_x_branch Revision 61816
 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 $mob_node;
19 
23  function init()
24  {
25  $this->setType("media");
26  }
27 
33  function readMediaObject($a_mob_id = 0)
34  {
35  if ($a_mob_id > 0)
36  {
37  $mob = new ilObjMediaObject($a_mob_id);
38  $this->setMediaObject($mob);
39  }
40  }
41 
42  function setNode(&$a_node)
43  {
44  parent::setNode($a_node); // this is the PageContent node
45  $this->mob_node =& $a_node->first_child();
46  }
47 
51  function setDom(&$a_dom)
52  {
53  $this->dom =& $a_dom;
54  }
55 
59  function setHierId($a_hier_id)
60  {
61  $this->hier_id = $a_hier_id;
62  }
63 
69  function setMediaObject($a_mediaobject)
70  {
71  $this->mediaobject = $a_mediaobject;
72  }
73 
79  function getMediaObject()
80  {
81  return $this->mediaobject;
82  }
83 
84  function createMediaObject()
85  {
86  $this->setMediaObject(new ilObjMediaObject());
87  }
88 
92  function create(&$a_pg_obj, $a_hier_id)
93  {
94  $this->node = $this->createPageContentNode();
95  }
96 
103  function createAlias(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
104  {
105  $this->node =& $this->dom->create_element("PageContent");
106  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
107  $this->mob_node =& $this->dom->create_element("MediaObject");
108  $this->mob_node =& $this->node->append_child($this->mob_node);
109  $this->mal_node =& $this->dom->create_element("MediaAlias");
110  $this->mal_node =& $this->mob_node->append_child($this->mal_node);
111  $this->mal_node->set_attribute("OriginId", "il__mob_".$this->getMediaObject()->getId());
112 
113  // standard view
114  $item_node =& $this->dom->create_element("MediaAliasItem");
115  $item_node =& $this->mob_node->append_child($item_node);
116  $item_node->set_attribute("Purpose", "Standard");
117  $media_item =& $this->getMediaObject()->getMediaItem("Standard");
118 
119  $layout_node =& $this->dom->create_element("Layout");
120  $layout_node =& $item_node->append_child($layout_node);
121  if ($media_item->getWidth() > 0)
122  {
123  //$layout_node->set_attribute("Width", $media_item->getWidth());
124  }
125  if ($media_item->getHeight() > 0)
126  {
127  //$layout_node->set_attribute("Height", $media_item->getHeight());
128  }
129  $layout_node->set_attribute("HorizontalAlign", "Left");
130 
131  // caption
132  if ($media_item->getCaption() != "")
133  {
134  $cap_node =& $this->dom->create_element("Caption");
135  $cap_node =& $item_node->append_child($cap_node);
136  $cap_node->set_attribute("Align", "bottom");
137  $cap_node->set_content($media_item->getCaption());
138  }
139 
140  // text representation
141  if ($media_item->getTextRepresentation() != "")
142  {
143  $tr_node =& $this->dom->create_element("TextRepresentation");
144  $tr_node =& $item_node->append_child($tr_node);
145  $tr_node->set_content($media_item->getTextRepresentation());
146  }
147 
148  $pars = $media_item->getParameters();
149  foreach($pars as $par => $val)
150  {
151  $par_node =& $this->dom->create_element("Parameter");
152  $par_node =& $item_node->append_child($par_node);
153  $par_node->set_attribute("Name", $par);
154  $par_node->set_attribute("Value", $val);
155  }
156 
157  // fullscreen view
158  $fullscreen_item =& $this->getMediaObject()->getMediaItem("Fullscreen");
159  if (is_object($fullscreen_item))
160  {
161  $item_node =& $this->dom->create_element("MediaAliasItem");
162  $item_node =& $this->mob_node->append_child($item_node);
163  $item_node->set_attribute("Purpose", "Fullscreen");
164 
165  // width and height
166  $layout_node =& $this->dom->create_element("Layout");
167  $layout_node =& $item_node->append_child($layout_node);
168  if ($fullscreen_item->getWidth() > 0)
169  {
170  $layout_node->set_attribute("Width", $fullscreen_item->getWidth());
171  }
172  if ($fullscreen_item->getHeight() > 0)
173  {
174  $layout_node->set_attribute("Height", $fullscreen_item->getHeight());
175  }
176 
177  // caption
178  if ($fullscreen_item->getCaption() != "")
179  {
180  $cap_node =& $this->dom->create_element("Caption");
181  $cap_node =& $item_node->append_child($cap_node);
182  $cap_node->set_attribute("Align", "bottom");
183  $cap_node->set_content($fullscreen_item->getCaption());
184  }
185 
186  // text representation
187  if ($fullscreen_item->getTextRepresentation() != "")
188  {
189  $tr_node =& $this->dom->create_element("TextRepresentation");
190  $tr_node =& $item_node->append_child($tr_node);
191  $tr_node->set_content($fullscreen_item->getTextRepresentation());
192  }
193 
194  $pars = $fullscreen_item->getParameters();
195  foreach($pars as $par => $val)
196  {
197  $par_node =& $this->dom->create_element("Parameter");
198  $par_node =& $item_node->append_child($par_node);
199  $par_node->set_attribute("Name", $par);
200  $par_node->set_attribute("Value", $val);
201  }
202  }
203  }
204 
211  {
212  if (is_object($this->mob_node))
213  {
214  $this->mal_node =& $this->mob_node->first_child();
215  if (is_object($this->mal_node) && $this->mal_node->node_name() == "MediaAlias")
216  {
217  $this->mal_node->set_attribute("OriginId", "il__mob_".$this->getMediaObject()->getId());
218  }
219  }
220  }
221 
225  function dumpXML()
226  {
227  $xml = $this->dom->dump_node($this->node);
228  return $xml;
229  }
230 
236  function setClass($a_class)
237  {
238  if (is_object($this->mob_node))
239  {
240  $mal_node = $this->mob_node->first_child();
241  if (is_object($mal_node))
242  {
243  if (!empty($a_class))
244  {
245  $mal_node->set_attribute("Class", $a_class);
246  }
247  else
248  {
249  if ($mal_node->has_attribute("Class"))
250  {
251  $mal_node->remove_attribute("Class");
252  }
253  }
254  }
255  }
256  }
257 
263  function getClass()
264  {
265  if (is_object($this->mob_node))
266  {
267  $mal_node = $this->mob_node->first_child();
268  if (is_object($mal_node))
269  {
270  $class = $mal_node->get_attribute("Class");
271  return $class;
272  }
273  }
274  }
275 
280  static function getLangVars()
281  {
282  return array("pc_mob");
283  }
284 
293  static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
294  {
295  if (!$a_page->getImportMode())
296  {
297  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
299  $a_page->getParentType().":pg", $a_page->getId(), 0, $a_page->getLanguage());
300  self::saveMobUsage($a_page, $a_domdoc);
301  foreach($mob_ids as $mob) // check, whether media object can be deleted
302  {
303  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
304  {
305  $mob_obj = new ilObjMediaObject($mob);
306  $usages = $mob_obj->getUsages(false);
307  if (count($usages) == 0) // delete, if no usage exists
308  {
309  $mob_obj->delete();
310  }
311  }
312  }
313  }
314  }
315 
321  static function beforePageDelete($a_page)
322  {
323  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
325  $a_page->getParentType().":pg", $a_page->getId(), 0, $a_page->getLanguage());
326 
327  ilObjMediaObject::_deleteAllUsages($a_page->getParentType().":pg", $a_page->getId(), false,
328  $a_page->getLanguage());
329 
330  foreach($mob_ids as $mob) // check, whether media object can be deleted
331  {
332  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
333  {
334  $mob_obj = new ilObjMediaObject($mob);
335  $usages = $mob_obj->getUsages(false);
336  if (count($usages) == 0) // delete, if no usage exists
337  {
338  $mob_obj->delete();
339  }
340  }
341  }
342  }
343 
352  static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
353  {
354  self::saveMobUsage($a_page, $a_old_domdoc, $a_old_nr);
355  }
356 
362  static function saveMobUsage($a_page, $a_domdoc, $a_old_nr = 0)
363  {
364  $usages = array();
365 
366  // media aliases
367  $xpath = new DOMXPath($a_domdoc);
368  $nodes = $xpath->query('//MediaAlias');
369  foreach($nodes as $node)
370  {
371  $id_arr = explode("_", $node->getAttribute("OriginId"));
372  $mob_id = $id_arr[count($id_arr) - 1];
373  if ($mob_id > 0 && $id_arr[1] == "")
374  {
375  $usages[$mob_id] = true;
376  }
377  }
378 
379  // media objects
380  $xpath = new DOMXPath($a_domdoc);
381  $nodes = $xpath->query('//MediaObject/MetaData/General/Identifier');
382  foreach($nodes as $node)
383  {
384  $mob_entry = $node->getAttribute("Entry");
385  $mob_arr = explode("_", $mob_entry);
386  $mob_id = $mob_arr[count($mob_arr) - 1];
387  if ($mob_id > 0 && $mob_arr[1] == "")
388  {
389  $usages[$mob_id] = true;
390  }
391  }
392 
393  // internal links
394  $xpath = new DOMXPath($a_domdoc);
395  $nodes = $xpath->query("//IntLink[@Type='MediaObject']");
396  foreach($nodes as $node)
397  {
398  $mob_target = $node->getAttribute("Target");
399  $mob_arr = explode("_", $mob_target);
400 //echo "<br>3<br>";
401 //echo $mob_target."<br>";
402 //var_dump($mob_arr);
403  $mob_id = $mob_arr[count($mob_arr) - 1];
404  if ($mob_id > 0 && $mob_arr[1] == "")
405  {
406  $usages[$mob_id] = true;
407  }
408  }
409 
410  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
411  ilObjMediaObject::_deleteAllUsages($a_page->getParentType().":pg", $a_page->getId(), $a_old_nr,
412  $a_page->getLanguage());
413  foreach($usages as $mob_id => $val)
414  {
415  // save usage, if object exists...
416  if (ilObject::_lookupType($mob_id) == "mob")
417  {
418  ilObjMediaObject::_saveUsage($mob_id, $a_page->getParentType().":pg", $a_page->getId(), $a_old_nr,
419  $a_page->getLanguage());
420  }
421  }
422 
423  return $usages;
424  }
425 
426 }
427 ?>