ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilWidthHeightInputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
17  protected $support_constraint_props = false;
21  protected $user;
22 
23  protected $value;
24 
31  public function __construct($a_title = "", $a_postvar = "")
32  {
33  global $DIC;
34 
35  $this->lng = $DIC->language();
36  $this->user = $DIC->user();
37  parent::__construct($a_title, $a_postvar);
38  $this->setType("width_height");
39  $this->dirs = array("width", "height");
40  }
41 
42  public function setSupportConstraintsProps(bool $a_val) : void
43  {
44  $this->support_constraint_props = $a_val;
45  }
46 
47  public function getSupportConstraintsProps() : bool
48  {
50  }
51 
52 
58  public function setWidth($a_width)
59  {
60  $this->width = $a_width;
61  }
62 
68  public function getWidth()
69  {
70  return $this->width;
71  }
72 
78  public function setHeight($a_height)
79  {
80  $this->height = $a_height;
81  }
82 
88  public function getHeight()
89  {
90  return $this->height;
91  }
92 
98  public function setConstrainProportions($a_constrainproportions)
99  {
100  $this->constrainproportions = $a_constrainproportions;
101  }
102 
108  public function getConstrainProportions()
109  {
110  return $this->constrainproportions;
111  }
112 
118  public function checkInput()
119  {
120  $lng = $this->lng;
121 
122  foreach ($this->dirs as $dir) {
123  $pre_value = $_POST[$this->getPostVar()][$dir] =
124  ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]);
125 
126  /*
127  if ($this->getRequired() && trim($num_value) == "")
128  {
129  $this->setAlert($lng->txt("msg_input_is_required"));
130 
131  return false;
132  }*/
133 
134  $value = $pre_value;
135 
136  if (trim($value) != "") {
137  switch ($dir) {
138  case "width": $this->setWidth($value); break;
139  case "height": $this->setHeight($value); break;
140  }
141  }
142  }
143 
144  return true;
145  }
146 
150  public function insert($a_tpl)
151  {
152  $lng = $this->lng;
153 
154  $tpl = new ilTemplate("tpl.prop_width_height.html", true, true, "Services/MediaObjects");
155 
156  $wh_ratio = 0;
157  if ((int) $this->getHeight() > 0) {
158  $wh_ratio = (int) $this->getWidth() / (int) $this->getHeight();
159  }
160  if ($this->getSupportConstraintsProps() && $wh_ratio > 0) {
161  $tpl->setCurrentBlock("cs_prop");
162  $tpl->setVariable("TXT_CONSTR_PROP", $lng->txt("cont_constrain_proportions"));
163  $tpl->setVariable("CS_POST_VAR", $this->getPostVar());
164  if ($this->getConstrainProportions()) {
165  $tpl->setVariable("CHECKED", 'checked="checked"');
166  }
167  $tpl->setVariable("WH_RATIO", str_replace(",", ".", round($wh_ratio, 6)));
168  $tpl->parseCurrentBlock();
169  }
170 
171  foreach ($this->dirs as $dir) {
172  switch ($dir) {
173  case "width": $value = strtolower(trim($this->getWidth())); break;
174  case "height": $value = strtolower(trim($this->getHeight())); break;
175  }
176  $tpl->setVariable("VAL_" . strtoupper($dir), $value);
177  }
178 
179  $tpl->setVariable("POST_VAR", $this->getPostVar());
180 
181 
182  $a_tpl->setCurrentBlock("prop_generic");
183  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
184  $a_tpl->parseCurrentBlock();
185 
186  $GLOBALS["tpl"]->addJavascript("./Services/MediaObjects/js/ServiceMediaObjectPropWidthHeight.js");
187  }
188 
194  public function setValueByArray($a_values)
195  {
197  //var_dump($a_values[$this->getPostVar()]);
198  $this->setWidth($a_values[$this->getPostVar()]["width"]);
199  $this->setHeight($a_values[$this->getPostVar()]["height"]);
200  $this->setConstrainProportions($a_values[$this->getPostVar()]["constr_prop"]);
201  }
202 }
getConstrainProportions()
Get Constrain Proportions.
getPostVar()
Get Post Variable.
setConstrainProportions($a_constrainproportions)
Set Constrain Proportions.
setHeight($a_height)
Set Height.
user()
Definition: user.php:4
checkInput()
Check input, strip slashes etc.
setType($a_type)
Set Type.
__construct($a_title="", $a_postvar="")
Constructor.
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
setValueByArray($a_values)
Set value by array.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
This class represents a width/height item in a property form.
insert($a_tpl)
Insert property html.
This class represents a property in a property form.
__construct(Container $dic, ilPlugin $plugin)
$ilUser
Definition: imgupload.php:18
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$_POST["username"]