ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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["taxNode"] ?? ($params["taxNode"] ?? 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 $id_and_title = array_map(static function (int $id) {
136 return [
137 "id" => $id,
138 "title" => ilObject::_lookupTitle($id)
139 ];
140 }, $node_valid);
141 $id_and_title = ilArrayUtil::sortArray($id_and_title, "title");
142 $sorted_ids = array_map(static function (array $id_and_title) {
143 return (int) $id_and_title["id"];
144 }, $id_and_title);
145 self::$valid_tax_map[$node["ref_id"]] = $sorted_ids;
146 }
147 }
148 }
149
150 if (isset(self::$valid_tax_map[$a_parent_ref_id]) && is_array(self::$valid_tax_map[$a_parent_ref_id])) {
151 return count(self::$valid_tax_map[$a_parent_ref_id]);
152 }
153
154 return 0;
155 }
156
157 public function getFilteredObjects(): array
158 {
159 $tax_obj_ids = array();
160 $tax_map = array();
161
162 // :TODO: this could be smarter
163 foreach ($this->selection as $node_id) {
164 $node = new ilTaxonomyNode((int) $node_id);
165 $tax_map[$node->getTaxonomyId()][] = (int) $node_id;
166 }
167
168 foreach ($tax_map as $tax_id => $node_ids) {
169 $tax_tree = new ilTaxonomyTree((int) $tax_id);
170
171 // combine taxonomy nodes AND
172 foreach ($node_ids as $node_id) {
173 $tax_nodes = array();
174 $tax_nodes = array_merge($tax_nodes, $tax_tree->getSubTreeIds((int) $node_id));
175 $tax_nodes[] = (int) $node_id;
176 if (!isset($tax_obj_ids[$tax_id])) {
177 $tax_obj_ids[$tax_id] = ilTaxNodeAssignment::findObjectsByNode((int) $tax_id, $tax_nodes, "obj");
178 } else {
179 $tax_obj_ids[$tax_id] = array_intersect(
180 $tax_obj_ids[$tax_id],
181 ilTaxNodeAssignment::findObjectsByNode((int) $tax_id, $tax_nodes, "obj")
182 );
183 }
184 }
185 }
186
187 // combine taxonomies AND
188 $obj_ids = null;
189 foreach ($tax_obj_ids as $tax_objs) {
190 $obj_ids = $obj_ids === null ? $tax_objs : array_intersect($obj_ids, $tax_objs);
191 }
192
193 return (array) $obj_ids;
194 }
195}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static _getContainerSettings(int $a_id)
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
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...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
global $DIC
Definition: shib_login.php:26