ILIAS  release_8 Revision v8.24
class.ilImageFileInputGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
29 protected bool $cache = false;
30 protected string $alt = "";
31 protected string $image = "";
32 protected bool $allow_capture = false;
33
34 public function __construct(
35 string $a_title = "",
36 string $a_postvar = ""
37 ) {
38 global $DIC;
39
40 $this->lng = $DIC->language();
41 $lng = $DIC->language();
42
43 parent::__construct($a_title, $a_postvar);
44 $this->setType("image_file");
45 $this->setAllowDeletion(true);
46 $this->setSuffixes(array("jpg", "jpeg", "png", "gif"));
47 $this->setHiddenTitle("(" . $lng->txt("form_image_file_input") . ")");
48 $this->cache = true;
49 $this->tpl = $DIC->ui()->mainTemplate();
50 }
51
52 public function setAllowDeletion(bool $a_val): void
53 {
54 $this->allow_deletion = $a_val;
55 }
56
57 public function getALlowDeletion(): bool
58 {
60 }
61
62 public function setAllowCapture(bool $a_val): void
63 {
64 $this->allow_capture = $a_val;
65 }
66
67 public function getAllowCapture(): bool
68 {
70 }
71
78 public function setUseCache(bool $a_cache): void
79 {
80 $this->cache = $a_cache;
81 }
82
83 public function getUseCache(): bool
84 {
85 return $this->cache;
86 }
87
88 public function setImage(string $a_image): void
89 {
90 $this->image = $a_image;
91 }
92
93 public function getImage(): string
94 {
95 return $this->image;
96 }
97
98 public function setAlt(string $a_alt): void
99 {
100 $this->alt = $a_alt;
101 }
102
103 public function getAlt(): string
104 {
105 return $this->alt;
106 }
107
108 public function insert(ilTemplate $a_tpl): void
109 {
111
112 $quota_exceeded = $quota_legend = false;
113 $i_tpl = new ilTemplate("tpl.prop_image_file.html", true, true, "Services/Form");
114
115 if ($this->getAllowCapture()) {
116 $i_tpl->setCurrentBlock("capture");
117 $i_tpl->setVariable("POST_VAR_V", $this->getPostVar());
118 $i_tpl->setVariable("TXT_USE_CAMERA", $lng->txt("form_use_camera"));
119 $i_tpl->setVariable("TXT_TAKE_SNAPSHOT", $lng->txt("form_take_snapshot"));
120 $i_tpl->parseCurrentBlock();
121 $main_tpl = $this->tpl;
122 $main_tpl->addJavascript("./Services/Form/js/ServiceFormImageFileCapture.js");
123 }
124
125 if ($this->getImage() != "") {
126 if (!$this->getDisabled() && $this->getALlowDeletion()) {
127 $i_tpl->setCurrentBlock("delete_bl");
128 $i_tpl->setVariable("POST_VAR_D", $this->getPostVar());
129 $i_tpl->setVariable(
130 "TXT_DELETE_EXISTING",
131 $lng->txt("delete_existing_file")
132 );
133 $i_tpl->parseCurrentBlock();
134 }
135
136 if (strlen($this->getValue())) {
137 $i_tpl->setCurrentBlock("has_value");
138 $i_tpl->setVariable("TEXT_IMAGE_NAME", $this->getValue());
139 $i_tpl->parseCurrentBlock();
140 }
141 $i_tpl->setCurrentBlock("image");
142 if (!$this->getUseCache()) {
143 $pos = strpos($this->getImage(), '?');
144 if ($pos !== false) {
145 $i_tpl->setVariable("SRC_IMAGE", $this->getImage() . "&amp;time=" . time());
146 } else {
147 $i_tpl->setVariable("SRC_IMAGE", $this->getImage() . "?time=" . time());
148 }
149 } else {
150 $i_tpl->setVariable("SRC_IMAGE", $this->getImage());
151 }
152 $i_tpl->setVariable("POST_VAR_I", $this->getPostVar());
153 $i_tpl->setVariable("ALT_IMAGE", $this->getAlt());
154 $i_tpl->parseCurrentBlock();
155 }
156
157 $pending = $this->getPending();
158 if ($pending) {
159 $i_tpl->setCurrentBlock("pending");
160 $i_tpl->setVariable("TXT_PENDING", $lng->txt("file_upload_pending") .
161 ": " . htmlentities($pending));
162 $i_tpl->parseCurrentBlock();
163 }
164
165 $i_tpl->setVariable("POST_VAR", $this->getPostVar());
166 $i_tpl->setVariable("ID", $this->getFieldId());
167
168
169 /* experimental: bootstrap'ed file upload */
170 $i_tpl->setVariable("TXT_BROWSE", $lng->txt("select_file"));
171
172
173 if (!$quota_exceeded) {
174 $i_tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " .
175 $this->getMaxFileSizeString() . $quota_legend);
176
177 $this->outputSuffixes($i_tpl, "allowed_image_suffixes");
178 } else {
179 $i_tpl->setVariable("TXT_MAX_SIZE", $quota_exceeded);
180 }
181
182 if ($this->getDisabled() || $quota_exceeded) {
183 $i_tpl->setVariable(
184 "DISABLED",
185 " disabled=\"disabled\""
186 );
187 }
188
189 $a_tpl->setCurrentBlock("prop_generic");
190 $a_tpl->setVariable("PROP_GENERIC", $i_tpl->get());
191 $a_tpl->parseCurrentBlock();
192 }
193
194 public function getDeletionFlag(): bool
195 {
196 if ($this->str($this->getPostVar() . "_delete") != "") {
197 return true;
198 }
199 return false;
200 }
201}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
This class represents a file property in a property form.
setSuffixes(array $a_suffixes)
outputSuffixes(ilTemplate $a_tpl, string $a_block="allowed_suffixes")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(string $a_title="", string $a_postvar="")
ilGlobalTemplateInterface $tpl
setUseCache(bool $a_cache)
Set cache.
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...
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc