ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTaxMDGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
16  protected $obj_definition;
17 
21  protected $tree;
22 
23  protected $md_rbac_id; // [int]
24  protected $md_obj_id; // [int]
25  protected $md_obj_type; // [string]
26 
27 
36  public function __construct($a_md_rbac_id, $a_md_obj_id, $a_md_obj_type, $a_ref_id)
37  {
38  global $DIC;
39 
40  $this->obj_definition = $DIC["objDefinition"];
41  $this->tree = $DIC->repositoryTree();
42 
43 
44  $this->tabs = $DIC->tabs();
45  $this->ctrl = $DIC->ctrl();
46  $this->lng = $DIC->language();
47  $this->tpl = $DIC["tpl"];
48 
49  $this->md_rbac_id = $a_md_rbac_id;
50  $this->md_obj_id = $a_md_obj_id;
51  $this->md_obj_type = $a_md_obj_type;
52  $this->ref_id = $a_ref_id;
53  }
54 
58  public function executeCommand()
59  {
60  $next_class = $this->ctrl->getNextClass($this);
61  $cmd = $this->ctrl->getCmd("show");
62 
63  switch ($next_class) {
64  case 'ilformpropertydispatchgui':
65  $form = $this->initForm();
66  include_once './Services/Form/classes/class.ilFormPropertyDispatchGUI.php';
67  $form_prop_dispatch = new ilFormPropertyDispatchGUI();
68  $item = $form->getItemByPostVar($_GET["postvar"]);
69  $form_prop_dispatch->setItem($item);
70  return $this->ctrl->forwardCommand($form_prop_dispatch);
71 
72  default:
73  if (in_array($cmd, array("show", "save"))) {
74  $this->$cmd();
75  }
76  }
77  }
78 
85  public function show()
86  {
87  $tpl = $this->tpl;
88 
89  $form = $this->initForm();
90  $tpl->setContent($form->getHTML());
91  }
92 
96  public function save()
97  {
98  $tpl = $this->tpl;
99  $ctrl = $this->ctrl;
100 
101  $form = $this->initForm();
102  if ($form->checkInput()) {
103  $this->updateFromMDForm();
104  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
105  $ctrl->redirect($this, "show");
106  } else {
107  $form->setValuesByPost();
108  $tpl->setContent($form->getHtml());
109  }
110  }
111 
115  public function initForm()
116  {
117  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
118  $form = new ilPropertyFormGUI();
119 
120  $this->addToMDForm($form);
121 
122  $form->addCommandButton("save", $this->lng->txt("save"));
123 
124 
125  $form->setTitle($this->lng->txt("tax_tax_assignment"));
126  $form->setFormAction($this->ctrl->getFormAction($this));
127 
128  return $form;
129  }
130 
136  public function getSelectableTaxonomies()
137  {
138  $objDefinition = $this->obj_definition;
139  $tree = $this->tree;
140 
141  if ($this->ref_id > 0 && $objDefinition->isRBACObject($this->md_obj_type)) {
142  $res = array();
143 
144  // see ilTaxonomyBlockGUI::getActiveTaxonomies()
145 
146  // get all active taxonomies of parent objects
147  foreach ($tree->getPathFull((int) $this->ref_id) as $node) {
148  if ($node["ref_id"] != (int) $this->ref_id) {
149  // currently only active for categories
150  if ($node["type"] == "cat") {
151  include_once "Services/Object/classes/class.ilObjectServiceSettingsGUI.php";
152  include_once "Services/Container/classes/class.ilContainer.php";
154  $node["obj_id"],
156  false
157  )
158  ) {
159  include_once "Services/Taxonomy/classes/class.ilObjTaxonomy.php";
160  $tax_ids = ilObjTaxonomy::getUsageOfObject($node["obj_id"]);
161  if (sizeof($tax_ids)) {
162  $res = array_merge($res, $tax_ids);
163  }
164  }
165  }
166  }
167  }
168 
169  if (sizeof($res)) {
170  return $res;
171  }
172  }
173  }
174 
181  protected function initTaxNodeAssignment($a_tax_id)
182  {
183  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
184  return new ilTaxNodeAssignment($this->md_obj_type, $this->md_obj_id, "obj", $a_tax_id);
185  }
186 
192  public function addToMDForm(ilPropertyFormGUI $a_form)
193  {
194  $tax_ids = $this->getSelectableTaxonomies();
195  if (is_array($tax_ids)) {
196  include_once "Services/Taxonomy/classes/class.ilTaxSelectInputGUI.php";
197  foreach ($tax_ids as $tax_id) {
198  // get existing assignments
199  $node_ids = array();
200  $ta = $this->initTaxNodeAssignment($tax_id);
201  foreach ($ta->getAssignmentsOfItem($this->md_obj_id) as $ass) {
202  $node_ids[] = $ass["node_id"];
203  }
204 
205  $tax_sel = new ilTaxSelectInputGUI($tax_id, "md_tax_" . $tax_id, true);
206  $tax_sel->setValue($node_ids);
207  $a_form->addItem($tax_sel);
208  }
209  }
210  }
211 
215  public function updateFromMDForm()
216  {
217  $tax_ids = $this->getSelectableTaxonomies();
218  if (is_array($tax_ids)) {
219  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
220 
221  foreach ($tax_ids as $tax_id) {
222  $ta = $this->initTaxNodeAssignment($tax_id);
223 
224  // delete existing assignments
225  $ta->deleteAssignmentsOfItem($this->md_obj_id);
226 
227  // set current assignment
228  if (is_array($_POST["md_tax_" . $tax_id])) {
229  foreach ($_POST["md_tax_" . $tax_id] as $node_id) {
230  $ta->addAssignment($node_id, $this->md_obj_id);
231  }
232  }
233  }
234  }
235  }
236 
243  public function addSubTab()
244  {
245  $tabs = $this->tabs;
246  $ctrl = $this->ctrl;
247  $lng = $this->lng;
248 
249  $tax_ids = $this->getSelectableTaxonomies();
250  if (is_array($tax_ids)) {
251  $tabs->addSubTab(
252  "tax_assignment",
253  $lng->txt("tax_tax_assignment"),
254  $ctrl->getLinkTarget($this, "")
255  );
256  }
257  }
258 }
Taxonomy node <-> item assignment.
Select taxonomy nodes input GUI.
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
save()
Save form.
$_GET["client_id"]
$tpl
Definition: ilias.php:10
addItem($a_item)
Add Item (Property, SectionHeader).
executeCommand()
Execute command.
addSubTab()
addSubTab
__construct($a_md_rbac_id, $a_md_obj_id, $a_md_obj_type, $a_ref_id)
Constructor.
initForm()
Init taxonomy form.
foreach($_POST as $key=> $value) $res
if(isset($_POST['submit'])) $form
Taxonomies selection for metadata helper GUI.
$lng
getSelectableTaxonomies()
Get selectable taxonomies for current object.
initTaxNodeAssignment($a_tax_id)
Init tax node assignment.
if(!empty($this->data['faventry'])) $tabs
Definition: disco.tpl.php:124
updateFromMDForm()
Import settings from MD (quick edit) form.
addToMDForm(ilPropertyFormGUI $a_form)
Add taxonomy selector to MD (quick edit) form.
$_POST["username"]
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.