ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilTRBLColorPickerInputGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
28  protected bool $acceptnamedcolors = false;
29  protected string $defaultcolor = "";
30  protected string $allvalue = "";
31  protected string $leftvalue = "";
32  protected string $rightvalue = "";
33  protected string $bottomvalue = "";
34  protected string $topvalue = "";
35 
39  protected array $dirs = [];
40  protected string $hex = "";
41 
42  public function __construct(string $a_title = "", string $a_postvar = "")
43  {
44  global $DIC;
45 
46  $this->lng = $DIC->language();
47  parent::__construct($a_title, $a_postvar);
48  $this->setType("trbl_color");
49  $this->dirs = array("all", "top", "bottom", "left", "right");
50  }
51 
52  public function setAllValue(string $a_allvalue): void
53  {
54  $a_allvalue = trim($a_allvalue);
55  if ($this->getAcceptNamedColors() && substr($a_allvalue, 0, 1) == "!") {
56  $this->allvalue = $a_allvalue;
57  } else {
58  $this->allvalue = ilColorPickerInputGUI::determineHexcode($a_allvalue);
59  }
60  }
61 
62  public function getAllValue(): string
63  {
64  return $this->allvalue;
65  }
66 
67  public function setTopValue(string $a_topvalue): void
68  {
69  $a_topvalue = trim($a_topvalue);
70  if ($this->getAcceptNamedColors() && substr($a_topvalue, 0, 1) == "!") {
71  $this->topvalue = $a_topvalue;
72  } else {
73  $this->topvalue = ilColorPickerInputGUI::determineHexcode($a_topvalue);
74  }
75  }
76 
77  public function getTopValue(): string
78  {
79  return $this->topvalue;
80  }
81 
82  public function setBottomValue(string $a_bottomvalue): void
83  {
84  $a_bottomvalue = trim($a_bottomvalue);
85  if ($this->getAcceptNamedColors() && substr($a_bottomvalue, 0, 1) == "!") {
86  $this->bottomvalue = $a_bottomvalue;
87  } else {
88  $this->bottomvalue = ilColorPickerInputGUI::determineHexcode($a_bottomvalue);
89  }
90  }
91 
92  public function getBottomValue(): string
93  {
94  return $this->bottomvalue;
95  }
96 
97  public function setLeftValue(string $a_leftvalue): void
98  {
99  $a_leftvalue = trim($a_leftvalue);
100  if ($this->getAcceptNamedColors() && substr($a_leftvalue, 0, 1) == "!") {
101  $this->leftvalue = $a_leftvalue;
102  } else {
103  $this->leftvalue = ilColorPickerInputGUI::determineHexcode($a_leftvalue);
104  }
105  }
106 
107  public function getLeftValue(): string
108  {
109  return $this->leftvalue;
110  }
111 
112  public function setRightValue(string $a_rightvalue): void
113  {
114  $a_rightvalue = trim($a_rightvalue);
115  if ($this->getAcceptNamedColors() && substr($a_rightvalue, 0, 1) == "!") {
116  $this->rightvalue = $a_rightvalue;
117  } else {
118  $this->rightvalue = ilColorPickerInputGUI::determineHexcode($a_rightvalue);
119  }
120  }
121 
122  public function getRightValue(): string
123  {
124  return $this->rightvalue;
125  }
126 
127  public function setDefaultColor(string $a_defaultcolor): void
128  {
129  $this->defaultcolor = $a_defaultcolor;
130  }
131 
132  public function getDefaultColor(): string
133  {
134  return $this->defaultcolor;
135  }
136 
137  public function setAcceptNamedColors(bool $a_acceptnamedcolors): void
138  {
139  $this->acceptnamedcolors = $a_acceptnamedcolors;
140  }
141 
142  public function getAcceptNamedColors(): bool
143  {
145  }
146 
147  public function checkInput(): bool
148  {
149  $input = $this->getInput();
150  foreach ($this->dirs as $dir) {
151  $value = $input[$dir]["value"];
152 
153  if (trim($value) != "") {
154  switch ($dir) {
155  case "all": $this->setAllValue($value);
156  break;
157  case "top": $this->setTopValue($value);
158  break;
159  case "bottom": $this->setBottomValue($value);
160  break;
161  case "left": $this->setLeftValue($value);
162  break;
163  case "right": $this->setRightValue($value);
164  break;
165  }
166  }
167  }
168  return true;
169  }
170 
171  public function getInput(): array
172  {
173  return $this->arrayArray($this->getPostVar());
174  }
175 
176  public function insert(ilTemplate $a_tpl): void
177  {
178  $lng = $this->lng;
179 
180  $layout_tpl = new ilTemplate("tpl.prop_trbl_layout.html", true, true, "components/ILIAS/Style/Content");
181 
182  $funcs = array(
183  "all" => "getAllValue", "top" => "getTopValue",
184  "bottom" => "getBottomValue", "left" => "getLeftValue",
185  "right" => "getRightValue");
186 
187  foreach ($this->dirs as $dir) {
188  $f = $funcs[$dir];
189  $value = trim($this->$f());
190  if (!$this->getAcceptNamedColors() || substr($value, 0, 1) != "!") {
191  $value = strtoupper($value);
192  }
193 
194  $tpl = new ilTemplate('tpl.prop_color.html', true, true, 'components/ILIAS/Form');
195  $tpl->setVariable('COLOR_ID', $this->getFieldId() . "_" . $dir);
197  if ($ic == "") {
198  $ic = "FFFFFF";
199  }
200  $tpl->setVariable('INIT_COLOR_SHORT', $ic);
201  $tpl->setVariable('POST_VAR', $this->getPostVar());
202 
203  if ($this->getDisabled()) {
204  $a_tpl->setVariable('COLOR_DISABLED', 'disabled="disabled"');
205  }
206 
207  $tpl->setVariable("POST_VAR", $this->getPostVar() . "[" . $dir . "][value]");
208  $tpl->setVariable("PROP_COLOR_ID", $this->getFieldId() . "_" . $dir);
209 
210  if (substr(trim((string) $this->getValue()), 0, 1) == "!" && $this->getAcceptNamedColors()) {
211  $tpl->setVariable(
212  "PROPERTY_VALUE_COLOR",
214  );
215  } else {
216  $tpl->setVariable("PROPERTY_VALUE_COLOR", ilLegacyFormElementsUtil::prepareFormOutput($value));
217  $tpl->setVariable('INIT_COLOR', '#' . $value);
218  }
219 
220  $tpl->setVariable("TXT_PREFIX", $lng->txt("sty_$dir"));
221 
222  $layout_tpl->setVariable(strtoupper($dir), $tpl->get());
223  }
224 
225  $a_tpl->setCurrentBlock("prop_generic");
226  $a_tpl->setVariable("PROP_GENERIC", $layout_tpl->get());
227  $a_tpl->parseCurrentBlock();
228  }
229 }
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 prepareFormOutput($a_str, bool $a_strip=false)
Color picker form for selecting color hexcodes using yui library (all/top/right/bottom/left) ...
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
global $DIC
Definition: shib_login.php:26
setAcceptNamedColors(bool $a_acceptnamedcolors)
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static determineHexcode(string $a_value)
__construct(string $a_title="", string $a_postvar="")
__construct(Container $dic, ilPlugin $plugin)