ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilOrgUnitDefaultPermissionFormGUI.php
Go to the documentation of this file.
1 <?php
2 
4 
11 {
12  const F_OPERATIONS = 'operations';
16  protected $parent_gui;
20  protected $ilOrgUnitPermissions = [];
24  protected $objectDefinition;
25 
33  public function __construct(
35  array $ilOrgUnitPermissionsFilter,
37  ) {
38  $this->parent_gui = $parent_gui;
39  $this->ilOrgUnitPermissions = $ilOrgUnitPermissionsFilter;
40  $this->dic()->ctrl()->saveParameter($parent_gui, 'arid');
41  $this->setFormAction($this->dic()->ctrl()->getFormAction($this->parent_gui));
42  $this->objectDefinition = $objectDefinition;
43  $this->initFormElements();
44  $this->initButtons();
45  $this->setTarget('_top');
47  }
48 
49 
53  public function saveObject()
54  {
55  if (!$this->fillObject()) {
56  return false;
57  }
58  foreach ($this->ilOrgUnitPermissions as $ilOrgUnitPermission) {
59  $ilOrgUnitPermission->update();
60  }
61 
62  return true;
63  }
64 
65 
66  protected function initButtons()
67  {
68  $this->setTitle($this->txt("form_title_org_default_permissions_"
69  . BaseCommands::CMD_UPDATE));
70  $this->addCommandButton(BaseCommands::CMD_UPDATE, $this->txt('save', true));
71  $this->addCommandButton(BaseCommands::CMD_CANCEL, $this->txt(BaseCommands::CMD_CANCEL));
72  }
73 
74 
75  protected function initFormElements()
76  {
77  foreach ($this->ilOrgUnitPermissions as $ilOrgUnitPermission) {
78  $header = new ilFormSectionHeaderGUI();
79  $context = $ilOrgUnitPermission->getContext()->getContext();
80  $header->setTitle($this->getTitleForFormHeaderByContext($context));
81  $this->addItem($header);
82 
83  // Checkboxes
84  foreach ($ilOrgUnitPermission->getPossibleOperations() as $operation) {
85  $title = $this->txt("org_op_{$operation->getOperationString()}");
86  $id = $operation->getOperationId();
87  $cb = new ilCheckboxInputGUI($title, "operations[{$context}][{$id}]");
88  $this->addItem($cb);
89  }
90  }
91  }
92 
93 
94  public function fillForm()
95  {
96  $operations = array();
97  foreach ($this->ilOrgUnitPermissions as $ilOrgUnitPermission) {
98  $context = $ilOrgUnitPermission->getContext()->getContext();
99  foreach ($ilOrgUnitPermission->getPossibleOperations() as $operation) {
100  $id = $operation->getOperationId();
101  $operations["operations[{$context}][{$id}]"] = $ilOrgUnitPermission->isOperationIdSelected($operation->getOperationId());
102  }
103  }
104  $this->setValuesByArray($operations);
105  }
106 
107 
108  protected function fillObject()
109  {
110  if (!$this->checkInput()) {
111  return false;
112  }
113  $sent_operation_ids = $this->getInput(self::F_OPERATIONS);
114  foreach ($this->ilOrgUnitPermissions as $ilOrgUnitPermission) {
115  $operations = [];
116  $context = $ilOrgUnitPermission->getContext()->getContext();
117  foreach ($ilOrgUnitPermission->getPossibleOperations() as $operation) {
118  $id = $operation->getOperationId();
119  if ($sent_operation_ids[$context][$id]) {
120  $operations[] = ilOrgUnitOperation::find($id);
121  }
122  }
123  $ilOrgUnitPermission->setOperations($operations);
124  }
125 
126  return true;
127  }
128 
129 
133  public function getIlOrgUnitPermissions()
134  {
136  }
137 
138 
143  {
144  $this->ilOrgUnitPermissions = $ilOrgUnitPermissions;
145  }
146 
147 
151  protected function dic()
152  {
153  return $GLOBALS["DIC"];
154  }
155 
156 
162  protected function txt($key)
163  {
164  return $this->parent_gui->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 }
getFormAction()
Get FormAction.
$context
Definition: webdav.php:26
static lookupTxtById($plugin_id, $lang_var)
This class represents a property form user interface.
This class represents a section header in a property form.
This class represents a checkbox property in a property form.
setFormAction($a_formaction)
Set FormAction.
addItem($a_item)
Add Item (Property, SectionHeader).
Class ilOrgUnitDefaultPermissionFormGUI.
parses the objects.xml it handles the xml-description of all ilias objects
setTarget($a_target)
Set Target.
setTitle($a_title)
Set Title.
__construct(BaseCommands $parent_gui, array $ilOrgUnitPermissionsFilter, ilObjectDefinition $objectDefinition)
ilOrgUnitDefaultPermissionFormGUI constructor.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
addCommandButton($a_cmd, $a_text, $a_id="")
Add Command button.
checkInput()
Check Post Input.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
__construct(Container $dic, ilPlugin $plugin)
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.