ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilWidthHeightInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 {
33  protected $value;
34 
41  function __construct($a_title = "", $a_postvar = "")
42  {
43  parent::__construct($a_title, $a_postvar);
44  $this->setType("width_height");
45  $this->dirs = array("width", "height");
46  }
47 
53  function setWidth($a_width)
54  {
55  $this->width = $a_width;
56  }
57 
63  function getWidth()
64  {
65  return $this->width;
66  }
67 
73  function setHeight($a_height)
74  {
75  $this->height = $a_height;
76  }
77 
83  function getHeight()
84  {
85  return $this->height;
86  }
87 
93  function setConstrainProportions($a_constrainproportions)
94  {
95  $this->constrainproportions = $a_constrainproportions;
96  }
97 
104  {
105  return $this->constrainproportions;
106  }
107 
113  function checkInput()
114  {
115  global $lng;
116 
117  foreach ($this->dirs as $dir)
118  {
119  $pre_value = $_POST[$this->getPostVar()][$dir]["pre_value"] =
120  ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["pre_value"]);
121 
122  /*
123  if ($this->getRequired() && trim($num_value) == "")
124  {
125  $this->setAlert($lng->txt("msg_input_is_required"));
126 
127  return false;
128  }*/
129 
130  $value = $pre_value;
131 
132  if (trim($value) != "")
133  {
134  switch ($dir)
135  {
136  case "width": $this->setWidth($value); break;
137  case "height": $this->setHeight($value); break;
138  }
139  }
140 
141  }
142 
143  return true;
144  }
145 
149  function insert($a_tpl)
150  {
151  global $lng;
152 
153  $tpl = new ilTemplate("tpl.prop_width_height.html", true, true, "Services/MediaObjects");
154 
155  foreach ($this->dirs as $dir)
156  {
157  switch($dir)
158  {
159  case "width": $value = strtolower(trim($this->getWidth())); break;
160  case "height": $value = strtolower(trim($this->getHeight())); break;
161  }
162  $tpl->setVariable("VAL_".strtoupper($dir), $value);
163  }
164  if ($this->getConstrainProportions())
165  {
166  $tpl->setVariable("CHECKED", 'checked="checked"');
167  }
168 
169  $tpl->setVariable("POST_VAR", $this->getPostVar());
170  $tpl->setVariable("TXT_CONSTR_PROP", $lng->txt("cont_constrain_proportions"));
171  $wh_ratio = 0;
172  if ((int) $this->getHeight() > 0)
173  {
174  $wh_ratio = (int) $this->getWidth() / (int) $this->getHeight();
175  }
176  $tpl->setVariable("WH_RATIO", round($wh_ratio, 6));
177 
178  $a_tpl->setCurrentBlock("prop_generic");
179  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
180  $a_tpl->parseCurrentBlock();
181 
182  $GLOBALS["tpl"]->addJavascript("./Services/MediaObjects/js/ServiceMediaObjectPropWidthHeight.js");
183  }
184 
190  function setValueByArray($a_values)
191  {
192  global $ilUser;
193 
194  $this->setWidth($a_values[$this->getPostVar()]["width"]);
195  $this->setHeight($a_values[$this->getPostVar()]["height"]);
196  $this->setConstrainProportions($a_values[$this->getPostVar()]["constr_prop"]);
197  }
198 
199 }