ILIAS  release_8 Revision v8.24
class.ilTaxonomyClassificationProvider.php
Go to the documentation of this file.
1<?php
2
24{
25 protected array $selection = [];
26 protected static array $valid_tax_map = [];
27 protected int $incoming_id = 0;
28
29 public static function isActive(int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type): bool
30 {
31 return (bool) self::getActiveTaxonomiesForParentRefId($a_parent_ref_id);
32 }
33
34 protected function init(): void
35 {
36 $params = $this->request->getQueryParams();
37 $body = $this->request->getParsedBody();
38 $this->incoming_id = (int) ($body["tax_node"] ?? ($params["tax_node"] ?? null));
39 }
40
41 public function render(array &$a_html, object $a_parent_gui): void
42 {
43 foreach (self::$valid_tax_map[$this->parent_ref_id] as $tax_id) {
44 $tax_exp = new ilTaxonomyClassificationExplorerGUI($a_parent_gui, "", (int) $tax_id, "", "");
45 $tax_exp->setSkipRootNode(true);
46 $tax_exp->setOnClick("il.Classification.toggle({tax_node: '{NODE_CHILD}'});");
47
48 if (isset($this->selection) && is_array($this->selection)) {
49 foreach ($this->selection as $node_id) {
50 $tax_exp->setPathOpen($node_id);
51 $tax_exp->setNodeSelected($node_id);
52 }
53 }
54
55 if (!$tax_exp->handleCommand()) {
56 $a_html[] = array(
57 "title" => ilObject::_lookupTitle((int) $tax_id),
58 "html" => $tax_exp->getHTML(true)
59 );
60 }
61 }
62 }
63
64 public function importPostData(?array $a_saved = null): array
65 {
67 if ($incoming_id !== 0) {
68 if (is_array($a_saved)) {
69 foreach ($a_saved as $idx => $node_id) {
70 if ($node_id == $incoming_id) {
71 unset($a_saved[$idx]);
72 return $a_saved;
73 }
74 }
75 $a_saved[] = $incoming_id;
76 return $a_saved;
77 } else {
78 return array($incoming_id);
79 }
80 }
81 return [];
82 }
83
87 public function setSelection(array $a_value): void
88 {
89 $this->selection = $a_value;
90 }
91
92 protected static function getActiveTaxonomiesForParentRefId(int $a_parent_ref_id): int
93 {
94 global $DIC;
95
96 $tree = $DIC->repositoryTree();
97
98 if (!isset(self::$valid_tax_map[$a_parent_ref_id])) {
100
101 $all_valid = array();
102 foreach ($tree->getPathFull($a_parent_ref_id) as $node) {
103 if ($node["type"] == "cat") {
104 $node_valid = array();
105
107 (int) $node["obj_id"],
109 false
110 ) !== '') {
111 $all_valid = array_merge(
112 $all_valid,
113 ilObjTaxonomy::getUsageOfObject((int) $node["obj_id"])
114 );
115
116 $active = array();
117 foreach (ilContainer::_getContainerSettings((int) $node["obj_id"]) as $keyword => $value) {
118 if (substr($keyword, 0, strlen($prefix)) == $prefix && (bool) $value) {
119 $active[] = substr($keyword, strlen($prefix));
120 }
121 }
122
123 $node_valid = array_intersect($all_valid, $active);
124 }
125
126 if (count($node_valid) !== 0) {
127 foreach ($node_valid as $idx => $node_id) {
128 // #15268 - deleted taxonomy?
129 if (ilObject::_lookupType((int) $node_id) != "tax") {
130 unset($node_valid[$idx]);
131 }
132 }
133 }
134
135 self::$valid_tax_map[$node["ref_id"]] = $node_valid;
136 }
137 }
138 }
139
140 if (isset(self::$valid_tax_map[$a_parent_ref_id]) && is_array(self::$valid_tax_map[$a_parent_ref_id])) {
141 return count(self::$valid_tax_map[$a_parent_ref_id]);
142 }
143
144 return 0;
145 }
146
147 public function getFilteredObjects(): array
148 {
149 $tax_obj_ids = array();
150 $tax_map = array();
151
152 // :TODO: this could be smarter
153 foreach ($this->selection as $node_id) {
154 $node = new ilTaxonomyNode((int) $node_id);
155 $tax_map[$node->getTaxonomyId()][] = (int) $node_id;
156 }
157
158 foreach ($tax_map as $tax_id => $node_ids) {
159 $tax_tree = new ilTaxonomyTree((int) $tax_id);
160
161 // combine taxonomy nodes OR
162 $tax_nodes = array();
163 foreach ($node_ids as $node_id) {
164 $tax_nodes = array_merge($tax_nodes, $tax_tree->getSubTreeIds((int) $node_id));
165 $tax_nodes[] = (int) $node_id;
166 }
167 $tax_obj_ids[$tax_id] = ilTaxNodeAssignment::findObjectsByNode((int) $tax_id, $tax_nodes, "obj");
168 }
169
170 // combine taxonomies AND
171 $obj_ids = null;
172 foreach ($tax_obj_ids as $tax_objs) {
173 $obj_ids = $obj_ids === null ? $tax_objs : array_intersect($obj_ids, $tax_objs);
174 }
175
176 return (array) $obj_ids;
177 }
178}
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
static _getContainerSettings(int $a_id)
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
static findObjectsByNode(int $a_tax_id, array $a_node_ids, string $a_item_type)
Find object which have assigned nodes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static isActive(int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
Is provider currently active?
render(array &$a_html, object $a_parent_gui)
Render HTML chunks.
static getActiveTaxonomiesForParentRefId(int $a_parent_ref_id)
importPostData(?array $a_saved=null)
Import post data.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33