ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SurveyMetricQuestionGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 protected function initObject(): void
28 {
29 $this->object = new SurveyMetricQuestion();
30 }
31
32
33 //
34 // EDITOR
35 //
36
37 public function setQuestionTabs(): void
38 {
39 $this->setQuestionTabsForClass("surveymetricquestiongui");
40 }
41
42 protected function addFieldsToEditForm(ilPropertyFormGUI $a_form): void
43 {
44 // subtype
45 $subtype = new ilRadioGroupInputGUI($this->lng->txt("subtype"), "type");
46 $subtype->setRequired(true);
47 $a_form->addItem($subtype);
48
49 // #10652
50 $opt = new ilRadioOption($this->lng->txt('non_ratio'), SurveyMetricQuestion::SUBTYPE_NON_RATIO, $this->lng->txt("metric_subtype_description_interval"));
51 $subtype->addOption($opt);
52
53 // minimum value
54 $minimum1 = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum3");
55 $minimum1->setRequired(false);
56 $minimum1->setSize(6);
57 $opt->addSubItem($minimum1);
58
59 // maximum value
60 $maximum1 = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum3");
61 $maximum1->setRequired(false);
62 $maximum1->setSize(6);
63 $opt->addSubItem($maximum1);
64
65 $opt = new ilRadioOption($this->lng->txt('ratio_non_absolute'), SurveyMetricQuestion::SUBTYPE_RATIO_NON_ABSOLUTE, $this->lng->txt("metric_subtype_description_rationonabsolute"));
66 $subtype->addOption($opt);
67
68 // minimum value
69 $minimum2 = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum4");
70 $minimum2->setRequired(false);
71 $minimum2->setSize(6);
72 $minimum2->setMinValue(0);
73 $opt->addSubItem($minimum2);
74
75 // maximum value
76 $maximum2 = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum4");
77 $maximum2->setRequired(false);
78 $maximum2->setSize(6);
79 $opt->addSubItem($maximum2);
80
81 $opt = new ilRadioOption($this->lng->txt('ratio_absolute'), SurveyMetricQuestion::SUBTYPE_RATIO_ABSOLUTE, $this->lng->txt("metric_subtype_description_ratioabsolute"));
82 $subtype->addOption($opt);
83
84 // minimum value
85 $minimum3 = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum5");
86 $minimum3->setRequired(false);
87 $minimum3->setSize(6);
88 $minimum3->setMinValue(0);
89 $minimum3->setDecimals(0);
90 $opt->addSubItem($minimum3);
91
92 // maximum value
93 $maximum3 = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum5");
94 $maximum3->setDecimals(0);
95 $maximum3->setRequired(false);
96 $maximum3->setSize(6);
97 $opt->addSubItem($maximum3);
98
99
100 // values
101 $subtype->setValue($this->object->getSubtype());
102
103 switch ($this->object->getSubtype()) {
105 $minimum1->setValue($this->object->getMinimum());
106 $maximum1->setValue($this->object->getMaximum());
107 break;
108
110 $minimum2->setValue($this->object->getMinimum());
111 $maximum2->setValue($this->object->getMaximum());
112 break;
113
115 $minimum3->setValue($this->object->getMinimum());
116 $maximum3->setValue($this->object->getMaximum());
117 break;
118 }
119 }
120
121 protected function importEditFormValues(ilPropertyFormGUI $a_form): void
122 {
123 $type = (int) $a_form->getInput("type");
124 $this->object->setOrientation((int) $a_form->getInput("orientation"));
125 $this->object->setSubtype((int) $type);
126 $min = ($a_form->getInput("minimum" . $type) != "")
127 ? (float) $a_form->getInput("minimum" . $type)
128 : null;
129 $max = ($a_form->getInput("maximum" . $type) != "")
130 ? (float) $a_form->getInput("maximum" . $type)
131 : null;
132 $this->object->setMinimum($min);
133 $this->object->setMaximum($max);
134 }
135
136 public function getParsedAnswers(
137 ?array $a_working_data = null,
138 $a_only_user_anwers = false
139 ): array {
140 $res = array();
141
142 if (is_array($a_working_data)) {
143 $res[] = array("value" => ($a_working_data[0]["value"] ?? null));
144 }
145
146 return $res;
147 }
148
154 public function getPrintView(
155 int $question_title = 1,
156 bool $show_questiontext = true,
157 ?int $survey_id = null,
158 ?array $working_data = null
159 ): string {
160 $user_answer = null;
161 if ($working_data) {
162 $user_answer = $this->getParsedAnswers($working_data);
163 $user_answer = $user_answer[0]["value"];
164 }
165 $template = new ilTemplate("tpl.il_svy_qpl_metric_printview.html", true, true, "components/ILIAS/SurveyQuestionPool");
166 $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
167
168 if ($show_questiontext) {
169 $this->outQuestionText($template);
170 }
171 if ($question_title) {
172 $template->setVariable("QUESTION_TITLE", $this->getPrintViewQuestionTitle($question_title));
173 }
174 $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
175 $template->setVariable("QUESTION_ID", $this->object->getId());
176
177 if (!is_array($working_data) || !trim((string) $user_answer)) {
178 $len = 10;
179 $solution_text = str_repeat("&#160;", 10);
180 } else {
181 $solution_text = $user_answer;
182 }
183 $template->setVariable("TEXT_SOLUTION", $solution_text);
184
185 $template->parseCurrentBlock();
186 return $template->get();
187 }
188
189
190 //
191 // EXECUTION
192 //
193
194 public function getWorkingForm(
195 ?array $working_data = null,
196 int $question_title = 1,
197 bool $show_questiontext = true,
198 string $error_message = "",
199 ?int $survey_id = null,
200 bool $compress_view = false
201 ): string {
202 $template = new ilTemplate("tpl.il_svy_out_metric.html", true, true, "components/ILIAS/SurveyQuestionPool");
203 $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
204
205 if ($show_questiontext) {
206 $this->outQuestionText($template);
207 }
208 $template->setVariable("QUESTION_TITLE", $this->getQuestionTitle($question_title));
209 $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
210 $template->setVariable("QUESTION_ID", $this->object->getId());
211 if (is_array($working_data)) {
212 $template->setVariable("VALUE_METRIC", $working_data[0]["value"] ?? "");
213 }
214
215 $template->setVariable("INPUT_SIZE", 10);
216
217 if (strcmp($error_message, "") !== 0) {
218 $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
219 }
220 $template->parseCurrentBlock();
221 return $template->get();
222 }
223}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addFieldsToEditForm(ilPropertyFormGUI $a_form)
getParsedAnswers(?array $a_working_data=null, $a_only_user_anwers=false)
importEditFormValues(ilPropertyFormGUI $a_form)
getPrintView(int $question_title=1, bool $show_questiontext=true, ?int $survey_id=null, ?array $working_data=null)
Creates a HTML representation of the question Creates a HTML representation of the question.
getWorkingForm(?array $working_data=null, int $question_title=1, bool $show_questiontext=true, string $error_message="", ?int $survey_id=null, bool $compress_view=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Basic class for all survey question types The SurveyQuestionGUI class defines and encapsulates basic ...
setQuestionTabsForClass(string $guiclass)
return true
This class represents a number property in a property form.
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
This class represents a property in a property form.
This class represents an option in a radio group.
special template class to simplify handling of ITX/PEAR
$res
Definition: ltiservices.php:69