ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SurveyTextQuestionGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 protected function initObject(): void
28 {
29 $this->object = new SurveyTextQuestion();
30 }
31
32
33 //
34 // EDITOR
35 //
36
37 public function setQuestionTabs(): void
38 {
39 $this->setQuestionTabsForClass("surveytextquestiongui");
40 }
41
42 protected function addFieldsToEditForm(ilPropertyFormGUI $a_form): void
43 {
44 // maximum number of characters
45 $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
46 $maxchars->setRequired(false);
47 $maxchars->setSize(5);
48 $maxchars->setDecimals(0);
49 $a_form->addItem($maxchars);
50
51 // values
52 if ($this->object->getMaxChars() > 0) {
53 $maxchars->setValue($this->object->getMaxChars());
54 }
55 }
56
57 protected function importEditFormValues(ilPropertyFormGUI $a_form): void
58 {
59 $max = $a_form->getInput("maxchars");
60 $this->object->setMaxChars((int) $max);
61 }
62
63 public function getParsedAnswers(
64 ?array $a_working_data = null,
65 $a_only_user_anwers = false
66 ): array {
67 $res = array();
68 if (is_array($a_working_data) && isset($a_working_data[0])) {
69 $res[] = array("textanswer" => trim($a_working_data[0]["textanswer"] ?? ""));
70 }
71
72 return $res;
73 }
74
75 public function getPrintView(
76 int $question_title = 1,
77 bool $show_questiontext = true,
78 ?int $survey_id = null,
79 ?array $working_data = null
80 ): string {
81 $user_answer = null;
82 if ($working_data) {
83 $user_answer = $this->getParsedAnswers($working_data);
84 $user_answer = $user_answer[0]["textanswer"];
85 }
86
87 $template = new ilTemplate("tpl.il_svy_qpl_text_printview.html", true, true, "components/ILIAS/SurveyQuestionPool");
88 if ($show_questiontext) {
89 $this->outQuestionText($template);
90 }
91 if ($question_title) {
92 $template->setVariable("QUESTION_TITLE", $this->getPrintViewQuestionTitle($question_title));
93 }
94 $template->setVariable("QUESTION_ID", $this->object->getId());
95 $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
96 if (is_array($working_data) && trim($user_answer)) {
97 $template->setVariable("TEXT", nl2br($user_answer));
98 } else {
99 $template->setVariable("TEXTBOX_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("textbox.png")));
100 $template->setVariable("TEXTBOX", $this->lng->txt("textbox"));
101 }
102 if ($this->object->getMaxChars()) {
103 $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
104 }
105 return $template->get();
106 }
107
108
109 //
110 // EXECUTION
111 //
112
116 public function getWorkingForm(
117 ?array $working_data = null,
118 int $question_title = 1,
119 bool $show_questiontext = true,
120 string $error_message = "",
121 ?int $survey_id = null,
122 bool $compress_view = false
123 ): string {
124 $template = new ilTemplate("tpl.il_svy_out_text.html", true, true, "components/ILIAS/SurveyQuestionPool");
125
126 $template->setCurrentBlock("textarea");
127 if (is_array($working_data) && isset($working_data[0]["textanswer"])) {
128 $template->setVariable("VALUE_ANSWER", ilLegacyFormElementsUtil::prepareFormOutput($working_data[0]["textanswer"]));
129 }
130 $template->setVariable("QUESTION_ID", $this->object->getId());
131
132 $template->parseCurrentBlock();
133 $template->setCurrentBlock("question_data_text");
134 if ($show_questiontext) {
135 $this->outQuestionText($template);
136 }
137 $template->setVariable("QUESTION_TITLE", $this->getQuestionTitle($question_title));
138 $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
139 $template->setVariable("LABEL_QUESTION_ID", $this->object->getId());
140 if (strcmp($error_message, "") !== 0) {
141 $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
142 }
143 if ($this->object->getMaxChars()) {
144 $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
145 }
146 $template->parseCurrentBlock();
147 return $template->get();
148 }
149}
Basic class for all survey question types The SurveyQuestionGUI class defines and encapsulates basic ...
setQuestionTabsForClass(string $guiclass)
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)
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return true
static prepareFormOutput($a_str, bool $a_strip=false)
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-...
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static getHtmlPath(string $relative_path)
get url of path
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$res
Definition: ltiservices.php:69