ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTaxonomyClassificationProvider.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("Services/Classification/classes/class.ilClassificationProvider.php");
5 
15 {
16  protected $selection; // [array]
17 
18  protected static $valid_tax_map = array();
19 
20  public static function isActive($a_parent_ref_id, $a_parent_obj_id, $a_parent_obj_type)
21  {
22  return (bool)self::getActiveTaxonomiesForParentRefId($a_parent_ref_id);
23  }
24 
25  public function render(array &$a_html, $a_parent_gui)
26  {
27  include_once("./Services/Taxonomy/classes/class.ilTaxonomyExplorerGUI.php");
28 
29  foreach(self::$valid_tax_map[$this->parent_ref_id] as $tax_id)
30  {
31  $tax_exp = new ilTaxonomyExplorerGUI($a_parent_gui, null, $tax_id, null, null);
32  $tax_exp->setSkipRootNode(true);
33  $tax_exp->setOnClick("il.Classification.toggle({tax_node: '{NODE_CHILD}'});");
34 
35  if(is_array($this->selection))
36  {
37  foreach($this->selection as $node_id)
38  {
39  $tax_exp->setPathOpen($node_id);
40  $tax_exp->setNodeSelected($node_id);
41  }
42  }
43 
44  if (!$tax_exp->handleCommand())
45  {
46  $a_html[] = array(
47  "title" => ilObject::_lookupTitle($tax_id),
48  "html" => $tax_exp->getHTML()
49  );
50  }
51  }
52  }
53 
54  public function importPostData($a_saved = null)
55  {
56  $incoming_id = (int)$_REQUEST["tax_node"];
57  if($incoming_id)
58  {
59  if(is_array($a_saved))
60  {
61  foreach($a_saved as $idx => $node_id)
62  {
63  if($node_id == $incoming_id)
64  {
65  unset($a_saved[$idx]);
66  return $a_saved;
67  }
68  }
69  $a_saved[] = $incoming_id;
70  return $a_saved;
71  }
72  else
73  {
74  return array($incoming_id);
75  }
76  }
77  }
78 
79  public function setSelection($a_value)
80  {
81  $this->selection = $a_value;
82  }
83 
84  protected static function getActiveTaxonomiesForParentRefId($a_parent_ref_id)
85  {
86  global $tree;
87 
88  if(!isset(self::$valid_tax_map[$a_parent_ref_id]))
89  {
90  include_once "Services/Object/classes/class.ilObjectServiceSettingsGUI.php";
91  include_once "Services/Taxonomy/classes/class.ilObjTaxonomy.php";
92  include_once "Modules/Category/classes/class.ilObjCategoryGUI.php";
93 
95 
96  $all_valid = array();
97  foreach($tree->getPathFull($a_parent_ref_id) as $node)
98  {
99  if($node["type"] == "cat")
100  {
101  $node_valid = array();
102 
104  $node["obj_id"],
106  false
107  ))
108  {
109  $all_valid = array_merge($all_valid,
110  ilObjTaxonomy::getUsageOfObject($node["obj_id"]));
111 
112  $active = array();
113  foreach(ilContainer::_getContainerSettings($node["obj_id"]) as $keyword => $value)
114  {
115  if(substr($keyword, 0, strlen($prefix)) == $prefix && (bool)$value)
116  {
117  $active[] = substr($keyword, strlen($prefix));
118  }
119  }
120 
121  $node_valid = array_intersect($all_valid, $active);
122  }
123 
124  if(sizeof($node_valid))
125  {
126  foreach($node_valid as $idx => $node_id)
127  {
128  // #15268 - deleted taxonomy?
129  if(ilObject::_lookupType($node_id) != "tax")
130  {
131  unset($node_valid[$idx]);
132  }
133  }
134  }
135 
136  self::$valid_tax_map[$node["ref_id"]] = $node_valid;
137  }
138  }
139  }
140 
141  return sizeof(self::$valid_tax_map[$a_parent_ref_id]);
142  }
143 
144  public function getFilteredObjects()
145  {
146  include_once "Services/Taxonomy/classes/class.ilTaxonomyTree.php";
147  include_once "Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
148  include_once "Services/Taxonomy/classes/class.ilTaxonomyNode.php";
149 
150  $tax_obj_ids = $tax_map = array();
151 
152  // :TODO: this could be smarter
153  foreach($this->selection as $node_id)
154  {
155  $node = new ilTaxonomyNode($node_id);
156  $tax_map[$node->getTaxonomyId()][] = $node_id;
157  }
158 
159  foreach($tax_map as $tax_id => $node_ids)
160  {
161  $tax_tree = new ilTaxonomyTree($tax_id);
162 
163  // combine taxonomy nodes OR
164  $tax_nodes = array();
165  foreach($node_ids as $node_id)
166  {
167  $tax_nodes = array_merge($tax_nodes, $tax_tree->getSubTreeIds($node_id));
168  $tax_nodes[] = $node_id;
169  }
170 
171  $tax_obj_ids[$tax_id] = ilTaxNodeAssignment::findObjectsByNode($tax_id, $tax_nodes, "obj");
172  }
173 
174  // combine taxonomies AND
175  $obj_ids = null;
176  foreach($tax_obj_ids as $tax_objs)
177  {
178  if($obj_ids === null)
179  {
180  $obj_ids = $tax_objs;
181  }
182  else
183  {
184  $obj_ids = array_intersect($obj_ids, $tax_objs);
185  }
186  }
187 
188  return (array)$obj_ids;
189  }
190 }