ILIAS  release_8 Revision v8.24
class.ilOrgUnitPositionFormGUI.php
Go to the documentation of this file.
1<?php
20
26{
27 public const F_AUTHORITIES = "authorities";
29 public const F_TITLE = 'title';
30 public const F_DESCRIPTION = 'description';
31
32 protected function initFormElements(): void
33 {
34 global $DIC;
35 $lng = $DIC->language();
36
37 $te = new ilTextInputGUI($lng->txt(self::F_TITLE), self::F_TITLE);
38 $te->setRequired(true);
39 $this->addItem($te);
40
41 $te = new ilTextAreaInputGUI($lng->txt(self::F_DESCRIPTION), self::F_DESCRIPTION);
42 $this->addItem($te);
43
44 $m = new ilOrgUnitGenericMultiInputGUI($lng->txt(self::F_AUTHORITIES), self::F_AUTHORITIES);
45 $m->setShowLabel(true);
46 $m->setRenderOneForEmptyValue(false);
47 $m->setMulti(true);
48
50 $m->addInput($id);
51
53 $over_options = [];
54 $over_options[ilOrgUnitAuthority::OVER_EVERYONE] = $lng->txt('over_'
56 $over_options += ilOrgUnitPosition::getArray('id', 'title');
57 $over->setOptions($over_options);
58 $m->addInput($over);
59
60 $available_scopes = [];
62 $txt = $lng->txt('scope_' . $scope);
63 $available_scopes[$scope] = $txt;
64 }
65
67 $scopes->setOptions($available_scopes);
68 $m->addInput($scopes);
69
70 $this->addItem($m);
71 }
72
73 public function fillForm(): void
74 {
75 $this->object->afterObjectLoad();
76 $array = array(
77 self::F_TITLE => $this->object->getTitle(),
78 self::F_DESCRIPTION => $this->object->getDescription(),
79 self::F_AUTHORITIES => $this->object->getAuthoritiesAsArray()
80 );
81 $this->setValuesByArray($array);
82 }
83
84 public function fillObject(): bool
85 {
86 if (!$this->checkInput()) {
87 return false;
88 }
89
90 $this->object->setTitle($this->getInput(self::F_TITLE));
91 $this->object->setDescription($this->getInput(self::F_DESCRIPTION));
92
93 $authorities = $this->getInput(self::F_AUTHORITIES);
94
95 if (!is_array($authorities)) {
96 $this->object->setAuthorities([]);
97 $this->object->storeAuthorities();
98 return true;
99 }
100
101 $ilOrgUnitAuthorities = [];
102 foreach ($authorities as $authority) {
106 $id = $authority["id"];
107 if ($id == '') {
108 $id = null;
109 }
110 $ilOrgUnitAuthority = ilOrgUnitAuthority::findOrGetInstance($id);
111 $ilOrgUnitAuthority->setPositionId($this->object->getId());
112 $ilOrgUnitAuthority->setScope($authority["scope"]);
113 $ilOrgUnitAuthority->setOver($authority["over"]);
114 $ilOrgUnitAuthorities[] = clone $ilOrgUnitAuthority;
115 }
116 $this->object->setAuthorities($ilOrgUnitAuthorities);
117 $this->object->storeAuthorities();
118 return true;
119 }
120}
Class ActiveRecord.
static findOrGetInstance($primary_key, array $add_constructor_args=array())
static getArray(?string $key=null, $values=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilOrgUnitPositionFormGUI.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
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-...
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
$txt
Definition: error.php:13
$scope
Definition: ltiregstart.php:53
$scopes
Definition: ltitoken.php:99