ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWidthHeightInputGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected bool $support_constraint_props = false;
27 protected bool $constrainproportions = false;
28 protected ?int $height = null;
29 protected ?int $width = null;
30 protected array $dirs = [];
31 protected ilObjUser $user;
32 protected \ilGlobalTemplateInterface $main_tpl;
33
34 public function __construct(
35 string $a_title = "",
36 string $a_postvar = ""
37 ) {
38 global $DIC;
39
40 $this->lng = $DIC->language();
41 $this->user = $DIC->user();
42 parent::__construct($a_title, $a_postvar);
43 $this->setType("width_height");
44 $this->main_tpl = $DIC->ui()->mainTemplate();
45 }
46
47 public function setSupportConstraintsProps(bool $a_val): void
48 {
49 $this->support_constraint_props = $a_val;
50 }
51
52 public function getSupportConstraintsProps(): bool
53 {
55 }
56
57 public function setWidth(?int $a_width): void
58 {
59 $this->width = $a_width;
60 }
61
62 public function getWidth(): ?int
63 {
64 return $this->width;
65 }
66
67 public function setHeight(?int $a_height): void
68 {
69 $this->height = $a_height;
70 }
71
72 public function getHeight(): ?int
73 {
74 return $this->height;
75 }
76
77 public function setConstrainProportions(bool $a_constrainproportions): void
78 {
79 $this->constrainproportions = $a_constrainproportions;
80 }
81
82 public function getConstrainProportions(): bool
83 {
85 }
86
87 public function checkInput(): bool
88 {
89 $i = $this->getInput();
90 $this->setWidth($i["width"] ? (int) $i["width"] : null);
91 $this->setHeight($i["height"] ? (int) $i["height"] : null);
92 $this->setConstrainProportions((bool) $i["constr_prop"]);
93
94 return true;
95 }
96
97 public function getInput(): array
98 {
99 $val = $this->strArray($this->getPostVar());
100 return [
101 "width" => (string) ($val["width"] ?? ""),
102 "height" => (string) ($val["height"] ?? ""),
103 "constr_prop" => (bool) ($val["constr_prop"] ?? false)
104 ];
105 }
106
107 public function insert(ilTemplate $a_tpl): void
108 {
110
111 $tpl = new ilTemplate("tpl.prop_width_height.html", true, true, "components/ILIAS/MediaObjects");
112
113 $wh_ratio = 0;
114 if ((int) $this->getHeight() > 0) {
115 $wh_ratio = (int) $this->getWidth() / (int) $this->getHeight();
116 }
117 $ratio = str_replace(",", ".", round($wh_ratio, 6));
118 if ($this->getSupportConstraintsProps() && $wh_ratio > 0) {
119 $tpl->setCurrentBlock("cs_prop");
120 $tpl->setVariable("TXT_CONSTR_PROP", $lng->txt("cont_constrain_proportions"));
121 $tpl->setVariable("CS_POST_VAR", $this->getPostVar());
122 if ($this->getConstrainProportions()) {
123 $tpl->setVariable("CHECKED", 'checked="checked"');
124 }
125 $tpl->parseCurrentBlock();
126 $this->main_tpl->addOnLoadCode(
127 'prop_width_height["prop_' . $this->getPostVar() . '"] = ' . $ratio . ';'
128 );
129 }
130
131 $tpl->setVariable("VAL_WIDTH", strtolower(trim((string) $this->getWidth())));
132 $tpl->setVariable("VAL_HEIGHT", strtolower(trim((string) $this->getHeight())));
133
134 $tpl->setVariable("POST_VAR", $this->getPostVar());
135
136 $a_tpl->setCurrentBlock("prop_generic");
137 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
138 $a_tpl->parseCurrentBlock();
139
140 $this->main_tpl
141 ->addJavaScript("assets/js/ServiceMediaObjectPropWidthHeight.js");
142 $this->main_tpl->addOnLoadCode(
143 'prop_width_height["prop_' . $this->getPostVar() . '"] = ' . $ratio . ';'
144 );
145 }
146
147 public function setValueByArray(array $a_values): void
148 {
149 $w = $a_values[$this->getPostVar()]["width"] ?? false;
150 $h = $a_values[$this->getPostVar()]["height"] ?? false;
151 $this->setWidth($w ? (int) $w : null);
152 $this->setHeight($h ? (int) $h : null);
153 $this->setConstrainProportions($a_values[$this->getPostVar()]["constr_prop"] ?? false);
154 }
155}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
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...
User class.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
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="")
checkInput()
Check input, strip slashes etc.
ilGlobalTemplateInterface $main_tpl
setConstrainProportions(bool $a_constrainproportions)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26