/**
  * Save all usages of media objects (media aliases, media objects, internal links)
  *
  * @param	string		$a_xml		xml data of page
  */
 static function saveMobUsage($a_page, $a_domdoc, $a_old_nr = 0)
 {
     $usages = array();
     // media aliases
     $xpath = new DOMXPath($a_domdoc);
     $nodes = $xpath->query('//MediaAlias');
     foreach ($nodes as $node) {
         $id_arr = explode("_", $node->getAttribute("OriginId"));
         $mob_id = $id_arr[count($id_arr) - 1];
         if ($mob_id > 0 && $id_arr[1] == "") {
             $usages[$mob_id] = true;
         }
     }
     // media objects
     $xpath = new DOMXPath($a_domdoc);
     $nodes = $xpath->query('//MediaObject/MetaData/General/Identifier');
     foreach ($nodes as $node) {
         $mob_entry = $node->getAttribute("Entry");
         $mob_arr = explode("_", $mob_entry);
         $mob_id = $mob_arr[count($mob_arr) - 1];
         if ($mob_id > 0 && $mob_arr[1] == "") {
             $usages[$mob_id] = true;
         }
     }
     // internal links
     $xpath = new DOMXPath($a_domdoc);
     $nodes = $xpath->query("//IntLink[@Type='MediaObject']");
     foreach ($nodes as $node) {
         $mob_target = $node->getAttribute("Target");
         $mob_arr = explode("_", $mob_target);
         //echo "<br>3<br>";
         //echo $mob_target."<br>";
         //var_dump($mob_arr);
         $mob_id = $mob_arr[count($mob_arr) - 1];
         if ($mob_id > 0 && $mob_arr[1] == "") {
             $usages[$mob_id] = true;
         }
     }
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     ilObjMediaObject::_deleteAllUsages($a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage());
     foreach ($usages as $mob_id => $val) {
         ilObjMediaObject::_saveUsage($mob_id, $a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage());
     }
     return $usages;
 }
 /**
  * delete page object
  */
 function delete()
 {
     global $ilDB;
     $mobs = array();
     $files = array();
     if (!$this->page_not_found) {
         $this->buildDom();
         $mobs = $this->collectMediaObjects(false);
     }
     $this->__beforeDelete();
     // delete style usages
     $this->deleteStyleUsages(false);
     // delete internal links
     $this->deleteInternalLinks();
     // delete all mob usages
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     ilObjMediaObject::_deleteAllUsages($this->getParentType() . ":pg", $this->getId());
     // delete news
     include_once "./Services/News/classes/class.ilNewsItem.php";
     ilNewsItem::deleteNewsOfContext($this->getParentId(), $this->getParentType(), $this->getId(), "pg");
     // delete page_object entry
     $ilDB->manipulate("DELETE FROM page_object " . "WHERE page_id = " . $ilDB->quote($this->getId(), "integer") . " AND parent_type= " . $ilDB->quote($this->getParentType(), "text"));
     //$this->ilias->db->query($query);
     // delete media objects
     foreach ($mobs as $mob_id) {
         if (ilObject::_lookupType($mob_id) != 'mob') {
             $GLOBALS['ilLog']->write(__METHOD__ . ': Type mismatch. Ignoring mob with id: ' . $mob_id);
             continue;
         }
         if (ilObject::_exists($mob_id)) {
             $mob_obj =& new ilObjMediaObject($mob_id);
             $mob_obj->delete();
         }
     }
     /* delete public and private notes (see PageObjectGUI->getNotesHTML())
     		  as they can be seen as personal data we are keeping them for now
     		include_once("Services/Notes/classes/class.ilNote.php");
     		foreach(array(IL_NOTE_PRIVATE, IL_NOTE_PUBLIC) as $note_type)
     		{
     			foreach(ilNote::_getNotesOfObject($this->getParentId(), $this->getId(),
     				$this->getParentType(), $note_type) as $note)
     			{
     				$note->delete();
     			}
     		}
     		*/
 }
 /**
  * save all usages of media objects (media aliases, media objects, internal links)
  *
  * @param	string		$a_xml		xml data of page
  */
 function saveMobUsage($a_xml, $a_old_nr = 0)
 {
     $doc = domxml_open_mem($a_xml);
     // media aliases
     $xpc = xpath_new_context($doc);
     $path = "//MediaAlias";
     $res =& xpath_eval($xpc, $path);
     $usages = array();
     for ($i = 0; $i < count($res->nodeset); $i++) {
         $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
         $mob_id = $id_arr[count($id_arr) - 1];
         if ($mob_id > 0) {
             $usages[$mob_id] = true;
         }
     }
     // media objects
     $xpc = xpath_new_context($doc);
     $path = "//MediaObject/MetaData/General/Identifier";
     $res =& xpath_eval($xpc, $path);
     for ($i = 0; $i < count($res->nodeset); $i++) {
         $mob_entry = $res->nodeset[$i]->get_attribute("Entry");
         $mob_arr = explode("_", $mob_entry);
         $mob_id = $mob_arr[count($mob_arr) - 1];
         if ($mob_id > 0) {
             $usages[$mob_id] = true;
         }
     }
     // internal links
     $xpc = xpath_new_context($doc);
     $path = "//IntLink[@Type='MediaObject']";
     $res =& xpath_eval($xpc, $path);
     for ($i = 0; $i < count($res->nodeset); $i++) {
         $mob_target = $res->nodeset[$i]->get_attribute("Target");
         $mob_arr = explode("_", $mob_target);
         $mob_id = $mob_arr[count($mob_arr) - 1];
         if ($mob_id > 0) {
             $usages[$mob_id] = true;
         }
     }
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     ilObjMediaObject::_deleteAllUsages($this->getParentType() . ":pg", $this->getId(), $a_old_nr);
     foreach ($usages as $mob_id => $val) {
         ilObjMediaObject::_saveUsage($mob_id, $this->getParentType() . ":pg", $this->getId(), $a_old_nr);
     }
     return $usages;
 }