ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilOrgUnitAuthorityInputGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25class ilOrgUnitAuthorityInputGUI extends ilFormPropertyGUI implements ilMultiValuesItem // TODO: still in use?
26{
30 protected $value;
32
38 public function __construct($a_title, $a_postvar)
39 {
40 parent::__construct($a_title, $a_postvar);
41 }
42
44 {
45 if (!isset($this->positionRepo)) {
47 $this->positionRepo = $dic["repo.Positions"];
48 }
49
51 }
52
56 public function insert(ilTemplate $a_tpl): void
57 {
58 $html = $this->render();
59
60 $a_tpl->setCurrentBlock("prop_generic");
61 $a_tpl->setVariable("PROP_GENERIC", $html);
62 $a_tpl->parseCurrentBlock();
63 }
64
68 public function setValueByArray(array $values): void
69 {
70 $authorities = $values[$this->getPostVar()];
71 if (!is_array($authorities)) {
72 $authorities = [];
73 }
74 foreach ($authorities as $authority) {
75 assert($authority instanceof ilOrgUnitAuthority);
76 }
77 $this->setValue($authorities);
78 }
79
83 public function setValue(array $a_value): void
84 {
85 $this->value = $a_value;
86 }
87
91 public function getValue(): array
92 {
93 return $this->value;
94 }
95
99 protected function render(): string
100 {
101 $tpl = new ilTemplate("tpl.authority_input.html", true, true, "components/ILIAS/OrgUnit");
102 // if (strlen($this->getValue())) {
103 // $tpl->setCurrentBlock("prop_text_propval");
104 // $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
105 // $tpl->parseCurrentBlock();
106 // }
107
108 //$tpl->setVariable("POSITION_ID", $this->getFieldId());
109
110 $postvar = $this->getPostVar();
111 // if ($this->getMulti() && substr($postvar, - 2) != "[]") {
112 // $postvar .= "[]";
113 // }
114
115 $tpl->setVariable("POST_VAR", $postvar);
116
117 // SCOPE
118 $scope_html = "";
120 $txt = $this->dic()->language()->txt('scope_' . $scope);
121 $scope_html .= "<option value='{$scope}'>{$txt}</option>";
122 }
123 $tpl->setVariable("SCOPE_OPTIONS", $scope_html);
124
125 // Over
126 $over_everyone = ilOrgUnitAuthority::OVER_EVERYONE;
127 $title = $this->lang()->txt('over_' . $over_everyone);
128 $over_html = "<option value='{$over_everyone}'>{$title}</option>";
129 foreach ($this->getPositionRepo()->getArray('id', 'title') as $id => $title) {
130 $over_html .= "<option value='{$id}'>{$title}</option>";
131 }
132 $tpl->setVariable("OVER_OPTIONS", $over_html);
136 if ($this->getMultiValues()) {
137 foreach ($this->getMultiValues() as $ilOrgUnitAuthority) {
138 // $tpl->setVariable("OVER_OPTIONS", $over_html); // TODO: remove?
139 }
140 }
141
142 if ($this->getRequired()) {
143 // $tpl->setVariable("REQUIRED", "required=\"required\""); // TODO: remove?
144 }
145
146 $tpl->touchBlock("inline_in_bl");
147 $tpl->setVariable("MULTI_ICONS", $this->getMultiIconsHTML());
148 $this->initJS();
149
150 return $tpl->get();
151 }
152
153 protected function dic(): \ILIAS\DI\Container
154 {
155 return $GLOBALS["DIC"];
156 }
157
158 protected function lang(): \ilLanguage
159 {
160 static $loaded;
161 $lang = $this->dic()->language();
162 if (!$loaded) {
163 $lang->loadLanguageModule('orgu');
164 $loaded = true;
165 }
166
167 return $lang;
168 }
169
170 public function getMulti(): bool
171 {
172 return false;
173 }
174
175 protected function initJS(): void
176 {
177 // Global JS
181 $globalTpl = $GLOBALS['DIC'] ? $GLOBALS['DIC']['tpl'] : $GLOBALS['tpl'];
182 $globalTpl->addJavascript("assets/js/authority.js");
183
184 $config = json_encode(array());
185
186 $authorities = $this->getValue();
187 $auth = [];
188 foreach ($authorities as $authority) {
189 $auth[] = [
190 'id' => $authority->getId(),
191 'over' => $authority->getOver(),
192 'scope' => $authority->getScope()
193 ];
194 }
195 $data = json_encode($auth);
196
197 $globalTpl->addOnLoadCode("ilOrgUnitAuthorityInput.init({$config}, {$data});");
198 }
199}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
This class represents a property in a property form.
language handling
Class ilOrgUnitAuthorityInputGUI.
__construct($a_title, $a_postvar)
ilOrgUnitAuthorityInputGUI constructor.
ilOrgUnitPositionDBRepository $positionRepo
Class ilOrguAuthority.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
$txt
Definition: error.php:31
Interface for multi values support.
$scope
Definition: ltiregstart.php:51
$dic
Definition: ltiresult.php:33
Class HTTPServicesTest.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$GLOBALS["DIC"]
Definition: wac.php:54
$lang
Definition: xapiexit.php:25