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