ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjOrgUnitSettingsFormGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
28 
29  public function __construct(ilObjectGUI $parent_gui, ilObjOrgUnit $obj_orgu)
30  {
31  global $DIC;
32 
34  $tpl = $DIC['tpl'];
35  $ilCtrl = $DIC['ilCtrl'];
36  $lng = $DIC['lng'];
37  $ilUser = $DIC['ilUser'];
38  $this->parent_gui = $parent_gui;
39  $this->obj_orgu = $obj_orgu;
40 
41  //$this->tpl = $tpl;
42  $this->ctrl = $ilCtrl;
43  $this->lng = $lng;
44  $this->user = $ilUser;
45  $this->initForm();
46  }
47 
52  public function saveObject()
53  {
54  if (!$this->fillObject()) {
55  return false;
56  }
57  $this->obj_orgu->update();
58  $this->updateTranslation();
59 
60  return true;
61  }
62 
66  private function initForm(): void
67  {
68  $this->setFormAction($this->ctrl->getFormAction($this->parent_gui));
69  $this->setTitle($this->lng->txt('orgu_settings'));
70 
71  $item = new ilTextInputGUI($this->lng->txt('title'), 'title');
72  $item->setRequired(true);
73  $item->setValue($this->obj_orgu->getTitle());
74  $this->addItem($item);
75 
76  $item = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
77  $item->setValue($this->obj_orgu->getDescription());
78  $this->addItem($item);
79 
80  $item = new ilFormSectionHeaderGUI();
81  $item->setTitle($this->lng->txt('orgu_type'));
82  $this->addItem($item);
83  $types = ilOrgUnitType::getAllTypes();
84  $options = array(0 => '');
86  foreach ($types as $type) {
87  $options[$type->getId()] = $type->getTitle();
88  }
89  asort($options);
90  $item = new ilSelectInputGUI($this->lng->txt('orgu_type'), 'orgu_type');
91  $item->setOptions($options);
92  $item->setValue($this->obj_orgu->getOrgUnitTypeId());
93  $this->addItem($item);
94 
95  $item = new ilFormSectionHeaderGUI();
96  $item->setTitle($this->lng->txt('ext_id'));
97  $this->addItem($item);
98 
99  $item = new ilTextInputGUI($this->lng->txt('ext_id'), 'ext_id');
100  $item->setValue($this->obj_orgu->getImportId());
101  $this->addItem($item);
102 
103  $this->addCommandButton('updateSettings', $this->lng->txt('save'));
104  }
105 
110  private function fillObject(): bool
111  {
112  $this->setValuesByPost();
113  if (!$this->checkInput()) {
114  return false;
115  }
116  $this->obj_orgu->setOrgUnitTypeId($this->getInput('orgu_type'));
117  $this->obj_orgu->setImportId($this->getInput('ext_id'));
118  $this->obj_orgu->setTitle($this->getInput('title'));
119  $this->obj_orgu->setDescription($this->getInput('description'));
120 
121  return true;
122  }
123 
127  private function updateTranslation(): void
128  {
129  $translations = $this->obj_orgu->getTranslations();
130  $lang_code_default = '';
131  $lang_codes = array();
132  foreach ($translations as $translation) {
133  if ($translation['default']) {
134  $lang_code_default = $translation['lang'];
135  }
136  $lang_codes[] = $translation['lang'];
137  }
138  $lang_code = (in_array($this->user->getLanguage(), $lang_codes, true)) ? $this->user->getLanguage() : $lang_code_default;
139  $this->obj_orgu->updateTranslation($this->getInput('title'), $this->getInput('description'), $lang_code, 0);
140  }
141 }
fillObject()
Check validity of form and pass values from form to object.
This class represents a selection list property in a property form.
setOptions(array $a_options)
updateTranslation()
Update title and description for the default language of translation.
static getAllTypes()
Get array of all instances of ilOrgUnitType objects.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
setFormAction(string $a_formaction)
Class ilObjectGUI Basic methods of all Output classes.
__construct(ilObjectGUI $parent_gui, ilObjOrgUnit $obj_orgu)
global $DIC
Definition: shib_login.php:25
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...