/** * Validate all pages */ function validatePages() { include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php"; include_once "./Modules/LearningModule/classes/class.ilLMPage.php"; $mess = ""; $pages = ilLMPageObject::getPageList($this->getId()); foreach ($pages as $page) { if (ilLMPage::_exists($this->getType(), $page["obj_id"])) { $cpage = new ilLMPage($page["obj_id"]); $cpage->buildDom(); $error = @$cpage->validateDom(); if ($error != "") { $this->lng->loadLanguageModule("content"); ilUtil::sendInfo($this->lng->txt("cont_import_validation_errors")); $title = ilLMObject::_lookupTitle($page["obj_id"]); $page_obj = new ilLMPageObject($this, $page["obj_id"]); $mess .= $this->lng->txt("obj_pg") . ": " . $title; $mess .= '<div class="small">'; foreach ($error as $e) { $err_mess = implode($e, " - "); if (!is_int(strpos($err_mess, ":0:"))) { $mess .= htmlentities($err_mess) . "<br />"; } } $mess .= '</div>'; $mess .= "<br />"; } } } return $mess; }
/** * Update internal links, after multiple pages have been copied */ static function updateInternalLinks($a_copied_nodes, $a_parent_type = "lm") { $all_fixes = array(); foreach ($a_copied_nodes as $original_id => $copied_id) { $copied_type = ilLMObject::_lookupType($copied_id); $copy_lm = ilLMObject::_lookupContObjID($copied_id); if ($copied_type == "pg") { // // 1. Outgoing links from the copied page. // //$targets = ilInternalLink::_getTargetsOfSource($a_parent_type.":pg", $copied_id); include_once "./Modules/LearningModule/classes/class.ilLMPage.php"; $tpg = new ilLMPage($copied_id); $tpg->buildDom(); $il = $tpg->getInternalLinks(); $targets = array(); foreach ($il as $l) { $targets[] = array("type" => ilInternalLink::_extractTypeOfTarget($l["Target"]), "id" => (int) ilInternalLink::_extractObjIdOfTarget($l["Target"]), "inst" => (int) ilInternalLink::_extractInstOfTarget($l["Target"])); } $fix = array(); foreach ($targets as $target) { if (($target["inst"] == 0 || ($target["inst"] = IL_INST_ID)) && ($target["type"] == "pg" || $target["type"] == "st")) { // first check, whether target is also within the copied set if ($a_copied_nodes[$target["id"]] > 0) { $fix[$target["id"]] = $a_copied_nodes[$target["id"]]; } else { // now check, if a copy if the target is already in the same lm // only if target is not already in the same lm! $trg_lm = ilLMObject::_lookupContObjID($target["id"]); if ($trg_lm != $copy_lm) { $lm_data = ilLMObject::_getAllObjectsForImportId("il__" . $target["type"] . "_" . $target["id"]); $found = false; foreach ($lm_data as $item) { if (!$found && $item["lm_id"] == $copy_lm) { $fix[$target["id"]] = $item["obj_id"]; $found = true; } } } } } } // outgoing links to be fixed if (count($fix) > 0) { //echo "<br>--".$copied_id; //var_dump($fix); $t = ilObject::_lookupType($copy_lm); if (is_array($all_fixes[$t . ":" . $copied_id])) { $all_fixes[$t . ":" . $copied_id] += $fix; } else { $all_fixes[$t . ":" . $copied_id] = $fix; } } } if ($copied_type == "pg" || $copied_type == "st") { // // 2. Incoming links to the original pages // // A->B A2 (A+B currently copied) // A->C B2 // B->A // C->A C2->A (C already copied) $original_lm = ilLMObject::_lookupContObjID($original_id); $original_type = ilObject::_lookupType($original_lm); if ($original_lm != $copy_lm) { // This gets sources that link to A+B (so we have C here) // (this also does already the trick when instance map areas are given in C) // int_link, where target_type, target_id, target_inst -> ok $sources = ilInternalLink::_getSourcesOfTarget($copied_type, $original_id, 0); // mobs linking to $original_id // map_area, where link_type, target -> ok $mobs = ilMapArea::_getMobsForTarget("int", "il__" . $copied_type . "_" . $original_id); // pages using these mobs include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; foreach ($mobs as $mob) { // mob_usage, where id -> ok // mep_item, where foreign_id, type -> ok // mep_tree, where child -> already existed // il_news_item, where mob_id -> ok // map_area, where link_type, target -> aready existed // media_item, where id -> already existed // personal_clipboard, where item_id, type -> ok $usages = ilObjMediaObject::lookupUsages($mob); foreach ($usages as $usage) { if ($usage["type"] == "lm:pg" | $usage["type"] == "lm:st") { $sources[] = $usage; } } } $fix = array(); foreach ($sources as $source) { $stype = explode(":", $source["type"]); $source_type = $stype[1]; if ($source_type == "pg" || $source_type == "st") { // first of all: source must be in original lm $src_lm = ilLMObject::_lookupContObjID($source["id"]); if ($src_lm == $original_lm) { // check, if a copy if the source is already in the same lm // now we look for the latest copy of C in LM2 $lm_data = ilLMObject::_getAllObjectsForImportId("il__" . $source_type . "_" . $source["id"], $copy_lm); $found = false; foreach ($lm_data as $item) { if (!$found) { $fix[$item["obj_id"]][$original_id] = $copied_id; $found = true; } } } } } // outgoing links to be fixed if (count($fix) > 0) { foreach ($fix as $page_id => $fix_array) { $t = ilObject::_lookupType($copy_lm); if (is_array($all_fixes[$t . ":" . $page_id])) { $all_fixes[$t . ":" . $page_id] += $fix_array; } else { $all_fixes[$t . ":" . $page_id] = $fix_array; } } } } } } foreach ($all_fixes as $pg => $fixes) { $pg = explode(":", $pg); include_once "./Services/COPage/classes/class.ilPageObjectFactory.php"; $page = ilPageObjectFactory::getInstance($pg[0], $pg[1]); if ($page->moveIntLinks($fixes)) { $page->update(true, true); } } }
/** * Standard Version of Fill Row. Most likely to * be overwritten by derived class. */ protected function fillRow($a_set) { global $lng, $ilCtrl; $this->tpl->setVariable("TXT_PAGE_TITLE", $a_set["title"]); $ilCtrl->setParameterByClass("illmpageobjectgui", "obj_id", $a_set["obj_id"]); $this->tpl->setVariable("HREF_PAGE", $ilCtrl->getLinkTargetByClass("illmpageobjectgui", "edit")); include_once "./Modules/LearningModule/classes/class.ilLMPage.php"; $page_object = new ilLMPage($a_set["obj_id"]); $page_object->buildDom(); $int_links = $page_object->getInternalLinks(); foreach ($int_links as $link) { $target = $link["Target"]; if (substr($target, 0, 4) == "il__") { $target_arr = explode("_", $target); $target_id = $target_arr[count($target_arr) - 1]; $type = $link["Type"]; switch ($type) { case "PageObject": $this->tpl->setCurrentBlock("link"); $this->tpl->setVariable("TXT_LINK_TYPE", $lng->txt("pg")); if (ilLMObject::_exists($target_id)) { $lm_id = ilLMObject::_lookupContObjID($target_id); $add_str = $lm_id != $this->lm_id ? " (" . ilObject::_lookupTitle($lm_id) . ")" : ""; $this->tpl->setVariable("TXT_LINK_TITLE", ilLMObject::_lookupTitle($target_id) . $add_str); } else { $this->tpl->setVariable("TXT_MISSING", "<b>" . $lng->txt("cont_target_missing") . " [" . $target_id . "]" . "</b>"); } $this->tpl->parseCurrentBlock(); break; case "StructureObject": $this->tpl->setCurrentBlock("link"); $this->tpl->setVariable("TXT_LINK_TYPE", $lng->txt("st")); if (ilLMObject::_exists($target_id)) { $lm_id = ilLMObject::_lookupContObjID($target_id); $add_str = $lm_id != $this->lm_id ? " (" . ilObject::_lookupTitle($lm_id) . ")" : ""; $this->tpl->setVariable("TXT_LINK_TITLE", ilLMObject::_lookupTitle($target_id) . $add_str); } else { $this->tpl->setVariable("TXT_MISSING", "<b>" . $lng->txt("cont_target_missing") . " [" . $target_id . "]" . "</b>"); } $this->tpl->parseCurrentBlock(); break; case "GlossaryItem": $this->tpl->setCurrentBlock("link"); $this->tpl->setVariable("TXT_LINK_TYPE", $lng->txt("cont_term")); include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php"; if (ilGlossaryTerm::_exists($target_id)) { $this->tpl->setVariable("TXT_LINK_TITLE", ilGlossaryTerm::_lookGlossaryTerm($target_id)); } else { $this->tpl->setVariable("TXT_MISSING", "<b>" . $lng->txt("cont_target_missing") . " [" . $target_id . "]" . "</b>"); } $this->tpl->parseCurrentBlock(); break; case "MediaObject": $this->tpl->setCurrentBlock("link"); $this->tpl->setVariable("TXT_LINK_TYPE", $lng->txt("mob")); if (ilObject::_exists($target_id)) { $this->tpl->setVariable("TXT_LINK_TITLE", ilObject::_lookupTitle($target_id)); } else { $this->tpl->setVariable("TXT_MISSING", "<b>" . $lng->txt("cont_target_missing") . " [" . $target_id . "]" . "</b>"); } $this->tpl->parseCurrentBlock(); break; case "RepositoryItem": $this->tpl->setCurrentBlock("link"); $this->tpl->setVariable("TXT_LINK_TYPE", $lng->txt("cont_repository_item")); $obj_type = ilObject::_lookupType($target_id, true); $obj_id = ilObject::_lookupObjId($target_id); if (ilObject::_exists($obj_id)) { $this->tpl->setVariable("TXT_LINK_TITLE", ilObject::_lookupTitle($obj_id) . " (" . $lng->txt("obj_" . $obj_type) . ")"); } else { $this->tpl->setVariable("TXT_MISSING", "<b>" . $lng->txt("cont_target_missing") . " [" . $target_id . "]" . "</b>"); } $this->tpl->parseCurrentBlock(); break; } } else { $type = $link["Type"]; switch ($type) { case "PageObject": $this->tpl->setVariable("TXT_LINK_TYPE", $lng->txt("pg")); break; case "StructureObject": $this->tpl->setVariable("TXT_LINK_TYPE", $lng->txt("st")); break; case "GlossaryItem": $this->tpl->setVariable("TXT_LINK_TYPE", $lng->txt("cont_term")); break; case "MediaObject": $this->tpl->setVariable("TXT_LINK_TYPE", $lng->txt("mob")); break; case "RepositoryItem": $this->tpl->setVariable("TXT_LINK_TYPE", $lng->txt("cont_repository_item")); break; } $this->tpl->setCurrentBlock("link"); $this->tpl->setVariable("TXT_MISSING", "<b>" . $lng->txt("cont_target_missing") . " [" . $target . "]" . "</b>"); $this->tpl->parseCurrentBlock(); } } }