ILIAS  Release_4_4_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  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
297  $a_page->getParentType().":pg", $a_page->getId(), 0, $a_page->getLanguage());
298  self::saveMobUsage($a_page, $a_domdoc);
299  foreach($mob_ids as $mob) // check, whether media object can be deleted
300  {
301  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
302  {
303  $mob_obj = new ilObjMediaObject($mob);
304  $usages = $mob_obj->getUsages(false);
305  if (count($usages) == 0) // delete, if no usage exists
306  {
307  $mob_obj->delete();
308  }
309  }
310  }
311  }
312 
318  static function beforePageDelete($a_page)
319  {
320  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
322  $a_page->getParentType().":pg", $a_page->getId(), 0, $a_page->getLanguage());
323 
324  ilObjMediaObject::_deleteAllUsages($a_page->getParentType().":pg", $a_page->getId(), false,
325  $a_page->getLanguage());
326 
327  foreach($mob_ids as $mob) // check, whether media object can be deleted
328  {
329  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
330  {
331  $mob_obj = new ilObjMediaObject($mob);
332  $usages = $mob_obj->getUsages(false);
333  if (count($usages) == 0) // delete, if no usage exists
334  {
335  $mob_obj->delete();
336  }
337  }
338  }
339  }
340 
349  static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
350  {
351  self::saveMobUsage($a_page, $a_old_domdoc, $a_old_nr);
352  }
353 
359  static function saveMobUsage($a_page, $a_domdoc, $a_old_nr = 0)
360  {
361  $usages = array();
362 
363  // media aliases
364  $xpath = new DOMXPath($a_domdoc);
365  $nodes = $xpath->query('//MediaAlias');
366  foreach($nodes as $node)
367  {
368  $id_arr = explode("_", $node->getAttribute("OriginId"));
369  $mob_id = $id_arr[count($id_arr) - 1];
370  if ($mob_id > 0 && $id_arr[1] == "")
371  {
372  $usages[$mob_id] = true;
373  }
374  }
375 
376  // media objects
377  $xpath = new DOMXPath($a_domdoc);
378  $nodes = $xpath->query('//MediaObject/MetaData/General/Identifier');
379  foreach($nodes as $node)
380  {
381  $mob_entry = $node->getAttribute("Entry");
382  $mob_arr = explode("_", $mob_entry);
383  $mob_id = $mob_arr[count($mob_arr) - 1];
384  if ($mob_id > 0 && $mob_arr[1] == "")
385  {
386  $usages[$mob_id] = true;
387  }
388  }
389 
390  // internal links
391  $xpath = new DOMXPath($a_domdoc);
392  $nodes = $xpath->query("//IntLink[@Type='MediaObject']");
393  foreach($nodes as $node)
394  {
395  $mob_target = $node->getAttribute("Target");
396  $mob_arr = explode("_", $mob_target);
397 //echo "<br>3<br>";
398 //echo $mob_target."<br>";
399 //var_dump($mob_arr);
400  $mob_id = $mob_arr[count($mob_arr) - 1];
401  if ($mob_id > 0 && $mob_arr[1] == "")
402  {
403  $usages[$mob_id] = true;
404  }
405  }
406 
407  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
408  ilObjMediaObject::_deleteAllUsages($a_page->getParentType().":pg", $a_page->getId(), $a_old_nr,
409  $a_page->getLanguage());
410  foreach($usages as $mob_id => $val)
411  {
412  ilObjMediaObject::_saveUsage($mob_id, $a_page->getParentType().":pg", $a_page->getId(), $a_old_nr,
413  $a_page->getLanguage());
414  }
415 
416  return $usages;
417  }
418 
419 }
420 ?>