ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilWidthHeightInputGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected $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  {
109  $lng = $this->lng;
110 
111  $tpl = new ilTemplate("tpl.prop_width_height.html", true, true, "Services/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($this->getWidth())));
132  $tpl->setVariable("VAL_HEIGHT", strtolower(trim($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("./Services/MediaObjects/js/ServiceMediaObjectPropWidthHeight.js");
142  }
143 
144  public function setValueByArray(array $a_values): void
145  {
146  $w = $a_values[$this->getPostVar()]["width"] ?? false;
147  $h = $a_values[$this->getPostVar()]["height"] ?? false;
148  $this->setWidth($w ? (int) $w : null);
149  $this->setHeight($h ? (int) $h : null);
150  $this->setConstrainProportions($a_values[$this->getPostVar()]["constr_prop"] ?? false);
151  }
152 }
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...
ilGlobalTemplateInterface $main_tpl
global $DIC
Definition: feed.php:28
__construct(string $a_title="", string $a_postvar="")
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
setConstrainProportions(bool $a_constrainproportions)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a property in a property form.
__construct(Container $dic, ilPlugin $plugin)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:41