/**
  * Collect page elements (that need to be exported separately)
  *
  * @param string $a_pg_type page type
  * @param int $a_pg_id page id
  */
 function collectPageElements($a_type, $a_id)
 {
     // collect media objects
     $pg_mobs = ilObjMediaObject::_getMobsOfObject($a_type, $a_id);
     foreach ($pg_mobs as $pg_mob) {
         $this->mobs[$pg_mob] = $pg_mob;
     }
     // collect all files
     include_once "./Modules/File/classes/class.ilObjFile.php";
     $files = ilObjFile::_getFilesOfObject($a_type, $a_id);
     foreach ($files as $f) {
         $this->files[$f] = $f;
     }
     $skill_tree = $ws_tree = null;
     $pcs = ilPageContentUsage::getUsagesOfPage($a_id, $a_type);
     foreach ($pcs as $pc) {
         // skils
         if ($pc["type"] == "skmg") {
             $skill_id = $pc["id"];
             // get user id from portfolio page
             include_once "Services/Portfolio/classes/class.ilPortfolioPage.php";
             $page = new ilPortfolioPage(0, $a_id);
             $user_id = $page->create_user;
             // we only need 1 instance each
             if (!$skill_tree) {
                 include_once "Services/Skill/classes/class.ilSkillTree.php";
                 $skill_tree = new ilSkillTree();
                 include_once "Services/Skill/classes/class.ilPersonalSkill.php";
                 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
                 $ws_tree = new ilWorkspaceTree($user_id);
             }
             // walk skill tree
             $b_skills = ilSkillTreeNode::getSkillTreeNodes($skill_id, true);
             foreach ($b_skills as $bs) {
                 $skill = ilSkillTreeNodeFactory::getInstance($bs["id"]);
                 $level_data = $skill->getLevelData();
                 foreach ($level_data as $k => $v) {
                     // get assigned materials from personal skill
                     $mat = ilPersonalSkill::getAssignedMaterial($user_id, $bs["tref"], $v["id"]);
                     if (sizeof($mat)) {
                         foreach ($mat as $item) {
                             $wsp_id = $item["wsp_id"];
                             $obj_id = $ws_tree->lookupObjectId($wsp_id);
                             // all possible material types for now
                             switch (ilObject::_lookupType($obj_id)) {
                                 case "file":
                                     $this->files[$obj_id] = $obj_id;
                                     break;
                                 case "tstv":
                                     include_once "Modules/Test/classes/class.ilObjTestVerification.php";
                                     $obj = new ilObjTestVerification($obj_id, false);
                                     $this->files_direct[$obj_id] = array($obj->getFilePath(), $obj->getOfflineFilename());
                                     break;
                                 case "excv":
                                     include_once "Modules/Exercise/classes/class.ilObjExerciseVerification.php";
                                     $obj = new ilObjExerciseVerification($obj_id, false);
                                     $this->files_direct[$obj_id] = array($obj->getFilePath(), $obj->getOfflineFilename());
                                     break;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * export all pages of learning module to html file
  */
 function exportHTMLPages(&$a_lm_gui, $a_target_dir)
 {
     global $tpl, $ilBench, $ilLocator;
     $pages = ilLMPageObject::getPageList($this->getId());
     $lm_tree =& $this->getLMTree();
     $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg");
     $this->first_page_id = $first_page["child"];
     // iterate all learning module pages
     $mobs = array();
     $int_links = array();
     $this->offline_files = array();
     include_once "./Services/COPage/classes/class.ilPageContentUsage.php";
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     // get html export id mapping
     $lm_set = new ilSetting("lm");
     $exp_id_map = array();
     if ($lm_set->get("html_export_ids")) {
         foreach ($pages as $page) {
             $exp_id = ilLMPageObject::getExportId($this->getId(), $page["obj_id"]);
             if (trim($exp_id) != "") {
                 $exp_id_map[$page["obj_id"]] = trim($exp_id);
             }
         }
     }
     //exit;
     reset($pages);
     foreach ($pages as $page) {
         if (ilLMPage::_exists($this->getType(), $page["obj_id"])) {
             $ilLocator->clearItems();
             $ilBench->start("ExportHTML", "exportHTMLPage");
             $ilBench->start("ExportHTML", "exportPageHTML");
             $this->exportPageHTML($a_lm_gui, $a_target_dir, $page["obj_id"], "", $exp_id_map);
             $ilBench->stop("ExportHTML", "exportPageHTML");
             // get all snippets of page
             $pcs = ilPageContentUsage::getUsagesOfPage($page["obj_id"], $this->getType() . ":pg");
             foreach ($pcs as $pc) {
                 if ($pc["type"] == "incl") {
                     $incl_mobs = ilObjMediaObject::_getMobsOfObject("mep:pg", $pc["id"]);
                     foreach ($incl_mobs as $incl_mob) {
                         $mobs[$incl_mob] = $incl_mob;
                     }
                 }
             }
             // get all media objects of page
             $pg_mobs = ilObjMediaObject::_getMobsOfObject($this->getType() . ":pg", $page["obj_id"]);
             foreach ($pg_mobs as $pg_mob) {
                 $mobs[$pg_mob] = $pg_mob;
             }
             // get all internal links of page
             $pg_links = ilInternalLink::_getTargetsOfSource($this->getType() . ":pg", $page["obj_id"]);
             $int_links = array_merge($int_links, $pg_links);
             // get all files of page
             include_once "./Modules/File/classes/class.ilObjFile.php";
             $pg_files = ilObjFile::_getFilesOfObject($this->getType() . ":pg", $page["obj_id"]);
             $this->offline_files = array_merge($this->offline_files, $pg_files);
             $ilBench->stop("ExportHTML", "exportHTMLPage");
         }
     }
     $this->offline_mobs = $mobs;
     $this->offline_int_links = $int_links;
 }
 /**
  * confirm remove of mobs
  */
 function confirmRemove()
 {
     global $ilAccess, $ilCtrl, $lng;
     if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) {
         $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
     }
     if (!isset($_POST["id"])) {
         $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
     }
     // display confirmation message
     include_once "./Services/Utilities/classes/class.ilConfirmationGUI.php";
     $cgui = new ilConfirmationGUI();
     $cgui->setFormAction($this->ctrl->getFormAction($this));
     $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
     $cgui->setCancel($this->lng->txt("cancel"), "cancelRemove");
     $cgui->setConfirm($this->lng->txt("confirm"), "remove");
     foreach ($_POST["id"] as $obj_id) {
         $type = ilMediaPoolItem::lookupType($obj_id);
         $title = ilMediaPoolItem::lookupTitle($obj_id);
         // check whether page can be removed
         $add = "";
         if ($type == "pg") {
             include_once "./Services/COPage/classes/class.ilPageContentUsage.php";
             $usages = ilPageContentUsage::getUsages("incl", $obj_id, false);
             if (count($usages) > 0) {
                 ilUtil::sendFailure(sprintf($lng->txt("mep_content_snippet_in_use"), $title), true);
                 $ilCtrl->redirect($this, "listMedia");
             } else {
                 // check whether the snippet is used in older versions of pages
                 $usages = ilPageContentUsage::getUsages("incl", $obj_id, true);
                 if (count($usages) > 0) {
                     $add = "<div class='small'>" . $lng->txt("mep_content_snippet_used_in_older_versions") . "</div>";
                 }
             }
         }
         $caption = ilUtil::getImageTagByType($type, $this->tpl->tplPath) . " " . $title . $add;
         $cgui->addItem("id[]", $obj_id, $caption);
     }
     $this->tpl->setContent($cgui->getHTML());
 }
 /**
  * save content include usages
  */
 static function saveContentIncludeUsage($a_page, $a_domdoc, $a_old_nr = 0)
 {
     include_once "./Services/COPage/classes/class.ilPageContentUsage.php";
     $ci_ids = self::collectContentIncludes($a_page, $a_domdoc);
     ilPageContentUsage::deleteAllUsages("incl", $a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage());
     foreach ($ci_ids as $ci_id) {
         if ((int) $ci_id["inst_id"] <= 0) {
             ilPageContentUsage::saveUsage("incl", $ci_id["id"], $a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage());
         }
     }
 }
 /**
  * save content include usages
  */
 function saveSkillUsage($a_xml = "", $a_old_nr = 0)
 {
     include_once "./Services/COPage/classes/class.ilPageContentUsage.php";
     $skl_ids = $this->collectSkills($a_xml);
     ilPageContentUsage::deleteAllUsages("skmg", $this->getParentType() . ":pg", $this->getId(), $a_old_nr);
     foreach ($skl_ids as $skl_id) {
         if ((int) $skl_id["inst_id"] <= 0) {
             ilPageContentUsage::saveUsage("skmg", $skl_id["id"], $this->getParentType() . ":pg", $this->getId(), $a_old_nr);
         }
     }
 }