ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTaxMDGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  protected $md_rbac_id; // [int]
15  protected $md_obj_id; // [int]
16  protected $md_obj_type; // [string]
17 
26  public function __construct($a_md_rbac_id, $a_md_obj_id, $a_md_obj_type)
27  {
28  $this->md_rbac_id = $a_md_rbac_id;
29  $this->md_obj_id = $a_md_obj_id;
30  $this->md_obj_type = $a_md_obj_type;
31  }
32 
38  protected function getSelectableTaxonomies()
39  {
40  global $objDefinition, $tree;
41 
42  if($objDefinition->isRBACObject($this->md_obj_type))
43  {
44  $res = array();
45 
46  // see ilTaxonomyBlockGUI::getActiveTaxonomies()
47 
48  // get all active taxonomies of parent objects
49  foreach($tree->getPathFull((int)$_REQUEST["ref_id"]) as $node)
50  {
51  // currently only active for categories
52  if($node["type"] == "cat")
53  {
54  include_once "Services/Object/classes/class.ilObjectServiceSettingsGUI.php";
55  include_once "Services/Container/classes/class.ilContainer.php";
57  $node["obj_id"],
59  false
60  ))
61  {
62  include_once "Services/Taxonomy/classes/class.ilObjTaxonomy.php";
63  $tax_ids = ilObjTaxonomy::getUsageOfObject($node["obj_id"]);
64  if(sizeof($tax_ids))
65  {
66  $res = array_merge($res, $tax_ids);
67  }
68  }
69  }
70  }
71 
72  if(sizeof($res))
73  {
74  return $res;
75  }
76  }
77  }
78 
85  protected function initTaxNodeAssignment($a_tax_id)
86  {
87  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
88  return new ilTaxNodeAssignment($this->md_obj_type, $this->md_obj_id, "obj", $a_tax_id);
89  }
90 
96  public function addToMDForm(ilPropertyFormGUI $a_form)
97  {
98  $tax_ids = $this->getSelectableTaxonomies();
99  if(is_array($tax_ids))
100  {
101  include_once "Services/Taxonomy/classes/class.ilTaxSelectInputGUI.php";
102  foreach($tax_ids as $tax_id)
103  {
104  // get existing assignments
105  $node_ids = array();
106  $ta = $this->initTaxNodeAssignment($tax_id);
107  foreach($ta->getAssignmentsOfItem($this->md_obj_id) as $ass)
108  {
109  $node_ids[] = $ass["node_id"];
110  }
111 
112  $tax_sel = new ilTaxSelectInputGUI($tax_id, "md_tax_".$tax_id, true);
113  $tax_sel->setValue($node_ids);
114  $a_form->addItem($tax_sel);
115  }
116  }
117  }
118 
122  public function updateFromMDForm()
123  {
124  $tax_ids = $this->getSelectableTaxonomies();
125  if(is_array($tax_ids))
126  {
127  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
128 
129  foreach($tax_ids as $tax_id)
130  {
131  $ta = $this->initTaxNodeAssignment($tax_id);
132 
133  // delete existing assignments
134  $ta->deleteAssignmentsOfItem($this->md_obj_id);
135 
136  // set current assignment
137  if(is_array($_POST["md_tax_".$tax_id]))
138  {
139  foreach($_POST["md_tax_".$tax_id] as $node_id)
140  {
141  $ta->addAssignment($node_id, $this->md_obj_id);
142  }
143  }
144  }
145  }
146  }
147 }