ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTaxMDGUI.php
Go to the documentation of this file.
1<?php
2
19use Psr\Http\Message\RequestInterface;
20
28{
30 protected ilTree $tree;
31 protected int $md_rbac_id;
32 protected int $md_obj_id;
33 protected string $md_obj_type;
34 protected string $requested_post_var;
35 protected RequestInterface $request;
36 protected ilCtrl $ctrl;
38 protected ilLanguage $lng;
39 protected ilTabsGUI $tabs;
40 protected int $ref_id;
41
45 public function __construct(
46 int $a_md_rbac_id,
47 int $a_md_obj_id,
48 string $a_md_obj_type,
49 int $a_ref_id
50 ) {
51 global $DIC;
52
53 $this->obj_definition = $DIC["objDefinition"];
54 $this->tree = $DIC->repositoryTree();
55
56
57 $this->tabs = $DIC->tabs();
58 $this->ctrl = $DIC->ctrl();
59 $this->lng = $DIC->language();
60 $this->tpl = $DIC->ui()->mainTemplate();
61
62 // @todo introduce request wrapper
63 $this->request = $DIC->http()->request();
64
65 $this->md_rbac_id = $a_md_rbac_id;
66 $this->md_obj_id = $a_md_obj_id;
67 $this->md_obj_type = $a_md_obj_type;
68 $this->ref_id = $a_ref_id;
69
70 $params = $this->request->getQueryParams();
71 $this->requested_post_var = $params["postvar"] ?? "";
72 }
73
79 public function executeCommand()
80 {
81 $next_class = $this->ctrl->getNextClass($this);
82 $cmd = $this->ctrl->getCmd("show");
83
84 if ($next_class == 'ilformpropertydispatchgui') {
85 $form = $this->initForm();
86 $form_prop_dispatch = new ilFormPropertyDispatchGUI();
87 $item = $form->getItemByPostVar($this->requested_post_var);
88 $form_prop_dispatch->setItem($item);
89 return $this->ctrl->forwardCommand($form_prop_dispatch);
90 } elseif (in_array($cmd, array("show", "save"))) {
91 $this->$cmd();
92 }
93 return "";
94 }
95
96 public function show(): void
97 {
99 $form = $this->initForm();
100 $tpl->setContent($form->getHTML());
101 }
102
103 public function save(): void
104 {
107
108 $form = $this->initForm();
109 if ($form->checkInput()) {
110 $this->updateFromMDForm();
111 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
112 $ctrl->redirect($this, "show");
113 } else {
114 $form->setValuesByPost();
115 $tpl->setContent($form->getHTML());
116 }
117 }
118
122 public function initForm(): ilPropertyFormGUI
123 {
124 $form = new ilPropertyFormGUI();
125
126 $this->addToMDForm($form);
127 $form->addCommandButton("save", $this->lng->txt("save"));
128 $form->setTitle($this->lng->txt("tax_tax_assignment"));
129 $form->setFormAction($this->ctrl->getFormAction($this));
130
131 return $form;
132 }
133
134 // Get selectable taxonomies for current object
135 public function getSelectableTaxonomies(): array
136 {
137 $objDefinition = $this->obj_definition;
139
140 $res = [];
141 if ($this->ref_id > 0 && $objDefinition->isRBACObject($this->md_obj_type)) {
142 // get all active taxonomies of parent objects
143 foreach ($tree->getPathFull($this->ref_id) as $node) {
144 // currently only active for categories
145 if ((int) $node["ref_id"] != $this->ref_id && $node["type"] == "cat") {
147 (int) $node["obj_id"],
149 false
150 ) !== ''
151 ) {
152 $tax_ids = ilObjTaxonomy::getUsageOfObject((int) $node["obj_id"]);
153 if (count($tax_ids) !== 0) {
154 $res = array_merge($res, $tax_ids);
155 }
156 }
157 }
158 }
159 }
160 return $res;
161 }
162
166 protected function initTaxNodeAssignment(int $a_tax_id): ilTaxNodeAssignment
167 {
168 return new ilTaxNodeAssignment($this->md_obj_type, $this->md_obj_id, "obj", $a_tax_id);
169 }
170
174 public function addToMDForm(ilPropertyFormGUI $a_form): void
175 {
176 $tax_ids = $this->getSelectableTaxonomies();
177 if (is_array($tax_ids)) {
178 foreach ($tax_ids as $tax_id) {
179 // get existing assignments
180 $node_ids = array();
181 $ta = $this->initTaxNodeAssignment((int) $tax_id);
182 foreach ($ta->getAssignmentsOfItem($this->md_obj_id) as $ass) {
183 $node_ids[] = $ass["node_id"];
184 }
185
186 $tax_sel = new ilTaxSelectInputGUI($tax_id, "md_tax_" . $tax_id, true);
187 $tax_sel->setValue($node_ids);
188 $a_form->addItem($tax_sel);
189 }
190 }
191 }
192
196 public function updateFromMDForm(): void
197 {
198 $body = $this->request->getParsedBody();
199 $tax_ids = $this->getSelectableTaxonomies();
200 if (is_array($tax_ids)) {
201 foreach ($tax_ids as $tax_id) {
202 $ta = $this->initTaxNodeAssignment($tax_id);
203
204 // delete existing assignments
205 $ta->deleteAssignmentsOfItem($this->md_obj_id);
206
207 // set current assignment
208 if (isset($body["md_tax_" . $tax_id])) {
209 foreach ($body["md_tax_" . $tax_id] as $node_id) {
210 $ta->addAssignment($node_id, $this->md_obj_id);
211 }
212 }
213 }
214 }
215 }
216
220 public function addSubTab(): void
221 {
225
226 $tax_ids = $this->getSelectableTaxonomies();
227 if (is_array($tax_ids)) {
229 "tax_assignment",
230 $lng->txt("tax_tax_assignment"),
231 $ctrl->getLinkTarget($this, "")
232 );
233 }
234 }
235}
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
Class ilCtrl provides processing control methods.
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
language handling
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...
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
parses the objects.xml it handles the xml-description of all ilias objects
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addSubTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
Taxonomies selection for metadata helper GUI.
ilObjectDefinition $obj_definition
string $requested_post_var
initTaxNodeAssignment(int $a_tax_id)
ilLanguage $lng
string $md_obj_type
ilTabsGUI $tabs
__construct(int $a_md_rbac_id, int $a_md_obj_id, string $a_md_obj_type, int $a_ref_id)
Constructor.
addSubTab()
addSubTab
ilGlobalTemplateInterface $tpl
addToMDForm(ilPropertyFormGUI $a_form)
Add taxonomy selector to MD (quick edit) form.
updateFromMDForm()
Import settings from MD (quick edit) form.
RequestInterface $request
initForm()
Init taxonomy form.
executeCommand()
Execute command.
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...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
getPathFull(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
setContent(string $a_html)
Sets content for standard template.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26