/**
  * Constructor
  */
 function __construct($a_parent_obj, $a_parent_cmd, $a_node_id, $a_tax, $a_comp_id, $a_obj_id, $a_item_type, $a_info_obj)
 {
     global $ilCtrl, $lng, $ilAccess, $lng;
     $this->setId("tax_ass_it");
     $this->setLimit(9999);
     $this->tax = $a_tax;
     $this->node_id = $a_node_id;
     $this->comp_id = $a_comp_id;
     $this->obj_id = $a_obj_id;
     $this->item_type = $a_item_type;
     $this->info_obj = $a_info_obj;
     parent::__construct($a_parent_obj, $a_parent_cmd);
     include_once "./Services/Taxonomy/classes/class.ilObjTaxonomy.php";
     include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
     $tax_ass = new ilTaxNodeAssignment($this->comp_id, $this->obj_id, $this->item_type, $this->tax->getId());
     $this->setData($tax_ass->getAssignmentsOfNode($this->node_id));
     $this->setTitle($lng->txt("tax_assigned_items"));
     $this->addColumn($this->lng->txt("tax_order"));
     $this->setDefaultOrderField("order_nr");
     $this->setDefaultOrderDirection("asc");
     $this->addColumn($this->lng->txt("title"));
     $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
     $this->setRowTemplate("tpl.tax_ass_items_row.html", "Services/Taxonomy");
     $this->addCommandButton("saveAssignedItemsSorting", $lng->txt("save"));
 }
 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);
         }
     }
 }
Ejemplo n.º 3
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]);
     }
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 /**
  * Save assigned items sorting
  *
  * @param
  * @return
  */
 function saveAssignedItemsSorting()
 {
     global $lng, $ilCtrl;
     include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
     if (is_array($_POST["order"])) {
         $order = $_POST["order"];
         //asort($order, SORT_NUMERIC);
         //$cnt = 10;
         $tax_node = (int) $_GET["tax_node"];
         foreach ($order as $a_item_id => $ord_nr) {
             $tax_ass = new ilTaxNodeAssignment($this->assigned_item_comp_id, $this->assigned_item_obj_id, $this->assigned_item_type, $this->getCurrentTaxonomyId());
             $tax_ass->setOrderNr($tax_node, $a_item_id, $ord_nr);
             //$cnt+= 10;
         }
         $tax_ass = new ilTaxNodeAssignment($this->assigned_item_comp_id, $this->assigned_item_obj_id, $this->assigned_item_type, $this->getCurrentTaxonomyId());
         $tax_ass->fixOrderNr($tax_node);
         ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
     }
     $ilCtrl->redirect($this, "listAssignedItems");
 }
 private function getTaxonomyFilterExpressions()
 {
     $expressions = array();
     require_once 'Services/Taxonomy/classes/class.ilTaxonomyTree.php';
     require_once 'Services/Taxonomy/classes/class.ilTaxNodeAssignment.php';
     foreach ($this->getTaxonomyFilters() as $taxId => $taxNodes) {
         $questionIds = array();
         $forceBypass = true;
         foreach ($taxNodes as $taxNode) {
             $forceBypass = false;
             $taxTree = new ilTaxonomyTree($taxId);
             $taxNodeAssignment = new ilTaxNodeAssignment('tst', $this->getTestObjId(), 'quest', $taxId);
             $subNodes = $taxTree->getSubTreeIds($taxNode);
             $subNodes[] = $taxNode;
             $taxItems = $taxNodeAssignment->getAssignmentsOfNode($subNodes);
             foreach ($taxItems as $taxItem) {
                 $questionIds[$taxItem['item_id']] = $taxItem['item_id'];
             }
         }
         if (!$forceBypass) {
             $expressions[] = $this->db->in('question_id', $questionIds, false, 'integer');
         }
     }
     return $expressions;
 }
Ejemplo n.º 8
0
 /**
  * Get all assigned items under a node
  *
  * @param
  * @return
  */
 static function getSubTreeItems($a_comp, $a_obj_id, $a_item_type, $a_tax_id, $a_node)
 {
     include_once "./Services/Taxonomy/classes/class.ilTaxonomyTree.php";
     $tree = new ilTaxonomyTree($a_tax_id);
     $sub_nodes = $tree->getSubTreeIds($a_node);
     $sub_nodes[] = $a_node;
     include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
     $tn_ass = new ilTaxNodeAssignment($a_comp, $a_obj_id, $a_item_type, $a_tax_id);
     $items = $tn_ass->getAssignmentsOfNode($sub_nodes);
     return $items;
 }
Ejemplo n.º 9
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");
 }
Ejemplo n.º 10
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;
 }
 /**
  * Delete taxonomy node
  */
 function delete()
 {
     global $ilDB;
     // delete all assignments of the node
     include_once "./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
     ilTaxNodeAssignment::deleteAssignmentsOfNode($this->getId());
     $query = "DELETE FROM tax_node WHERE obj_id= " . $ilDB->quote($this->getId(), "integer");
     $ilDB->manipulate($query);
 }
 /**
  * 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;
     }
 }
 public function getFilteredObjects()
 {
     include_once "Services/Taxonomy/classes/class.ilTaxonomyTree.php";
     include_once "Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
     include_once "Services/Taxonomy/classes/class.ilTaxonomyNode.php";
     $tax_obj_ids = $tax_map = array();
     // :TODO: this could be smarter
     foreach ($this->selection as $node_id) {
         $node = new ilTaxonomyNode($node_id);
         $tax_map[$node->getTaxonomyId()][] = $node_id;
     }
     foreach ($tax_map as $tax_id => $node_ids) {
         $tax_tree = new ilTaxonomyTree($tax_id);
         // combine taxonomy nodes OR
         $tax_nodes = array();
         foreach ($node_ids as $node_id) {
             $tax_nodes = array_merge($tax_nodes, $tax_tree->getSubTreeIds($node_id));
             $tax_nodes[] = $node_id;
         }
         $tax_obj_ids[$tax_id] = ilTaxNodeAssignment::findObjectsByNode($tax_id, $tax_nodes, "obj");
     }
     // combine taxonomies AND
     $obj_ids = null;
     foreach ($tax_obj_ids as $tax_objs) {
         if ($obj_ids === null) {
             $obj_ids = $tax_objs;
         } else {
             $obj_ids = array_intersect($obj_ids, $tax_objs);
         }
     }
     return (array) $obj_ids;
 }