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);
         }
     }
 }
Esempio 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);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Set current values
  *
  * @param
  * @return
  */
 function setCurrentValues($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());
     $ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
     $nodes = array();
     foreach ($ass as $a) {
         $nodes[] = $a["node_id"];
     }
     if ($this->getMulti()) {
         $this->setValue($nodes);
     } else {
         $this->setValue($nodes[0]);
     }
 }
Esempio 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;
 }
 /**
  * Get edit term form
  *
  * @param
  * @return
  */
 function getEditTermForm()
 {
     global $ilTabs, $ilCtrl;
     include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
     $form = new ilPropertyFormGUI();
     $form->setFormAction($this->ctrl->getFormAction($this, "updateTerm"));
     $form->setTitle($this->lng->txt("cont_edit_term"));
     $term = new ilTextInputGUI($this->lng->txt("cont_term"), "term");
     $term->setRequired(true);
     $term->setValue($this->term->getTerm());
     $form->addItem($term);
     $lang = new ilSelectInputGUI($this->lng->txt("language"), "term_language");
     $lang->setRequired(true);
     $lang->setOptions(ilMDLanguageItem::_getLanguages());
     $lang->setValue($this->term->getLanguage());
     $form->addItem($lang);
     // taxonomy
     if ($this->glossary->getTaxonomyId() > 0) {
         include_once "./Services/Taxonomy/classes/class.ilTaxSelectInputGUI.php";
         $tax_node_assign = new ilTaxSelectInputGUI($this->glossary->getTaxonomyId(), "tax_node", true);
         include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
         $ta = new ilTaxNodeAssignment("glo", $this->glossary->getId(), "term", $this->glossary->getTaxonomyId());
         $assgnmts = $ta->getAssignmentsOfItem($this->term->getId());
         $node_ids = array();
         foreach ($assgnmts as $a) {
             $node_ids[] = $a["node_id"];
         }
         $tax_node_assign->setValue($node_ids);
         $form->addItem($tax_node_assign);
     }
     // advanced metadata
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php';
     $this->record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_EDITOR, 'glo', $this->glossary->getId(), 'term', $this->term->getId());
     $this->record_gui->setPropertyForm($form);
     $this->record_gui->setSelectedOnly(true);
     $this->record_gui->parse();
     $form->addCommandButton("updateTerm", $this->lng->txt("save"));
     return $form;
 }
Esempio n. 6
0
 private function loadTaxonomyAssignmentData($parentObjId, $questionId)
 {
     $taxAssignmentData = array();
     foreach ($this->getAvailableTaxonomyIds() as $taxId) {
         require_once 'Services/Taxonomy/classes/class.ilTaxonomyTree.php';
         require_once 'Services/Taxonomy/classes/class.ilTaxNodeAssignment.php';
         $taxTree = new ilTaxonomyTree($taxId);
         $taxAssignment = new ilTaxNodeAssignment('qpl', $parentObjId, 'quest', $taxId);
         $assignments = $taxAssignment->getAssignmentsOfItem($questionId);
         foreach ($assignments as $assData) {
             if (!isset($taxAssignmentData[$assData['tax_id']])) {
                 $taxAssignmentData[$assData['tax_id']] = array();
             }
             $nodeData = $taxTree->getNodeData($assData['node_id']);
             $assData['node_lft'] = $nodeData['lft'];
             $taxAssignmentData[$assData['tax_id']][$assData['node_id']] = $assData;
         }
     }
     return $taxAssignmentData;
 }