ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $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 public function setValue($a_value)
43 {
44 $this->value = $a_value;
45 }
46
52 public 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 $this->setValue(array(0,0,0,0,0));
62 if ($a_value != "") {
63 $this->valid = false;
64 }
65 } else {
66 $this->setValue($tlt);
67 }
68 }
69
75 public function getValue()
76 {
77 return $this->value;
78 }
79
85 public function setValueByArray($a_values)
86 {
87 $this->setValue($a_values[$this->getPostVar()]);
88 }
89
95 public function checkInput()
96 {
97 global $lng;
98
99 $_POST[$this->getPostVar()][0] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][0]);
100 $_POST[$this->getPostVar()][1] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][1]);
101 $_POST[$this->getPostVar()][2] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][2]);
102 $_POST[$this->getPostVar()][3] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][3]);
103 if (isset($_POST[$this->getPostVar()][4])) {
104 $_POST[$this->getPostVar()][4] = (int) ilUtil::stripSlashes($_POST[$this->getPostVar()][4]);
105 }
106
107 // check required
108 $v = $_POST[$this->getPostVar()];
109 if ($this->getRequired() && $v[0] == 0 && $v[1] == 0 &&
110 $v[2] == 0 && $v[3] == 0 && (int) $v[4] == 0) {
111 $this->setAlert($lng->txt("msg_input_is_required"));
112 return false;
113 }
114
115 return true;
116 }
117
118 public function __buildMonthsSelect($sel_month)
119 {
120 for ($i = 0;$i <= 24;$i++) {
121 $options[$i] = sprintf('%02d', $i);
122 }
123 return ilUtil::formSelect($sel_month, $this->getPostVar() . '[mo]', $options, false, true);
124 }
125
126
127 public function __buildDaysSelect($sel_day)
128 {
129 for ($i = 0;$i <= 31;$i++) {
130 $options[$i] = sprintf('%02d', $i);
131 }
132 return ilUtil::formSelect($sel_day, $this->getPostVar() . '[d]', $options, false, true);
133 }
134
138 public function insert(&$a_tpl)
139 {
140 $ttpl = new ilTemplate("tpl.prop_typical_learning_time.html", true, true, "Services/MetaData");
141 $val = $this->getValue();
142
143 $ttpl->setVariable("TXT_MONTH", $this->lng->txt('md_months'));
144 $ttpl->setVariable("SEL_MONTHS", $this->__buildMonthsSelect($val[0]));
145 $ttpl->setVariable("SEL_DAYS", $this->__buildDaysSelect($val[1]));
146
147 $ttpl->setVariable("TXT_DAYS", $this->lng->txt('md_days'));
148 $ttpl->setVariable("TXT_TIME", $this->lng->txt('md_time'));
149
150 $ttpl->setVariable("SEL_TLT", ilUtil::makeTimeSelect(
151 $this->getPostVar(),
152 $val[4] ? false : true,
153 $val[2],
154 $val[3],
155 $val[4],
156 false
157 ));
158 $ttpl->setVariable("TLT_HINT", $tlt[4] ? '(hh:mm:ss)' : '(hh:mm)');
159
160 if (!$this->valid) {
161 $ttpl->setCurrentBlock("tlt_not_valid");
162 $ttpl->setVariable("TXT_CURRENT_VAL", $this->lng->txt('meta_current_value'));
163 $ttpl->setVariable("TLT", $this->lom_duration);
164 $ttpl->setVariable("INFO_TLT_NOT_VALID", $this->lng->txt('meta_info_tlt_not_valid'));
165 $ttpl->parseCurrentBlock();
166 }
167
168 $a_tpl->setCurrentBlock("prop_generic");
169 $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
170 $a_tpl->parseCurrentBlock();
171 }
172}
sprintf('%.4f', $callTime)
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_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