ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBackgroundImageInputGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 protected array $images;
29 protected ilObjUser $user;
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("background_image");
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 setImages(array $a_images): void
53 {
54 $this->images = $a_images;
55 }
56
57 public function getImages(): array
58 {
59 return $this->images;
60 }
61
62 public function checkInput(): bool
63 {
65
66 $input = $this->getInput();
67
68 $type = $input["type"] ?? "";
69 $int_value = $input["int_value"] ?? "";
70 $ext_value = $input["ext_value"] ?? "";
71
72 if ($this->getRequired() && $type == "ext" && trim($ext_value) == "") {
73 $this->setAlert($lng->txt("msg_input_is_required"));
74
75 return false;
76 }
77
78 if ($type == "external") {
79 $this->setValue($ext_value);
80 } else {
81 $this->setValue($int_value);
82 }
83
84 return true;
85 }
86
87 public function getInput(): array
88 {
89 return $this->strArray($this->getPostVar());
90 }
91
92 public function insert(ilTemplate $a_tpl): void
93 {
94 $tpl = new ilTemplate("tpl.prop_background_image.html", true, true, "components/ILIAS/Style/Content");
95
96 $tpl->setVariable("POSTVAR", $this->getPostVar());
97
98 $int_options = array_merge(array("" => ""), $this->getImages());
99
100 $value = trim($this->getValue());
101
102 if (is_int(strpos($value, "/"))) {
103 $current_type = "ext";
104 $tpl->setVariable("EXTERNAL_SELECTED", 'checked="checked"');
105 $tpl->setVariable("VAL_EXT", ilLegacyFormElementsUtil::prepareFormOutput($value));
106 } else {
107 $current_type = "int";
108 $tpl->setVariable("INTERNAL_SELECTED", 'checked="checked"');
109 }
110
111 foreach ($int_options as $option) {
112 $tpl->setCurrentBlock("int_option");
113 $tpl->setVariable("VAL_INT", $option);
114 $tpl->setVariable("TXT_INT", $option);
115
116 if ($current_type == "int" && $value == $option) {
117 $tpl->setVariable("INT_SELECTED", 'selected="selected"');
118 }
119 $tpl->parseCurrentBlock();
120 }
121
122 $a_tpl->setCurrentBlock("prop_generic");
123 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
124 $a_tpl->parseCurrentBlock();
125 }
126
127 public function setValueByArray(array $a_values): void
128 {
129 if ($a_values[$this->getPostVar()]["type"] == "internal") {
130 $this->setValue($a_values[$this->getPostVar()]["int_value"]);
131 } else {
132 $this->setValue($a_values[$this->getPostVar()]["ext_value"]);
133 }
134 }
135}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
This class represents a background image property in a property form.
checkInput()
Check input, strip slashes etc.
__construct(string $a_title="", string $a_postvar="")
This class represents a property in a property form.
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)
User class.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26