private function transferAssignmentsFromOriginalToDuplicatedTaxonomy($originalTaxonomyId, $mappedTaxonomyId)
 {
     $originalTaxAssignment = new ilTaxNodeAssignment('qpl', $this->getSourcePoolId(), 'quest', $originalTaxonomyId);
     $duplicatedTaxAssignment = new ilTaxNodeAssignment('tst', $this->testOBJ->getId(), 'quest', $mappedTaxonomyId);
     foreach ($this->getQuestionIdMapping() as $originalQuestionId => $duplicatedQuestionId) {
         $assignments = $originalTaxAssignment->getAssignmentsOfItem($originalQuestionId);
         foreach ($assignments as $assData) {
             $mappedNodeId = $this->duplicatedTaxonomiesKeysMap->getMappedTaxNodeId($assData['node_id']);
             $duplicatedTaxAssignment->addAssignment($mappedNodeId, $duplicatedQuestionId);
         }
     }
 }
Exemplo n.º 2
0
 public function cloneDependencies($a_target_id, $a_copy_id)
 {
     parent::cloneDependencies($a_target_id, $a_copy_id);
     // clone taxonomies
     include_once "./Services/Taxonomy/classes/class.ilObjTaxonomy.php";
     $all_tax = ilObjTaxonomy::getUsageOfObject($this->getId());
     if (sizeof($all_tax)) {
         include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
         $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
         $mappings = $cwo->getMappings();
         foreach ($all_tax as $old_tax_id) {
             if ($old_tax_id) {
                 // clone it
                 $old_tax = new ilObjTaxonomy($old_tax_id);
                 $new_tax = $old_tax->cloneObject(0, 0, true);
                 $tax_map = $old_tax->getNodeMapping();
                 // assign new taxonomy to new category
                 ilObjTaxonomy::saveUsage($new_tax->getId(), ilObject::_lookupObjId($a_target_id));
                 // clone assignments (for all sub-items)
                 foreach ($mappings as $old_ref_id => $new_ref_id) {
                     if ($old_ref_id != $new_ref_id) {
                         $old_obj_id = ilObject::_lookupObjId($old_ref_id);
                         $new_obj_id = ilObject::_lookupObjId($new_ref_id);
                         $obj_type = ilObject::_lookupType($old_obj_id);
                         $tax_ass = new ilTaxNodeAssignment($obj_type, $old_obj_id, "obj", $old_tax_id);
                         $assignmts = $tax_ass->getAssignmentsOfItem($old_obj_id);
                         if (sizeof($assignmts)) {
                             $new_tax_ass = new ilTaxNodeAssignment($obj_type, $new_obj_id, "obj", $new_tax->getId());
                             foreach ($assignmts as $a) {
                                 if ($tax_map[$a["node_id"]]) {
                                     $new_tax_ass->addAssignment($tax_map[$a["node_id"]], $new_obj_id);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Save input
  *
  * @param
  * @return
  */
 function saveInput($a_component_id, $a_item_type, $a_item_id)
 {
     include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
     $tax_node_ass = new ilTaxNodeAssignment($a_component_id, $a_item_type, $this->getTaxonomyId());
     $tax_node_ass->deleteAssignmentsOfItem($a_item_id);
     $post = $_POST[$this->getPostVar()];
     //var_dump($_POST);
     //var_dump($post);
     if ($this->getMulti()) {
         foreach ($post as $p) {
             $tax_node_ass->addAssignment(ilUtil::stripSlashes($p), $a_item_id);
         }
     } else {
         $tax_node_ass->addAssignment(ilUtil::stripSlashes($post), $a_item_id);
     }
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * update term
  */
 function updateTerm()
 {
     // update term
     $this->term->setTerm(ilUtil::stripSlashes($_POST["term"]));
     $this->term->setLanguage($_POST["term_language"]);
     $this->term->update();
     // update taxonomy assignment
     if ($this->glossary->getTaxonomyId() > 0) {
         include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
         $ta = new ilTaxNodeAssignment("glo", $this->glossary->getId(), "term", $this->glossary->getTaxonomyId());
         $ta->deleteAssignmentsOfItem($this->term->getId());
         if (is_array($_POST["tax_node"])) {
             foreach ($_POST["tax_node"] as $node_id) {
                 $ta->addAssignment($node_id, $this->term->getId());
             }
         }
     }
     // advanced metadata
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php';
     $record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_EDITOR, 'glo', $this->glossary->getId(), 'term', $this->term->getId());
     // :TODO: proper validation
     $form = $this->getEditTermForm();
     $form->checkInput();
     if ($this->record_gui->importEditFormPostValues()) {
         $this->record_gui->writeEditForm();
     }
     ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
     $this->ctrl->redirect($this, "editTerm");
 }
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     //echo $a_entity;
     //var_dump($a_rec);
     switch ($a_entity) {
         case "tax":
             include_once "./Services/Taxonomy/classes/class.ilObjTaxonomy.php";
             //				if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
             //				{
             //					$newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
             //				}
             //				else
             //				{
             $newObj = new ilObjTaxonomy();
             $newObj->create();
             //				}
             $newObj->setTitle($a_rec["Title"]);
             $newObj->setDescription($a_rec["Description"]);
             $newObj->setSortingMode($a_rec["SortingMode"]);
             $newObj->update();
             $this->current_obj = $newObj;
             $a_mapping->addMapping("Services/Taxonomy", "tax", $a_rec["Id"], $newObj->getId());
             break;
         case "tax_tree":
             switch ($a_rec["Type"]) {
                 case "taxn":
                     $parent = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_tree", $a_rec["Parent"]);
                     $tax_id = $a_mapping->getMapping("Services/Taxonomy", "tax", $a_rec["TaxId"]);
                     if ($parent == 0) {
                         $parent = $this->current_obj->getTree()->readRootId();
                     }
                     $node = new ilTaxonomyNode();
                     $node->setTitle($a_rec["Title"]);
                     $node->setOrderNr($a_rec["OrderNr"]);
                     $node->setTaxonomyId($tax_id);
                     $node->create();
                     ilTaxonomyNode::putInTree($tax_id, $node, (int) $parent, "", $a_rec["OrderNr"]);
                     $a_mapping->addMapping("Services/Taxonomy", "tax_tree", $a_rec["Child"], $node->getId());
                     break;
             }
         case "tax_node_assignment":
             $new_item_id = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_item", $a_rec["Component"] . ":" . $a_rec["ItemType"] . ":" . $a_rec["ItemId"]);
             $new_node_id = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_tree", $a_rec["NodeId"]);
             if ($new_item_id > 0 && $new_node_id > 0) {
                 include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
                 $node_ass = new ilTaxNodeAssignment($a_rec["Component"], $a_rec["ItemType"], $this->current_obj->getId());
                 $node_ass->addAssignment($new_node_id, $new_item_id);
             }
             break;
         case "tax_usage":
             $usage = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $a_rec["ObjId"]);
             if ($usage != "") {
                 $usage .= ":";
             }
             $a_mapping->addMapping("Services/Taxonomy", "tax_usage_of_obj", $a_rec["ObjId"], $this->current_obj->getId());
             break;
     }
 }
 /**
  * Save input
  *
  * @param
  * @return
  */
 function saveInput($a_component_id, $a_obj_id, $a_item_type, $a_item_id)
 {
     include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
     $tax_node_ass = new ilTaxNodeAssignment($a_component_id, $a_obj_id, $a_item_type, $this->getTaxonomyId());
     //$tax_node_ass->deleteAssignmentsOfItem($a_item_id);
     $post = $_POST[$this->getPostVar()];
     if (!$this->getMulti()) {
         $post = array($post);
     }
     $current_ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
     $exising = array();
     foreach ($current_ass as $ca) {
         if (!in_array($ca["node_id"], $post)) {
             $tax_node_ass->deleteAssignment($ca["node_id"], $a_item_id);
         } else {
             $exising[] = $ca["node_id"];
         }
     }
     foreach ($post as $p) {
         if (!in_array($p, $exising)) {
             $tax_node_ass->addAssignment(ilUtil::stripSlashes($p), $a_item_id);
         }
     }
 }