ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTaxAssignInputGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected bool $include_please_select;
26 protected int $taxononmy_id;
27
28 public function __construct(
29 int $a_taxonomy_id,
30 bool $a_multi = true,
31 string $a_title = "",
32 string $a_postvar = "",
33 bool $a_include_please_select = true
34 ) {
35 global $DIC;
36
37 $this->lng = $DIC->language();
38 $lng = $DIC->language();
39
41 $this->setMulti($a_multi);
42 $this->include_please_select = $a_include_please_select;
43
44 if ($a_title == "") {
45 $a_title = $lng->txt("tax_taxonomy");
46 }
47
48 if ($a_postvar == "") {
49 $a_postvar = "tax_node_assign";
50 }
51
52 parent::__construct($a_title, $a_postvar);
53 $this->setType("tax_assign");
54
55 if ((int) $a_taxonomy_id == 0) {
56 throw new ilTaxonomyException("No taxonomy ID passed to ilTaxAssignInputGUI.");
57 }
58
59 $this->setTaxonomyId((int) $a_taxonomy_id);
60 }
61
66 public function setTaxonomyId(int $a_val): void
67 {
68 $this->taxononmy_id = $a_val;
69 }
70
75 public function getTaxonomyId(): int
76 {
78 }
79
84 public function setOptions($a_options): void
85 {
86 throw new ilTaxonomyException("setOptions: Not supported for ilTaxAssignInputGUI.");
87 }
88
93 public function getOptions(): array
94 {
96
97 $options = [];
98 if ($this->include_please_select) {
99 $options = array("" => $lng->txt("please_select"));
100 }
101
102 $tax_tree = new ilTaxonomyTree($this->getTaxonomyId());
103
104 $nodes = $tax_tree->getSubTree($tax_tree->getNodeData($tax_tree->readRootId()));
105 foreach ($nodes as $n) {
106 if ($n["type"] == "taxn") {
107 $options[$n["child"]] = str_repeat("&nbsp;", ($n["depth"] - 2) * 2) . $n["title"];
108 }
109 }
110
111 return $options;
112 }
113
118 public function saveInput(
119 string $a_component_id,
120 int $a_obj_id,
121 string $a_item_type,
122 int $a_item_id
123 ): void {
124 $tax_node_ass = new ilTaxNodeAssignment($a_component_id, $a_obj_id, $a_item_type, $this->getTaxonomyId());
125
126 $body = $this->request->getParsedBody();
127 $post = $body[$this->getPostVar()] ?? "";
128
129 if (!$this->getMulti()) {
130 $post = array($post);
131 } elseif (!is_array($post)) {
132 // BH: when multi values are ENABLED and $form->checkInput is NOT called
133 // there is no post parameter available WHEN the selection is left empty
134 // - fixed mantis #22186 - the followup issue
135 $post = array();
136 }
137
138 $current_ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
139 $exising = array();
140 foreach ($current_ass as $ca) {
141 if (!in_array($ca["node_id"], $post)) {
142 $tax_node_ass->deleteAssignment((int) $ca["node_id"], $a_item_id);
143 } else {
144 $exising[] = (int) $ca["node_id"];
145 }
146 }
147
148 foreach ($post as $p) {
149 if (!in_array((int) $p, $exising)) {
150 $tax_node_ass->addAssignment((int) $p, $a_item_id);
151 }
152 }
153 }
154
159 public function setCurrentValues(
160 string $a_component_id,
161 int $a_obj_id,
162 string $a_item_type,
163 int $a_item_id
164 ): void {
165 $tax_node_ass = new ilTaxNodeAssignment($a_component_id, $a_obj_id, $a_item_type, $this->getTaxonomyId());
166 $ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
167
168 $nodes = array();
169 foreach ($ass as $a) {
170 $nodes[] = $a["node_id"];
171 }
172 if ($this->getMulti()) {
173 $this->setValue($nodes);
174 } else {
175 $this->setValue($nodes[0]);
176 }
177 }
178}
setMulti(bool $a_multi, bool $a_sortable=false, bool $a_addremove=true)
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(int $a_taxonomy_id, bool $a_multi=true, string $a_title="", string $a_postvar="", bool $a_include_please_select=true)
setOptions($a_options)
Set Options.
setTaxonomyId(int $a_val)
Set taxonomy id.
saveInput(string $a_component_id, int $a_obj_id, string $a_item_type, int $a_item_id)
Save input.
setCurrentValues(string $a_component_id, int $a_obj_id, string $a_item_type, int $a_item_id)
Set current values.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAssignmentsOfItem(int $a_item_id)
Get assignments for item.
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...
$post
Definition: ltitoken.php:46
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26