ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilOrgUnitAuthorityInputGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 class 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 
50  return $this->positionRepo;
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 = "";
119  foreach (ilOrgUnitAuthority::getScopes() as $scope) {
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 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
$scope
Definition: ltiregstart.php:47
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:544
$GLOBALS["DIC"]
Definition: wac.php:53
Class HTTPServicesTest.
$txt
Definition: error.php:31
Interface for multi values support.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
$lang
Definition: xapiexit.php:25
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
Class ilOrgUnitAuthorityInputGUI.
$dic
Definition: result.php:31
Class ilOrguAuthority.