47 $orientation->addOption(
new ilRadioOption($this->
lng->txt(
'horizontal'), 1));
52 $minanswers->setValue(1);
53 $minanswers->setOptionTitle($this->
lng->txt(
"use_min_answers_option"));
54 $minanswers->setRequired(
false);
58 $nranswers->setDecimals(0);
59 $nranswers->setRequired(
false);
60 $nranswers->setMinValue(1);
61 $minanswers->addSubItem($nranswers);
65 $nrmaxanswers->setDecimals(0);
66 $nrmaxanswers->setRequired(
false);
67 $nrmaxanswers->setMinValue(1);
68 $minanswers->addSubItem($nrmaxanswers);
75 $answers->setAllowMove(
true);
76 $answers->setShowWizard(
false);
77 $answers->setUseOtherAnswer(
true);
78 $answers->setShowNeutralCategory(
true);
79 $answers->setNeutralCategoryTitle($this->
lng->txt(
'svy_neutral_answer'));
80 $answers->setDisabledScale(
false);
85 $orientation->setValue($this->
object->getOrientation());
86 $minanswers->setChecked((
bool) $this->
object->use_min_answers);
87 $nranswers->setValue($this->
object->nr_min_answers);
88 $nrmaxanswers->setValue($this->
object->nr_max_answers);
89 if (!$this->
object->getCategories()->getCategoryCount()) {
90 $this->
object->getCategories()->addCategory(
"");
92 $answers->setValues($this->
object->getCategories());
98 if ($a_form->
getInput(
"use_min_answers")) {
101 $answers = $this->request->getAnswers();
102 foreach ($answers[
'answer'] as $key => $value) {
103 if (strlen($value ??
"")) {
107 if ($this->request->getNeutral() !==
"") {
114 $min_anwers = $a_form->
getInput(
"nr_min_answers");
115 $max_anwers = $a_form->
getInput(
"nr_max_answers");
118 $min_anwers > $cnt_answers) {
119 $a_form->
getItemByPostVar(
"nr_min_answers")->setAlert($this->
lng->txt(
'err_minvalueganswers'));
122 if ($max_anwers > 0 &&
123 ($max_anwers > $cnt_answers || $max_anwers < $min_anwers)) {
124 $a_form->
getItemByPostVar(
"nr_max_answers")->setAlert($this->
lng->txt(
'err_maxvaluegeminvalue'));
129 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
135 $this->
object->setOrientation($a_form->
getInput(
"orientation"));
136 $this->
object->use_other_answer = ($a_form->
getInput(
'use_other_answer')) ? 1 : 0;
137 $this->
object->other_answer_label = $this->
object->use_other_answer ? $a_form->
getInput(
'other_answer_label') :
"";
138 $this->
object->use_min_answers = (bool) $a_form->
getInput(
'use_min_answers');
139 $this->
object->nr_min_answers = ($a_form->
getInput(
'nr_min_answers') > 0) ? $a_form->
getInput(
'nr_min_answers') :
"";
140 $this->
object->nr_max_answers = ($a_form->
getInput(
'nr_max_answers') > 0) ? $a_form->
getInput(
'nr_max_answers') :
"";
141 $this->
object->label = $a_form->
getInput(
'label');
143 $this->
object->categories->flushCategories();
145 $answers = $this->request->getAnswers();
146 foreach ($answers[
'answer'] as $key => $value) {
147 if (strlen($value ??
"")) {
148 $this->
object->getCategories()->addCategory($value, $answers[
'other'][$key] ?? 0, 0,
null, $answers[
'scale'][$key]);
151 if ($this->request->getNeutral() !==
"") {
152 $this->
object->getCategories()->addCategory($this->request->getNeutral(), 0, 1,
null, $this->request->getNeutralScale());
157 ?array $a_working_data =
null,
158 $a_only_user_anwers =
false 160 if (is_array($a_working_data)) {
161 $user_answers = $a_working_data;
165 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++) {
166 $cat = $this->
object->categories->getCategory($i);
167 $value = ($cat->scale) ? ($cat->scale - 1) : $i;
169 $checked =
"unchecked";
171 if (is_array($a_working_data)) {
172 foreach ($user_answers as $user_answer) {
173 if ($value == $user_answer[
"value"]) {
174 $checked =
"checked";
175 if ($user_answer[
"textanswer"]) {
176 $text = $user_answer[
"textanswer"];
184 $idx = $cat->other .
"_" . $value;
186 if (!$a_only_user_anwers || $checked ===
"checked") {
187 $options[$idx] = array(
189 ,
"title" => trim($cat->title)
190 ,
"other" => (
bool) $cat->other
191 ,
"checked" => $checked
192 ,
"textanswer" => $text
199 return array_values($options);
203 int $question_title = 1,
204 bool $show_questiontext =
true,
205 ?
int $survey_id =
null,
206 ?array $working_data =
null 210 $template =
new ilTemplate(
"tpl.il_svy_qpl_mc_printview.html",
true,
true,
"components/ILIAS/SurveyQuestionPool");
211 switch ($this->
object->getOrientation()) {
214 foreach ($options as $option) {
215 if ($option[
"other"]) {
216 $template->setCurrentBlock(
"other_row");
218 $template->setVariable(
"ALT_CHECKBOX", $this->
lng->txt($option[
"checked"]));
219 $template->setVariable(
"TITLE_CHECKBOX", $this->
lng->txt($option[
"checked"]));
220 $template->setVariable(
224 $template->setVariable(
"OTHER_ANSWER", $option[
"textanswer"]
228 $template->setCurrentBlock(
"mc_row");
230 $template->setVariable(
"ALT_CHECKBOX", $this->
lng->txt($option[
"checked"]));
231 $template->setVariable(
"TITLE_CHECKBOX", $this->
lng->txt($option[
"checked"]));
234 $template->parseCurrentBlock();
239 foreach ($options as $option) {
240 $template->setCurrentBlock(
"checkbox_col");
242 $template->setVariable(
"ALT_CHECKBOX", $this->
lng->txt($option[
"checked"]));
243 $template->setVariable(
"TITLE_CHECKBOX", $this->
lng->txt($option[
"checked"]));
244 $template->parseCurrentBlock();
246 foreach ($options as $option) {
247 if ($option[
"other"]) {
248 $template->setCurrentBlock(
"other_text_col");
249 $template->setVariable(
253 $template->setVariable(
"OTHER_ANSWER", $option[
"textanswer"]
257 $template->setCurrentBlock(
"text_col");
260 $template->parseCurrentBlock();
265 if ($this->
object->use_min_answers) {
266 $template->setCurrentBlock(
'min_max_msg');
267 if ($this->
object->nr_min_answers > 0 && $this->object->nr_max_answers > 0) {
268 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->
lng->txt(
'msg_min_max_nr_answers'), $this->
object->nr_min_answers, $this->
object->nr_max_answers));
269 } elseif ($this->
object->nr_min_answers > 0) {
270 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->
lng->txt(
'msg_min_nr_answers'), $this->
object->nr_min_answers));
271 } elseif ($this->
object->nr_max_answers > 0) {
272 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->
lng->txt(
'msg_max_nr_answers'), $this->
object->nr_max_answers));
274 $template->parseCurrentBlock();
276 if ($show_questiontext) {
279 if ($question_title) {
282 $template->parseCurrentBlock();
283 return $template->get();
295 ?array $working_data =
null,
296 int $question_title = 1,
297 bool $show_questiontext =
true,
298 string $error_message =
"",
299 ?
int $survey_id =
null,
300 bool $compress_view =
false 302 $template =
new ilTemplate(
"tpl.il_svy_out_mc.html",
true,
true,
"components/ILIAS/SurveyQuestionPool");
303 switch ($this->
object->getOrientation()) {
306 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++) {
307 $cat = $this->
object->categories->getCategory($i);
309 $template->setCurrentBlock(
"other_row");
310 if (strlen($cat->title ??
"")) {
311 $template->setVariable(
"OTHER_LABEL", $cat->title);
313 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
314 $template->setVariable(
"QUESTION_ID", $this->
object->getId());
315 if (is_array($working_data)) {
316 foreach ($working_data as $value) {
317 if (strlen($value[
"value"] ??
"")) {
318 if ($value[
"value"] == $cat->scale - 1) {
322 if (!($value[
'uncheck'] ??
false)) {
323 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
330 $template->setCurrentBlock(
"mc_row");
332 $template->setVariable(
'ROWCLASS',
' class="neutral"');
335 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
336 $template->setVariable(
"QUESTION_ID", $this->
object->getId());
337 if (is_array($working_data)) {
338 foreach ($working_data as $value) {
339 if (strlen($value[
"value"] ??
"")) {
340 if ($value[
"value"] == $cat->scale - 1) {
341 if (!($value[
'uncheck'] ??
false)) {
342 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
349 $template->parseCurrentBlock();
350 $template->touchBlock(
'outer_row');
357 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++) {
358 $cat = $this->
object->categories->getCategory($i);
361 $template->setCurrentBlock(
"checkbox_col");
363 $template->setVariable(
'COLCLASS',
' neutral');
365 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
366 $template->setVariable(
"QUESTION_ID", $this->
object->getId());
367 if (is_array($working_data)) {
368 foreach ($working_data as $value) {
369 if (strlen($value[
"value"] ??
"")) {
370 if ($value[
"value"] == $cat->scale - 1) {
371 if (!($value[
'uncheck'] ??
false)) {
372 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
378 $template->parseCurrentBlock();
382 $template->setCurrentBlock(
"text_other_col");
383 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
384 $template->setVariable(
"QUESTION_ID", $this->
object->getId());
385 if (strlen($cat->title ??
"")) {
386 $template->setVariable(
"OTHER_LABEL", $cat->title);
388 if (is_array($working_data)) {
389 foreach ($working_data as $value) {
390 if (strlen($value[
"value"] ??
"")) {
391 if ($value[
"value"] == $cat->scale - 1) {
402 $template->setCurrentBlock(
"text_col");
404 $template->setVariable(
'COLCLASS',
' neutral');
406 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
408 $template->setVariable(
"QUESTION_ID", $this->
object->getId());
410 $template->parseCurrentBlock();
411 $template->touchBlock(
'text_outer_col');
416 $template->setCurrentBlock(
"question_data");
417 if ($this->
object->use_min_answers) {
418 $template->setCurrentBlock(
'min_max_msg');
419 if ($this->
object->nr_min_answers > 0 && $this->object->nr_max_answers > 0) {
420 if ($this->
object->nr_min_answers == $this->object->nr_max_answers) {
421 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->
lng->txt(
'msg_min_max_exact_answers'), $this->
object->nr_min_answers));
423 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->
lng->txt(
'msg_min_max_nr_answers'), $this->
object->nr_min_answers, $this->
object->nr_max_answers));
425 } elseif ($this->
object->nr_min_answers > 0) {
426 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->
lng->txt(
'msg_min_nr_answers'), $this->
object->nr_min_answers));
427 } elseif ($this->
object->nr_max_answers > 0) {
428 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->
lng->txt(
'msg_max_nr_answers'), $this->
object->nr_max_answers));
430 $template->parseCurrentBlock();
432 if (strcmp($error_message,
"") !== 0) {
433 $template->setVariable(
"ERROR_MESSAGE",
"<p class=\"warning\">$error_message</p>");
435 if ($show_questiontext) {
438 $template->setVariable(
"QUESTION_TITLE", $this->
getQuestionTitle($question_title));
439 $template->parseCurrentBlock();
440 return $template->get();
This class represents an option in a radio group.
getQuestionTitle(int $question_title_mode=1)
getPrintViewQuestionTitle(int $question_title=1)
getPrintView(int $question_title=1, bool $show_questiontext=true, ?int $survey_id=null, ?array $working_data=null)
outQuestionText(ilTemplate $template)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setQuestionTabsForClass(string $guiclass)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static getHtmlPath(string $relative_path)
get url of path
validateEditForm(ilPropertyFormGUI $a_form)
importEditFormValues(ilPropertyFormGUI $a_form)
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 ...
getWorkingForm(?array $working_data=null, int $question_title=1, bool $show_questiontext=true, string $error_message="", ?int $survey_id=null, bool $compress_view=false)
Creates the question output form for the learner.
addFieldsToEditForm(ilPropertyFormGUI $a_form)
getParsedAnswers(?array $a_working_data=null, $a_only_user_anwers=false)