ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
5include_once("./Services/Form/classes/class.ilFormPropertyGUI.php");
6
15{
16 protected $value;
17 protected $valid = true;
18
25 public function __construct($a_title = "", $a_postvar = "")
26 {
27 global $DIC;
28
29 $lng = $DIC['lng'];
30
31 $this->lng = $lng;
32 $this->lng->loadLanguageModule("meta");
33
34 parent::__construct($a_title, $a_postvar);
35 $this->setType("typical_learntime");
36 $this->setValue(array(0,0,0,0,0));
37 }
38
44 public function setValue($a_value)
45 {
46 $this->value = $a_value;
47 }
48
54 public function setValueByLOMDuration($a_value)
55 {
56 $this->lom_duration = $a_value;
57 $this->valid = true;
58
59 include_once 'Services/MetaData/classes/class.ilMDUtils.php';
60 $tlt = ilMDUtils::_LOMDurationToArray($a_value);
61
62 if (!$tlt) {
63 $this->setValue(array(0,0,0,0,0));
64 if ($a_value != "") {
65 $this->valid = false;
66 }
67 } else {
68 $this->setValue($tlt);
69 }
70 }
71
77 public function getValue()
78 {
79 return $this->value;
80 }
81
87 public function setValueByArray($a_values)
88 {
89 $this->setValue($a_values[$this->getPostVar()]);
90 }
91
97 public function checkInput()
98 {
99 global $DIC;
100
101 $lng = $DIC['lng'];
102
103 $_POST[$this->getPostVar()][0] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][0]);
104 $_POST[$this->getPostVar()][1] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][1]);
105 $_POST[$this->getPostVar()][2] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][2]);
106 $_POST[$this->getPostVar()][3] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][3]);
107 if (isset($_POST[$this->getPostVar()][4])) {
108 $_POST[$this->getPostVar()][4] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][4]);
109 }
110
111 // check required
112 $v = $_POST[$this->getPostVar()];
113 if ($this->getRequired() && $v[0] == 0 && $v[1] == 0 &&
114 $v[2] == 0 && $v[3] == 0 && (int) $v[4] == 0) {
115 $this->setAlert($lng->txt("msg_input_is_required"));
116 return false;
117 }
118
119 return true;
120 }
121
122 public function __buildMonthsSelect($sel_month)
123 {
124 for ($i = 0;$i <= 24;$i++) {
125 $options[$i] = sprintf('%02d', $i);
126 }
127 return ilUtil::formSelect($sel_month, $this->getPostVar() . '[mo]', $options, false, true);
128 }
129
130
131 public function __buildDaysSelect($sel_day)
132 {
133 for ($i = 0;$i <= 31;$i++) {
134 $options[$i] = sprintf('%02d', $i);
135 }
136 return ilUtil::formSelect($sel_day, $this->getPostVar() . '[d]', $options, false, true);
137 }
138
142 public function insert(&$a_tpl)
143 {
144 $ttpl = new ilTemplate("tpl.prop_typical_learning_time.html", true, true, "Services/MetaData");
145 $val = $this->getValue();
146
147 $ttpl->setVariable("TXT_MONTH", $this->lng->txt('md_months'));
148 $ttpl->setVariable("SEL_MONTHS", $this->__buildMonthsSelect($val[0]));
149 $ttpl->setVariable("SEL_DAYS", $this->__buildDaysSelect($val[1]));
150
151 $ttpl->setVariable("TXT_DAYS", $this->lng->txt('md_days'));
152 $ttpl->setVariable("TXT_TIME", $this->lng->txt('md_time'));
153
154 $ttpl->setVariable("SEL_TLT", ilUtil::makeTimeSelect(
155 $this->getPostVar(),
156 $val[4] ? false : true,
157 $val[2],
158 $val[3],
159 $val[4],
160 false
161 ));
162 $ttpl->setVariable("TLT_HINT", $tlt[4] ? '(hh:mm:ss)' : '(hh:mm)');
163
164 if (!$this->valid) {
165 $ttpl->setCurrentBlock("tlt_not_valid");
166 $ttpl->setVariable("TXT_CURRENT_VAL", $this->lng->txt('meta_current_value'));
167 $ttpl->setVariable("TLT", $this->lom_duration);
168 $ttpl->setVariable("INFO_TLT_NOT_VALID", $this->lng->txt('meta_info_tlt_not_valid'));
169 $ttpl->parseCurrentBlock();
170 }
171
172 $a_tpl->setCurrentBlock("prop_generic");
173 $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
174 $a_tpl->parseCurrentBlock();
175 }
176}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a property in a property form.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
static _LOMDurationToArray($a_string)
LOM datatype duration is a string like P2M4DT7H18M2S (2 months 4 days 7 hours 18 minutes 2 seconds) T...
special template class to simplify handling of ITX/PEAR
This class represents a typical learning time property in a property form.
setValueByLOMDuration($a_value)
Set by LOM duration.
checkInput()
Check input, strip slashes etc.
__construct($a_title="", $a_postvar="")
Constructor.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static formSelect( $selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
static makeTimeSelect($prefix, $short=true, $hour="", $minute="", $second="", $a_use_default=true, $a_further_options=array())
Creates a combination of HTML selects for time inputs.
$i
Definition: disco.tpl.php:19
global $DIC
Definition: saml.php:7