ILIAS  release_8 Revision v8.24
class.ilTypicalLearningTimeInputGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
28{
29 public const POST_NAME_MONTH = 'mo';
30 public const POST_NAME_DAY = 'd';
31 public const POST_NAME_HOUR = 'h';
32 public const POST_NAME_MINUTE = 'm';
33 public const POST_NAME_SECOND = 's';
34
35 protected array $value;
36 protected bool $valid = true;
37 protected string $lom_duration = '';
38 protected bool $show_seconds = false;
39
40 public function __construct(string $a_title = "", string $a_postvar = "")
41 {
42 parent::__construct($a_title, $a_postvar);
43
44 $this->lng->loadLanguageModule("meta");
45 $this->setType("typical_learntime");
46 $this->setValue(array(0, 0, 0, 0, 0));
47 }
48
49 public function setValue(array $a_value): void
50 {
51 $this->value = $a_value;
52 }
53
54 public function setValueByLOMDuration(string $a_value): void
55 {
56 $this->lom_duration = $a_value;
57 $this->valid = true;
58
59 $tlt = ilMDUtils::_LOMDurationToArray($a_value);
60
61 if (!$tlt) {
62 $this->setValue(array(0, 0, 0, 0, 0));
63 if ($a_value !== "") {
64 $this->valid = false;
65 }
66 } else {
67 $this->setValue($tlt);
68 }
69 }
70
71 public function setShowSeconds(bool $status): void
72 {
73 $this->show_seconds = $status;
74 }
75
76 public function getShowSeconds(): bool
77 {
79 }
80
84 public function getValue(): array
85 {
86 return $this->value;
87 }
88
89 public function setValueByArray(array $a_values): void
90 {
91 $this->setValue($a_values[$this->getPostVar()]);
92 }
93
94 protected function getInputFromPost(string $post_name): int
95 {
96 if ($this->http->wrapper()->post()->has($this->getPostVar() . '[' . $post_name . ']')) {
97 return $this->http->wrapper()->post()->retrieve(
98 $this->getPostVar() . '[' . $post_name . ']',
99 $this->refinery->kindlyTo()->int()
100 );
101 }
102 return 0;
103 }
104
105 public function checkInput(): bool
106 {
107 $counter = 0;
108 $required_fullfilled = false;
109 foreach ([self::POST_NAME_MONTH, self::POST_NAME_DAY, self::POST_NAME_HOUR, self::POST_NAME_MINUTE, self::POST_NAME_SECOND] as $post_name) {
110 $value = $this->getInputFromPost($post_name);
111 if ($value > 0) {
112 $required_fullfilled = true;
113 }
114 $this->value[$counter++] = $this->getInputFromPost($post_name);
115 }
116 if ($this->getRequired() && !$required_fullfilled) {
117 $this->setAlert($this->lng->txt("msg_input_is_required"));
118 return false;
119 }
120 return true;
121 }
122
123 public function __buildMonthsSelect(string $sel_month): string
124 {
125 $options = [];
126 for ($i = 0; $i <= 24; $i++) {
127 $options[$i] = sprintf('%02d', $i);
128 }
129 return ilLegacyFormElementsUtil::formSelect($sel_month, $this->getPostVar() . '[mo]', $options, false, true);
130 }
131
132 public function __buildDaysSelect(string $sel_day): string
133 {
134 $options = [];
135 for ($i = 0; $i <= 31; $i++) {
136 $options[$i] = sprintf('%02d', $i);
137 }
138 return ilLegacyFormElementsUtil::formSelect($sel_day, $this->getPostVar() . '[d]', $options, false, true);
139 }
140
141 public function insert(ilTemplate $a_tpl): void
142 {
143 $ttpl = new ilTemplate("tpl.prop_typical_learning_time.html", true, true, "Services/MetaData");
144 $val = $this->getValue();
145
146 $ttpl->setVariable("TXT_MONTH", $this->lng->txt('md_months'));
147 $ttpl->setVariable("SEL_MONTHS", $this->__buildMonthsSelect((string) ($val[0] ?? "")));
148 $ttpl->setVariable("SEL_DAYS", $this->__buildDaysSelect((string) ($val[1] ?? "")));
149
150 $ttpl->setVariable("TXT_DAYS", $this->lng->txt('md_days'));
151 $ttpl->setVariable("TXT_TIME", $this->lng->txt('md_time'));
152
153 $ttpl->setVariable(
154 "SEL_TLT",
156 $this->getPostVar(),
157 !($val[4] ?? 0),
158 (int) ($val[2] ?? 0),
159 (int) ($val[3] ?? 0),
160 (int) ($val[4] ?? 0),
161 false
162 )
163 );
164 $ttpl->setVariable("TLT_HINT", ($val[4] ?? false) ? '(hh:mm:ss)' : '(hh:mm)');
165
166 if (!$this->valid) {
167 $ttpl->setCurrentBlock("tlt_not_valid");
168 $ttpl->setVariable("TXT_CURRENT_VAL", $this->lng->txt('meta_current_value'));
169 $ttpl->setVariable("TLT", $this->lom_duration);
170 $ttpl->setVariable("INFO_TLT_NOT_VALID", $this->lng->txt('meta_info_tlt_not_valid'));
171 $ttpl->parseCurrentBlock();
172 }
173
174 $a_tpl->setCurrentBlock("prop_generic");
175 $a_tpl->setVariable("PROP_GENERIC", $ttpl->get());
176 $a_tpl->parseCurrentBlock();
177 }
178}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
This class represents a property in a property form.
static makeTimeSelect(string $prefix, bool $short=true, int $hour=0, int $minute=0, int $second=0, bool $a_use_default=true, array $a_further_options=[])
Creates a combination of HTML selects for time inputs.
static formSelect( $selected, string $varname, array $options, bool $multiple=false, bool $direct_text=false, int $size=0, string $style_class="", array $attribs=[], bool $disabled=false)
Builds a select form field with options and shows the selected option first.
static _LOMDurationToArray(string $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
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(string $a_title="", string $a_postvar="")
$i
Definition: metadata.php:41
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc