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