ILIAS  release_7 Revision v7.30-3-g800a261c036
class.SurveyTextQuestionGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
14{
15 protected function initObject()
16 {
17 $this->object = new SurveyTextQuestion();
18 }
19
20
21 //
22 // EDITOR
23 //
24
25 public function setQuestionTabs()
26 {
27 $this->setQuestionTabsForClass("surveytextquestiongui");
28 }
29
30 protected function addFieldsToEditForm(ilPropertyFormGUI $a_form)
31 {
32 // maximum number of characters
33 $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
34 $maxchars->setRequired(false);
35 $maxchars->setSize(5);
36 $maxchars->setDecimals(0);
37 $a_form->addItem($maxchars);
38
39 // textwidth
40 $textwidth = new ilNumberInputGUI($this->lng->txt("width"), "textwidth");
41 $textwidth->setRequired(true);
42 $textwidth->setSize(3);
43 $textwidth->setDecimals(0);
44 $textwidth->setMinValue(10, true);
45 $a_form->addItem($textwidth);
46
47 // textheight
48 $textheight = new ilNumberInputGUI($this->lng->txt("height"), "textheight");
49 $textheight->setRequired(true);
50 $textheight->setSize(3);
51
52 $textheight->setDecimals(0);
53 $textheight->setMinValue(1);
54 $a_form->addItem($textheight);
55
56 // values
57 if ($this->object->getMaxChars() > 0) {
58 $maxchars->setValue($this->object->getMaxChars());
59 }
60 $textwidth->setValue($this->object->getTextWidth());
61 $textheight->setValue($this->object->getTextHeight());
62 }
63
64 protected function importEditFormValues(ilPropertyFormGUI $a_form)
65 {
66 $max = $a_form->getInput("maxchars");
67 $this->object->setMaxChars(strlen($max) ? $max : null);
68 $this->object->setTextWidth($a_form->getInput("textwidth"));
69 $this->object->setTextHeight($a_form->getInput("textheight"));
70 }
71
72 public function getParsedAnswers(array $a_working_data = null, $a_only_user_anwers = false)
73 {
74 $res = array();
75
76 if (is_array($a_working_data)) {
77 $res[] = array("textanswer" => trim($a_working_data[0]["textanswer"]));
78 }
79
80 return $res;
81 }
82
83 public function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null, array $a_working_data = null)
84 {
85 $user_answer = null;
86 if ($a_working_data) {
87 $user_answer = $this->getParsedAnswers($a_working_data);
88 $user_answer = $user_answer[0]["textanswer"];
89 }
90
91 $template = new ilTemplate("tpl.il_svy_qpl_text_printview.html", true, true, "Modules/SurveyQuestionPool");
92 if ($show_questiontext) {
93 $this->outQuestionText($template);
94 }
95 if ($question_title) {
96 $template->setVariable("QUESTION_TITLE", $this->getPrintViewQuestionTitle($question_title));
97 }
98 $template->setVariable("QUESTION_ID", $this->object->getId());
99 $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
100 if (is_array($a_working_data) && trim($user_answer)) {
101 $template->setVariable("TEXT", nl2br($user_answer));
102 } else {
103 $template->setVariable("TEXTBOX_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("textbox.png")));
104 $template->setVariable("TEXTBOX", $this->lng->txt("textbox"));
105 $template->setVariable("TEXTBOX_WIDTH", $this->object->getTextWidth() * 16);
106 $template->setVariable("TEXTBOX_HEIGHT", $this->object->getTextHeight() * 16);
107 }
108 if ($this->object->getMaxChars()) {
109 $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
110 }
111 return $template->get();
112 }
113
114
115 //
116 // EXECUTION
117 //
118
122 public function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null, $compress_view = false)
123 {
124 $template = new ilTemplate("tpl.il_svy_out_text.html", true, true, "Modules/SurveyQuestionPool");
125 $template->setCurrentBlock("material_text");
126 $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
127 $template->parseCurrentBlock();
128
129 if ($this->object->getTextHeight() == 1) {
130 $template->setCurrentBlock("textinput");
131 if (is_array($working_data)) {
132 if (strlen($working_data[0]["textanswer"])) {
133 $template->setVariable("VALUE_ANSWER", " value=\"" . ilUtil::prepareFormOutput($working_data[0]["textanswer"]) . "\"");
134 }
135 }
136 $template->setVariable("QUESTION_ID", $this->object->getId());
137 $template->setVariable("WIDTH", $this->object->getTextWidth());
138 if ($this->object->getMaxChars()) {
139 $template->setVariable("MAXLENGTH", " maxlength=\"" . $this->object->getMaxChars() . "\"");
140 }
141 $template->parseCurrentBlock();
142 } else {
143 $template->setCurrentBlock("textarea");
144 if (is_array($working_data)) {
145 $template->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($working_data[0]["textanswer"]));
146 }
147 $template->setVariable("QUESTION_ID", $this->object->getId());
148 $template->setVariable("WIDTH", $this->object->getTextWidth());
149 $template->setVariable("HEIGHT", $this->object->getTextHeight());
150 $template->parseCurrentBlock();
151 }
152 $template->setCurrentBlock("question_data_text");
153 if ($show_questiontext) {
154 $this->outQuestionText($template);
155 }
156 if ($question_title) {
157 $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
158 }
159 $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
160 $template->setVariable("LABEL_QUESTION_ID", $this->object->getId());
161 if (strcmp($error_message, "") != 0) {
162 $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
163 }
164 if ($this->object->getMaxChars()) {
165 $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
166 }
167 $template->parseCurrentBlock();
168 return $template->get();
169 }
170}
An exception for terminatinating execution or to throw for unit testing.
Basic class for all survey question types.
getPrintViewQuestionTitle($question_title=1)
getMaterialOutput()
Creates the HTML output of the question material(s)
Text survey question GUI representation.
addFieldsToEditForm(ilPropertyFormGUI $a_form)
getPrintView($question_title=1, $show_questiontext=1, $survey_id=null, array $a_working_data=null)
importEditFormValues(ilPropertyFormGUI $a_form)
getParsedAnswers(array $a_working_data=null, $a_only_user_anwers=false)
getWorkingForm($working_data="", $question_title=1, $show_questiontext=1, $error_message="", $survey_id=null, $compress_view=false)
Creates the question output form for the learner.
Text survey question.
This class represents a number property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
special template class to simplify handling of ITX/PEAR
static getHtmlPath($relative_path)
get url of path
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
foreach($_POST as $key=> $value) $res