/** * Clone glossary * * @param int target ref_id * @param int copy id */ public function cloneObject($a_target_id, $a_copy_id = 0) { global $ilDB, $ilUser, $ilias; $new_obj = parent::cloneObject($a_target_id, $a_copy_id); $this->cloneMetaData($new_obj); //copy online status if object is not the root copy object $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id); if (!$cp_options->isRootNode($this->getRefId())) { $new_obj->setOnline($this->getOnline()); } // $new_obj->setTitle($this->getTitle()); $new_obj->setDescription($this->getDescription()); $new_obj->setVirtualMode($this->getVirtualMode()); $new_obj->setPresentationMode($this->getPresentationMode()); $new_obj->setSnippetLength($this->getSnippetLength()); $new_obj->update(); // set/copy stylesheet include_once "./Services/Style/classes/class.ilObjStyleSheet.php"; $style_id = $this->getStyleSheetId(); if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id)) { $style_obj = $ilias->obj_factory->getInstanceByObjId($style_id); $new_id = $style_obj->ilClone(); $new_obj->setStyleSheetId($new_id); $new_obj->update(); } // copy taxonomy if (($tax_id = $this->getTaxonomyId()) > 0) { // clone it include_once "./Services/Taxonomy/classes/class.ilObjTaxonomy.php"; $tax = new ilObjTaxonomy($tax_id); $new_tax = $tax->cloneObject(0, 0, true); $map = $tax->getNodeMapping(); // assign new taxonomy to new glossary ilObjTaxonomy::saveUsage($new_tax->getId(), $new_obj->getId()); } // assign new tax/new glossary // handle mapping // prepare tax node assignments objects include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php"; if ($tax_id > 0) { $tax_ass = new ilTaxNodeAssignment("glo", $this->getId(), "term", $tax_id); $new_tax_ass = new ilTaxNodeAssignment("glo", $new_obj->getId(), "term", $new_tax->getId()); } // copy terms foreach (ilGlossaryTerm::getTermList($this->getId()) as $term) { $new_term_id = ilGlossaryTerm::_copyTerm($term["id"], $new_obj->getId()); // copy tax node assignments if ($tax_id > 0) { $assignmts = $tax_ass->getAssignmentsOfItem($term["id"]); foreach ($assignmts as $a) { if ($map[$a["node_id"]] > 0) { $new_tax_ass->addAssignment($map[$a["node_id"]], $new_term_id); } } } } return $new_obj; }
/** * Auto link glossary terms * * @param * @return */ function autoLinkGlossaryTerms($a_glo_id) { // get terms include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php"; $terms = ilGlossaryTerm::getTermList($a_glo_id); // each get page: get content include_once "./Modules/LearningModule/classes/class.ilLMPage.php"; $pages = ilLMPage::getAllPages($this->getType(), $this->getId()); // determine terms that occur in the page $found_pages = array(); foreach ($pages as $p) { $pg = new ilLMPage($p["id"]); $c = $pg->getXMLContent(); foreach ($terms as $t) { if (is_int(stripos($c, $t["term"]))) { $found_pages[$p["id"]]["terms"][] = $t; if (!is_object($found_pages[$p["id"]]["page"])) { $found_pages[$p["id"]]["page"] = $pg; } } } reset($terms); } // ilPCParagraph autoLinkGlossariesPage with page and terms include_once "./Services/COPage/classes/class.ilPCParagraph.php"; foreach ($found_pages as $id => $fp) { ilPCParagraph::autoLinkGlossariesPage($fp["page"], $fp["terms"]); } }
/** * Auto link glossaries * * @param * @return */ function autoLinkGlossaries($a_glos) { if (is_array($a_glos) && count($a_glos) > 0) { include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php"; // check which terms occur in the text (we may // get some false positives due to the strip_tags, but // we do not want to find strong or list or other stuff // within the tags $text = strip_tags($this->getText()); $found_terms = array(); foreach ($a_glos as $glo) { if (ilObject::_lookupType($glo) == "glo") { $terms = ilGlossaryTerm::getTermList($glo); foreach ($terms as $t) { if (is_int(stripos($text, $t["term"]))) { $found_terms[$t["id"]] = $t; } } } } // did we find anything? -> modify content if (count($found_terms) > 0) { self::linkTermsInDom($this->dom, $found_terms, $this->par_node); } } }