ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilFontSizeInputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 {
28  protected ilObjUser $user;
29 
30  protected string $value = "";
31 
32  public function __construct(string $a_title = "", string $a_postvar = "")
33  {
34  global $DIC;
35 
36  $this->lng = $DIC->language();
37  $this->user = $DIC->user();
38  parent::__construct($a_title, $a_postvar);
39  $this->setType("fontsize");
40  }
41 
42  public function setValue(string $a_value): void
43  {
44  $this->value = $a_value;
45  }
46 
47  public function getValue(): string
48  {
49  return $this->value;
50  }
51 
52  public function checkInput(): bool
53  {
54  $lng = $this->lng;
55 
56  $input = $this->getInput();
57 
58  $type = $input["type"];
59  $num_value = $input["num_value"];
60  $num_unit = $input["num_unit"];
61  $pre_value = $input["pre_value"];
62 
63  if ($this->getRequired() && $type == "numeric" && trim($num_value) == "") {
64  $this->setAlert($lng->txt("msg_input_is_required"));
65 
66  return false;
67  }
68 
69  if ($type == "numeric") {
70  if (!is_numeric($num_value) && $num_value != "") {
71  $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
72 
73  return false;
74  }
75 
76  if (trim($num_value) != "") {
77  $this->setValue($num_value . $num_unit);
78  }
79  } else {
80  $this->setValue($pre_value);
81  }
82 
83  return true;
84  }
85 
86  public function getInput(): array
87  {
88  return $this->strArray($this->getPostVar());
89  }
90 
91  public function insert(ilTemplate $a_tpl): void
92  {
93  $tpl = new ilTemplate("tpl.prop_fontsize.html", true, true, "Services/Style/Content");
94 
95  $tpl->setVariable("POSTVAR", $this->getPostVar());
96  $current_unit = "";
97 
99  $pre_options = ilObjStyleSheet::_getStyleParameterValues("font-size");
100 
101  $value = strtolower(trim($this->getValue()));
102 
103  if (in_array($value, $pre_options)) {
104  $current_type = "pre";
105  $tpl->setVariable("PREDEFINED_SELECTED", 'checked="checked"');
106  } else {
107  $current_type = "unit";
108  $tpl->setVariable("NUMERIC_SELECTED", 'checked="checked"');
109  foreach ($unit_options as $u) {
110  if (substr($value, strlen($value) - strlen($u)) == $u) {
111  $current_unit = $u;
112  }
113  }
114  $tpl->setVariable(
115  "VAL_NUM",
116  substr($value, 0, strlen($value) - strlen($current_unit))
117  );
118  if ($current_unit == "") {
119  $current_unit = "px";
120  }
121  }
122 
123  foreach ($unit_options as $option) {
124  $tpl->setCurrentBlock("unit_option");
125  $tpl->setVariable("VAL_UNIT", $option);
126  $tpl->setVariable("TXT_UNIT", $option);
127  if ($current_type == "unit" && $current_unit == $option) {
128  $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
129  }
130  $tpl->parseCurrentBlock();
131  }
132 
133  foreach ($pre_options as $option) {
134  $tpl->setCurrentBlock("pre_option");
135  $tpl->setVariable("VAL_PRE", $option);
136  $tpl->setVariable("TXT_PRE", $option);
137  if ($current_type == "pre" && $value == $option) {
138  $tpl->setVariable("PRE_SELECTED", 'selected="selected"');
139  }
140  $tpl->parseCurrentBlock();
141  }
142 
143  $a_tpl->setCurrentBlock("prop_generic");
144  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
145  $a_tpl->parseCurrentBlock();
146  }
147 
148  public function setValueByArray(array $a_values): void
149  {
150  if ($a_values[$this->getPostVar()]["type"] == "predefined") {
151  $this->setValue($a_values[$this->getPostVar()]["pre_value"]);
152  } else {
153  $this->setValue($a_values[$this->getPostVar()]["num_value"] .
154  $a_values[$this->getPostVar()]["num_unit"]);
155  }
156  }
157 }
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
__construct(string $a_title="", string $a_postvar="")
setValueByArray(array $a_values)
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property in a property form.
__construct(Container $dic, ilPlugin $plugin)
static _getStyleParameterValues(string $par)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41