ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTypicalLearningTimeInputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Form/classes/class.ilFormPropertyGUI.php");
6 
15 {
16  protected $value;
17  protected $valid = true;
18 
25  function __construct($a_title = "", $a_postvar = "")
26  {
27  global $lng;
28 
29  $this->lng = $lng;
30  $this->lng->loadLanguageModule("meta");
31 
32  parent::__construct($a_title, $a_postvar);
33  $this->setType("typical_learntime");
34  $this->setValue(array(0,0,0,0,0));
35  }
36 
42  function setValue($a_value)
43  {
44  $this->value = $a_value;
45  }
46 
52  function setValueByLOMDuration($a_value)
53  {
54  $this->lom_duration = $a_value;
55  $this->valid = true;
56 
57  include_once 'Services/MetaData/classes/class.ilMDUtils.php';
58  $tlt = ilMDUtils::_LOMDurationToArray($a_value);
59 
60  if(!$tlt)
61  {
62  $this->setValue(array(0,0,0,0,0));
63  if ($a_value != "")
64  {
65  $this->valid = false;
66  }
67  }
68  else
69  {
70  $this->setValue($tlt);
71  }
72 
73  }
74 
80  function getValue()
81  {
82  return $this->value;
83  }
84 
90  function setValueByArray($a_values)
91  {
92  $this->setValue($a_values[$this->getPostVar()]);
93  }
94 
100  function checkInput()
101  {
102  global $lng;
103 
104  $_POST[$this->getPostVar()][0] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][0]);
105  $_POST[$this->getPostVar()][1] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][1]);
106  $_POST[$this->getPostVar()][2] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][2]);
107  $_POST[$this->getPostVar()][3] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][3]);
108  if (isset($_POST[$this->getPostVar()][4]))
109  {
110  $_POST[$this->getPostVar()][4] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][4]);
111  }
112 
113  // check required
114  $v = $_POST[$this->getPostVar()];
115  if ($this->getRequired() && $v[0] == 0 && $v[1] == 0 &&
116  $v[2] == 0 && $v[3] == 0 && (int) $v[4] == 0)
117  {
118  $this->setAlert($lng->txt("msg_input_is_required"));
119  return false;
120  }
121 
122  return true;
123  }
124 
125  function __buildMonthsSelect($sel_month)
126  {
127  for($i = 0;$i <= 24;$i++)
128  {
129  $options[$i] = sprintf('%02d',$i);
130  }
131  return ilUtil::formSelect($sel_month,$this->getPostVar().'[mo]',$options,false,true);
132  }
133 
134 
135  function __buildDaysSelect($sel_day)
136  {
137  for($i = 0;$i <= 31;$i++)
138  {
139  $options[$i] = sprintf('%02d',$i);
140  }
141  return ilUtil::formSelect($sel_day, $this->getPostVar().'[d]',$options,false,true);
142  }
143 
147  function insert(&$a_tpl)
148  {
149  $ttpl = new ilTemplate("tpl.prop_typical_learning_time.html", true, true, "Services/MetaData");
150  $val = $this->getValue();
151 
152  $ttpl->setVariable("TXT_MONTH",$this->lng->txt('md_months'));
153  $ttpl->setVariable("SEL_MONTHS",$this->__buildMonthsSelect($val[0]));
154  $ttpl->setVariable("SEL_DAYS",$this->__buildDaysSelect($val[1]));
155 
156  $ttpl->setVariable("TXT_DAYS",$this->lng->txt('md_days'));
157  $ttpl->setVariable("TXT_TIME",$this->lng->txt('md_time'));
158 
159  $ttpl->setVariable("SEL_TLT",ilUtil::makeTimeSelect($this->getPostVar(),$val[4] ? false : true,
160  $val[2],$val[3],$val[4],
161  false));
162  $ttpl->setVariable("TLT_HINT",$tlt[4] ? '(hh:mm:ss)' : '(hh:mm)');
163 
164  if(!$this->valid)
165  {
166  $ttpl->setCurrentBlock("tlt_not_valid");
167  $ttpl->setVariable("TXT_CURRENT_VAL",$this->lng->txt('meta_current_value'));
168  $ttpl->setVariable("TLT", $this->lom_duration);
169  $ttpl->setVariable("INFO_TLT_NOT_VALID",$this->lng->txt('meta_info_tlt_not_valid'));
170  $ttpl->parseCurrentBlock();
171  }
172 
173  $a_tpl->setCurrentBlock("prop_generic");
174  $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
175  $a_tpl->parseCurrentBlock();
176  }
177 }