ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilOrgUnitDefaultPermissionFormGUI.php
Go to the documentation of this file.
1 <?php
20 
26 {
27  public const F_OPERATIONS = 'operations';
30  protected array $ilOrgUnitPermissions = [];
32  protected \ilLanguage $language;
33 
40  public function __construct(
41  BaseCommands $parent_gui,
42  array $ilOrgUnitPermissionsFilter,
43  ilObjectDefinition $objectDefinition
44  ) {
45  global $DIC;
46  $this->parent_gui = $parent_gui;
47  $this->language = $DIC->language();
48  $this->ilOrgUnitPermissions = $ilOrgUnitPermissionsFilter;
49  $this->dic()->ctrl()->saveParameter($parent_gui, 'arid');
50  $this->setFormAction($this->dic()->ctrl()->getFormAction($this->parent_gui));
52  $this->initFormElements();
53  $this->initButtons();
54  $this->setTarget('_top');
56  }
57 
58  public function saveObject(): bool
59  {
60  if ($this->fillObject() === false) {
61  return false;
62  }
63  foreach ($this->ilOrgUnitPermissions as $ilOrgUnitPermission) {
64  $ilOrgUnitPermission->update();
65  }
66 
67  return true;
68  }
69 
70  private function initButtons(): void
71  {
72  $this->setTitle($this->txt("form_title_org_default_permissions_"
73  . BaseCommands::CMD_UPDATE));
74  $this->addCommandButton(BaseCommands::CMD_UPDATE, $this->txt('save', true));
75  $this->addCommandButton(BaseCommands::CMD_CANCEL, $this->txt(BaseCommands::CMD_CANCEL));
76  }
77 
78  private function initFormElements(): void
79  {
80  foreach ($this->ilOrgUnitPermissions as $ilOrgUnitPermission) {
81  $ilOrgUnitPermission->afterObjectLoad();
82  if ($ilOrgUnitPermission->getContext() !== null) {
83  $header = new ilFormSectionHeaderGUI();
84  $context = $ilOrgUnitPermission->getContext()->getContext();
85  $header->setTitle($this->getTitleForFormHeaderByContext($context));
86  $this->addItem($header);
87  }
88 
89 
90 
91  // Checkboxes
92  foreach ($ilOrgUnitPermission->getPossibleOperations() as $operation) {
93  $title = $this->txt("org_op_{$operation->getOperationString()}");
94  $id = $operation->getOperationId();
95  $cb = new ilCheckboxInputGUI($title, "operations[{$context}][{$id}]");
96  $this->addItem($cb);
97  }
98  }
99  }
100 
101  public function fillForm(): void
102  {
103  $operations = array();
104  foreach ($this->ilOrgUnitPermissions as $ilOrgUnitPermission) {
105  $ilOrgUnitPermission->afterObjectLoad();
106  if ($ilOrgUnitPermission->getContext() !== null) {
107  $context = $ilOrgUnitPermission->getContext()->getContext();
108  foreach ($ilOrgUnitPermission->getPossibleOperations() as $operation) {
109  $id = $operation->getOperationId();
110  $operations["operations[{$context}][{$id}]"] = $ilOrgUnitPermission->isOperationIdSelected($operation->getOperationId());
111  }
112  }
113  }
114  $this->setValuesByArray($operations);
115  }
116 
117  private function fillObject(): bool
118  {
119  if (!$this->checkInput()) {
120  return false;
121  }
122  $sent_operation_ids = ($this->getInput(self::F_OPERATIONS) != '') ? $this->getInput(self::F_OPERATIONS) : [];
123  foreach ($this->ilOrgUnitPermissions as $ilOrgUnitPermission) {
124  $operations = [];
125  $ilOrgUnitPermission->afterObjectLoad();
126  if ($ilOrgUnitPermission->getContext()) {
127  $context = $ilOrgUnitPermission->getContext()->getContext();
128  foreach ($ilOrgUnitPermission->getPossibleOperations() as $operation) {
129  $id = $operation->getOperationId();
130  if (isset($sent_operation_ids[$context][$id])) {
131  $operations[] = ilOrgUnitOperation::find($id);
132  }
133  }
134  $ilOrgUnitPermission->setOperations($operations);
135  }
136  }
137 
138  return true;
139  }
140 
144  public function getIlOrgUnitPermissions(): array
145  {
147  }
148 
152  public function setIlOrgUnitPermissions(array $ilOrgUnitPermissions): void
153  {
154  $this->ilOrgUnitPermissions = $ilOrgUnitPermissions;
155  }
156 
157  private function dic(): \ILIAS\DI\Container
158  {
159  return $GLOBALS["DIC"];
160  }
161 
162  private function txt(string $key): string
163  {
164  return $this->language->txt($key);
165  }
166 
167  protected function getTitleForFormHeaderByContext(string $context)
168  {
169  $lang_code = "obj_{$context}";
170  if ($this->objectDefinition->isPlugin($context)) {
171  return ilObjectPlugin::lookupTxtById($context, $lang_code);
172  }
173 
174  return $this->txt($lang_code);
175  }
176 }
$context
Definition: webdav.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider .
setTarget(string $a_target)
This class represents a checkbox property in a property form.
Class ilOrgUnitDefaultPermissionFormGUI.
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-...
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
setFormAction(string $a_formaction)
__construct(BaseCommands $parent_gui, array $ilOrgUnitPermissionsFilter, ilObjectDefinition $objectDefinition)
ilOrgUnitDefaultPermissionFormGUI constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class HTTPServicesTest.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
string $key
Consumer key/client ID value.
Definition: System.php:193
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
static lookupTxtById(string $plugin_id, string $lang_var)
__construct(Container $dic, ilPlugin $plugin)