ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBackgroundPositionInputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 {
31  protected array $dirs = [];
32  protected string $verticalvalue = "";
33  protected string $horizontalvalue = "";
34  protected ilObjUser $user;
35  protected string $value = "";
36 
37  public function __construct(string $a_title = "", string $a_postvar = "")
38  {
39  global $DIC;
40 
41  $this->lng = $DIC->language();
42  $this->user = $DIC->user();
43  parent::__construct($a_title, $a_postvar);
44  $this->setType("border_width");
45  $this->dirs = array("horizontal", "vertical");
46  }
47 
48  public function setHorizontalValue(string $a_horizontalvalue): void
49  {
50  $this->horizontalvalue = $a_horizontalvalue;
51  }
52 
53  public function getHorizontalValue(): string
54  {
56  }
57 
58  public function setVerticalValue(string $a_verticalvalue): void
59  {
60  $this->verticalvalue = $a_verticalvalue;
61  }
62 
63  public function getVerticalValue(): string
64  {
65  return $this->verticalvalue;
66  }
67 
68  public function getValue(): string
69  {
70  if ($this->getHorizontalValue() != "") {
71  if ($this->getVerticalValue() != "") {
72  return $this->getHorizontalValue() . " " . $this->getVerticalValue();
73  } else {
74  return $this->getHorizontalValue();
75  }
76  } else {
77  if ($this->getVerticalValue() != "") {
78  return "left " . $this->getVerticalValue();
79  }
80  }
81  return "";
82  }
83 
84  public function setValue(string $a_val): void
85  {
86  $a_val = trim($a_val);
87  $a_val_arr = explode(" ", $a_val);
88  $hor = trim($a_val_arr[0]);
89  $ver = trim($a_val_arr[1] ?? "");
90  if ($hor == "center" && $ver == "") {
91  $ver = "center";
92  }
93  $this->setHorizontalValue($hor);
94  $this->setVerticalValue($ver);
95  }
96 
97  public function checkInput(): bool
98  {
99  $lng = $this->lng;
100 
101  $input = $this->getInput();
102 
103  foreach ($this->dirs as $dir) {
104  $type = $input[$dir]["type"];
105  $num_value = $input[$dir]["num_value"];
106  $num_unit = $input[$dir]["num_unit"];
107  $pre_value = $input[$dir]["pre_value"];
108 
109  if (!is_numeric($num_value) && trim($num_value) != "") {
110  $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
111  return false;
112  }
113 
114  $value = "";
115  if ($type == "numeric") {
116  if ($num_value != "") {
117  $value = $num_value . $num_unit;
118  }
119  } else {
120  $value = $pre_value;
121  }
122 
123  if (trim($value) != "") {
124  switch ($dir) {
125  case "horizontal": $this->setHorizontalValue($value); break;
126  case "vertical": $this->setVerticalValue($value); break;
127  }
128  }
129  }
130 
131  return true;
132  }
133 
134  public function getInput(): array
135  {
136  return $this->arrayArray($this->getPostVar());
137  }
138 
139  public function insert(ilTemplate $a_tpl): void
140  {
141  $lng = $this->lng;
142 
143  $layout_tpl = new ilTemplate("tpl.prop_hv_layout.html", true, true, "Services/Style/Content");
144 
145  foreach ($this->dirs as $dir) {
146  $value = "";
147  $current_unit = "";
148  $tpl = new ilTemplate("tpl.prop_background_position.html", true, true, "Services/Style/Content");
150  $pre_options = ilObjStyleSheet::_getStyleParameterValues("background-position");
151  $pre_options = $pre_options[$dir];
152  switch ($dir) {
153  case "horizontal": $value = strtolower(trim($this->getHorizontalValue())); break;
154  case "vertical": $value = strtolower(trim($this->getVerticalValue())); break;
155  }
156 
157  if (in_array($value, $pre_options)) {
158  $current_type = "pre";
159  $tpl->setVariable("PREDEFINED_SELECTED", 'checked="checked"');
160  } else {
161  $current_type = "unit";
162  $tpl->setVariable("NUMERIC_SELECTED", 'checked="checked"');
163 
164  foreach ($unit_options as $u) {
165  if (substr($value, strlen($value) - strlen($u)) == $u) {
166  $current_unit = $u;
167  }
168  }
169  $disp_val = substr($value, 0, strlen($value) - strlen($current_unit));
170  if ($current_unit == "") {
171  $current_unit = "px";
172  }
173  $tpl->setVariable("VAL_NUM", $disp_val);
174  }
175 
176  foreach ($unit_options as $option) {
177  $tpl->setCurrentBlock("unit_option");
178  $tpl->setVariable("VAL_UNIT", $option);
179  $tpl->setVariable("TXT_UNIT", $option);
180  if ($current_type == "unit" && $current_unit == $option) {
181  $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
182  }
183  $tpl->parseCurrentBlock();
184  }
185 
186  foreach ($pre_options as $option) {
187  $tpl->setCurrentBlock("pre_option");
188  $tpl->setVariable("VAL_PRE", $option);
189  $tpl->setVariable("TXT_PRE", $option);
190  if ($current_type == "pre" && $value == $option) {
191  $tpl->setVariable("PRE_SELECTED", 'selected="selected"');
192  }
193  $tpl->parseCurrentBlock();
194  }
195 
196  $tpl->setVariable("POSTVAR", $this->getPostVar());
197  $tpl->setVariable("TXT_DIR", $lng->txt("sty_$dir"));
198  $tpl->setVariable("DIR", $dir);
199 
200  $layout_tpl->setVariable(strtoupper($dir), $tpl->get());
201  }
202  $layout_tpl->setVariable("COLSPAN", "2");
203 
204  $a_tpl->setCurrentBlock("prop_generic");
205  $a_tpl->setVariable("PROP_GENERIC", $layout_tpl->get());
206  $a_tpl->parseCurrentBlock();
207  }
208 
209  public function setValueByArray(array $a_values): void
210  {
211  if ($a_values[$this->getPostVar()]["horizontal"]["type"] == "predefined") {
212  $this->setHorizontalValue($a_values[$this->getPostVar()]["horizontal"]["pre_value"]);
213  } else {
214  $this->setHorizontalValue($a_values[$this->getPostVar()]["horizontal"]["num_value"] .
215  $a_values[$this->getPostVar()]["horizontal"]["num_unit"]);
216  }
217  if ($a_values[$this->getPostVar()]["vertical"]["type"] == "predefined") {
218  $this->setVerticalValue($a_values[$this->getPostVar()]["vertical"]["pre_value"]);
219  } else {
220  $this->setVerticalValue($a_values[$this->getPostVar()]["vertical"]["num_value"] .
221  $a_values[$this->getPostVar()]["vertical"]["num_unit"]);
222  }
223  }
224 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
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...
static _getStyleParameterNumericUnits(bool $a_no_percentage=false)
global $DIC
Definition: feed.php:28
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a property in a property form.
__construct(Container $dic, ilPlugin $plugin)
static _getStyleParameterValues(string $par)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
__construct(string $a_title="", string $a_postvar="")