ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $tax_exp = new ilTaxonomyExplorerGUI($a_parent_gui, null, $tax_id, null, null);
31  $tax_exp->setSkipRootNode(true);
32  $tax_exp->setOnClick("il.Classification.toggle({tax_node: '{NODE_CHILD}'});");
33 
34  if (is_array($this->selection)) {
35  foreach ($this->selection as $node_id) {
36  $tax_exp->setPathOpen($node_id);
37  $tax_exp->setNodeSelected($node_id);
38  }
39  }
40 
41  if (!$tax_exp->handleCommand()) {
42  $a_html[] = array(
43  "title" => ilObject::_lookupTitle($tax_id),
44  "html" => $tax_exp->getHTML()
45  );
46  }
47  }
48  }
49 
50  public function importPostData($a_saved = null)
51  {
52  $incoming_id = (int) $_REQUEST["tax_node"];
53  if ($incoming_id) {
54  if (is_array($a_saved)) {
55  foreach ($a_saved as $idx => $node_id) {
56  if ($node_id == $incoming_id) {
57  unset($a_saved[$idx]);
58  return $a_saved;
59  }
60  }
61  $a_saved[] = $incoming_id;
62  return $a_saved;
63  } else {
64  return array($incoming_id);
65  }
66  }
67  }
68 
69  public function setSelection($a_value)
70  {
71  $this->selection = $a_value;
72  }
73 
74  protected static function getActiveTaxonomiesForParentRefId($a_parent_ref_id)
75  {
76  global $DIC;
77 
78  $tree = $DIC->repositoryTree();
79 
80  if (!isset(self::$valid_tax_map[$a_parent_ref_id])) {
81  include_once "Services/Object/classes/class.ilObjectServiceSettingsGUI.php";
82  include_once "Services/Taxonomy/classes/class.ilObjTaxonomy.php";
83  include_once "Modules/Category/classes/class.ilObjCategoryGUI.php";
84 
86 
87  $all_valid = array();
88  foreach ($tree->getPathFull($a_parent_ref_id) as $node) {
89  if ($node["type"] == "cat") {
90  $node_valid = array();
91 
93  $node["obj_id"],
95  false
96  )) {
97  $all_valid = array_merge(
98  $all_valid,
99  ilObjTaxonomy::getUsageOfObject($node["obj_id"])
100  );
101 
102  $active = array();
103  foreach (ilContainer::_getContainerSettings($node["obj_id"]) as $keyword => $value) {
104  if (substr($keyword, 0, strlen($prefix)) == $prefix && (bool) $value) {
105  $active[] = substr($keyword, strlen($prefix));
106  }
107  }
108 
109  $node_valid = array_intersect($all_valid, $active);
110  }
111 
112  if (sizeof($node_valid)) {
113  foreach ($node_valid as $idx => $node_id) {
114  // #15268 - deleted taxonomy?
115  if (ilObject::_lookupType($node_id) != "tax") {
116  unset($node_valid[$idx]);
117  }
118  }
119  }
120 
121  self::$valid_tax_map[$node["ref_id"]] = $node_valid;
122  }
123  }
124  }
125 
126  if (is_array(self::$valid_tax_map[$a_parent_ref_id])) {
127  return sizeof(self::$valid_tax_map[$a_parent_ref_id]);
128  }
129 
130  return 0;
131  }
132 
133  public function getFilteredObjects()
134  {
135  include_once "Services/Taxonomy/classes/class.ilTaxonomyTree.php";
136  include_once "Services/Taxonomy/classes/class.ilTaxNodeAssignment.php";
137  include_once "Services/Taxonomy/classes/class.ilTaxonomyNode.php";
138 
139  $tax_obj_ids = $tax_map = array();
140 
141  // :TODO: this could be smarter
142  foreach ($this->selection as $node_id) {
143  $node = new ilTaxonomyNode($node_id);
144  $tax_map[$node->getTaxonomyId()][] = $node_id;
145  }
146 
147  foreach ($tax_map as $tax_id => $node_ids) {
148  $tax_tree = new ilTaxonomyTree($tax_id);
149 
150  // combine taxonomy nodes OR
151  $tax_nodes = array();
152  foreach ($node_ids as $node_id) {
153  $tax_nodes = array_merge($tax_nodes, $tax_tree->getSubTreeIds($node_id));
154  $tax_nodes[] = $node_id;
155  }
156 
157  $tax_obj_ids[$tax_id] = ilTaxNodeAssignment::findObjectsByNode($tax_id, $tax_nodes, "obj");
158  }
159 
160  // combine taxonomies AND
161  $obj_ids = null;
162  foreach ($tax_obj_ids as $tax_objs) {
163  if ($obj_ids === null) {
164  $obj_ids = $tax_objs;
165  } else {
166  $obj_ids = array_intersect($obj_ids, $tax_objs);
167  }
168  }
169 
170  return (array) $obj_ids;
171  }
172 }
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
global $DIC
Definition: saml.php:7
Taxonomy explorer GUI class.
static _lookupTitle($a_id)
lookup object title
static findObjectsByNode($a_tax_id, array $a_node_ids, $a_item_type)
Find object which have assigned nodes.
static isActive($a_parent_ref_id, $a_parent_obj_id, $a_parent_obj_type)
static _getContainerSettings($a_id)
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.